Skip to content

Commit

Permalink
Add mutex to protect concurrent prepareMPPTasks (#8553)
Browse files Browse the repository at this point in the history
ref #8285
  • Loading branch information
yibin87 authored Dec 19, 2023
1 parent 45e3071 commit c15fcc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dbms/src/Flash/tests/gtest_compute_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ try
addOneQuery(i + 10, running_queries, gather_ids);
}
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
ASSERT_TRUE(
TiFlashMetrics::instance()
.tiflash_task_scheduler.get(tiflash_task_scheduler_metrics::type_active_queries_count, "")
Expand All @@ -997,7 +997,7 @@ try
.Value()
== 0);
addOneQuery(1, running_queries, gather_ids);
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
ASSERT_TRUE(
TiFlashMetrics::instance()
.tiflash_task_scheduler.get(tiflash_task_scheduler_metrics::type_active_queries_count, "")
Expand All @@ -1020,7 +1020,7 @@ try
addOneQuery((i + 1) * 20, running_queries, gather_ids);
}
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
ASSERT_TRUE(
TiFlashMetrics::instance()
.tiflash_task_scheduler.get(tiflash_task_scheduler_metrics::type_active_queries_count, "")
Expand All @@ -1032,7 +1032,7 @@ try
.Value()
== 0);
addOneQuery(30, running_queries, gather_ids);
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
ASSERT_TRUE(
TiFlashMetrics::instance()
.tiflash_task_scheduler.get(tiflash_task_scheduler_metrics::type_active_queries_count, "")
Expand All @@ -1046,7 +1046,7 @@ try
/// cancel 1 running query
MockComputeServerManager::instance().cancelGather(gather_ids[0]);
running_queries[0].join();
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
ASSERT_TRUE(
TiFlashMetrics::instance()
.tiflash_task_scheduler.get(tiflash_task_scheduler_metrics::type_active_queries_count, "")
Expand Down Expand Up @@ -1103,7 +1103,7 @@ try
single_gather_properties.gather_id = 1;
addOneGather(running_queries, gather_ids, single_gather_properties);
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for(2s);
std::this_thread::sleep_for(4s);
/// 6 gathers, but two query
ASSERT_TRUE(
TiFlashMetrics::instance()
Expand Down
1 change: 1 addition & 0 deletions dbms/src/TestUtils/MPPTaskTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ BlockInputStreamPtr MPPTaskTestUtils::prepareMPPStreams(DAGRequestBuilder builde

std::vector<QueryTask> MPPTaskTestUtils::prepareMPPTasks(DAGRequestBuilder builder, const DAGProperties & properties)
{
std::lock_guard lock(mu);
auto tasks = builder.buildMPPTasks(context, properties);
for (int i = test_meta.context_idx; i < TiFlashTestEnv::globalContextSize(); ++i)
TiFlashTestEnv::getGlobalContext(i).setCancelTest();
Expand Down
1 change: 1 addition & 0 deletions dbms/src/TestUtils/MPPTaskTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MPPTaskTestUtils : public ExecutorTest
static LoggerPtr log_ptr;
static size_t server_num;
static MPPTestMeta test_meta;
std::mutex mu;
};

#define ASSERT_MPPTASK_EQUAL(tasks, properties, expected_cols) \
Expand Down

0 comments on commit c15fcc2

Please sign in to comment.