Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tiflash crash when setting join_concurrent_build = 0 #4735

Merged
merged 4 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dbms/src/DataStreams/HashJoinBuildBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
#include <DataStreams/HashJoinBuildBlockInputStream.h>
namespace DB
{

Block HashJoinBuildBlockInputStream::readImpl()
{
Block block = children.back()->read();
if (!block)
return block;
join->insertFromBlock(block, stream_index);
join->insertFromBlock(block, concurrency_build_index);
return block;
}

Expand Down
6 changes: 3 additions & 3 deletions dbms/src/DataStreams/HashJoinBuildBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class HashJoinBuildBlockInputStream : public IProfilingBlockInputStream
HashJoinBuildBlockInputStream(
const BlockInputStreamPtr & input,
JoinPtr join_,
size_t stream_index_,
size_t concurrency_build_index_,
const String & req_id)
: stream_index(stream_index_)
: concurrency_build_index(concurrency_build_index_)
, log(Logger::get(NAME, req_id))
{
children.push_back(input);
Expand All @@ -44,7 +44,7 @@ class HashJoinBuildBlockInputStream : public IProfilingBlockInputStream

private:
JoinPtr join;
size_t stream_index;
size_t concurrency_build_index;
const LoggerPtr log;
};

Expand Down
10 changes: 7 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,13 @@ void DAGQueryBlockInterpreter::handleJoin(const tipb::Join & join, DAGPipeline &
recordJoinExecuteInfo(swap_join_side ? 0 : 1, join_ptr);

// add a HashJoinBuildBlockInputStream to build a shared hash table
size_t stream_index = 0;
right_pipeline.transform(
[&](auto & stream) { stream = std::make_shared<HashJoinBuildBlockInputStream>(stream, join_ptr, stream_index++, log->identifier()); });
size_t concurrency_build_index = 0;
auto get_concurrency_build_index = [&concurrency_build_index, &join_build_concurrency]() {
return (concurrency_build_index++) % join_build_concurrency;
};
right_pipeline.transform([&](auto & stream) {
stream = std::make_shared<HashJoinBuildBlockInputStream>(stream, join_ptr, get_concurrency_build_index(), log->identifier());
});
executeUnion(right_pipeline, max_streams, log, /*ignore_block=*/true);

right_query.source = right_pipeline.firstStream();
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Interpreters/Join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ bool Join::insertFromBlock(const Block & block)
/// the block should be valid.
void Join::insertFromBlock(const Block & block, size_t stream_index)
{
assert(stream_index < build_concurrency);

if (empty())
throw Exception("Logical error: Join was not initialized", ErrorCodes::LOGICAL_ERROR);
std::shared_lock lock(rwlock);
Expand Down