Skip to content

Commit

Permalink
Fix gtest data race detected by tsan check (#8565)
Browse files Browse the repository at this point in the history
ref #8285
  • Loading branch information
yibin87 authored Dec 22, 2023
1 parent 11c0567 commit ddf3f97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 5 additions & 4 deletions dbms/src/Flash/tests/gtest_compute_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ class ComputeServerRunner : public DB::tests::MPPTaskTestUtils
BlockInputStreamPtr stream;
try
{
auto tasks = prepareMPPTasks(
context.scan("test_db", "l_table")
std::function<DAGRequestBuilder()> gen_builder = [&]() {
return context.scan("test_db", "l_table")
.aggregation({Max(col("l_table.s"))}, {col("l_table.s")})
.project({col("max(l_table.s)"), col("l_table.s")}),
properties);
.project({col("max(l_table.s)"), col("l_table.s")});
};
QueryTasks tasks = prepareMPPTasks(gen_builder, properties);
executeProblematicMPPTasks(tasks, properties, stream);
}
catch (...)
Expand Down
13 changes: 12 additions & 1 deletion dbms/src/TestUtils/MPPTaskTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void MPPTaskTestUtils::startServers(size_t server_num_)
}

MockComputeServerManager::instance().startServers(log_ptr, test_meta.context_idx);
MockComputeServerManager::instance().setMockStorage(context.mockStorage());
MockServerAddrGenerator::instance().reset();
}

Expand Down Expand Up @@ -112,7 +113,17 @@ std::vector<QueryTask> MPPTaskTestUtils::prepareMPPTasks(DAGRequestBuilder build
auto tasks = builder.buildMPPTasks(context, properties);
for (int i = test_meta.context_idx; i < TiFlashTestEnv::globalContextSize(); ++i)
TiFlashTestEnv::getGlobalContext(i).setCancelTest();
MockComputeServerManager::instance().setMockStorage(context.mockStorage());
return tasks;
}

std::vector<QueryTask> MPPTaskTestUtils::prepareMPPTasks(
std::function<DAGRequestBuilder()> & gen_builder,
const DAGProperties & properties)
{
std::lock_guard lock(mu);
auto tasks = gen_builder().buildMPPTasks(context, properties);
for (int i = test_meta.context_idx; i < TiFlashTestEnv::globalContextSize(); ++i)
TiFlashTestEnv::getGlobalContext(i).setCancelTest();
return tasks;
}

Expand Down
6 changes: 6 additions & 0 deletions dbms/src/TestUtils/MPPTaskTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ class MPPTaskTestUtils : public ExecutorTest
// run mpp tasks which are ready to cancel, the return value is the start_ts of query.
BlockInputStreamPtr prepareMPPStreams(DAGRequestBuilder builder, const DAGProperties & properties);

// prepareMPPTasks is not thread safe, the builder's executor_index(which is ref to context's index) is updated during this process
std::vector<QueryTask> prepareMPPTasks(DAGRequestBuilder builder, const DAGProperties & properties);

// prepareMPPTasks is thread safe
std::vector<QueryTask> prepareMPPTasks(
std::function<DAGRequestBuilder()> & gen_builder,
const DAGProperties & properties);

static void setCancelTest();

/// Keep stream not deconstructed until cancelGather invoked outside, so that the deconstruction progress won't block
Expand Down

0 comments on commit ddf3f97

Please sign in to comment.