From c15fcc2bf83c6e1230c43a0daaccdc00fb15304f Mon Sep 17 00:00:00 2001 From: yibin Date: Tue, 19 Dec 2023 18:10:53 +0800 Subject: [PATCH] Add mutex to protect concurrent prepareMPPTasks (#8553) ref pingcap/tiflash#8285 --- dbms/src/Flash/tests/gtest_compute_server.cpp | 12 ++++++------ dbms/src/TestUtils/MPPTaskTestUtils.cpp | 1 + dbms/src/TestUtils/MPPTaskTestUtils.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dbms/src/Flash/tests/gtest_compute_server.cpp b/dbms/src/Flash/tests/gtest_compute_server.cpp index 0879bbef7fc..24c5496ab50 100644 --- a/dbms/src/Flash/tests/gtest_compute_server.cpp +++ b/dbms/src/Flash/tests/gtest_compute_server.cpp @@ -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, "") @@ -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, "") @@ -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, "") @@ -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, "") @@ -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, "") @@ -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() diff --git a/dbms/src/TestUtils/MPPTaskTestUtils.cpp b/dbms/src/TestUtils/MPPTaskTestUtils.cpp index c2240c1abdf..adf51f5f5d7 100644 --- a/dbms/src/TestUtils/MPPTaskTestUtils.cpp +++ b/dbms/src/TestUtils/MPPTaskTestUtils.cpp @@ -108,6 +108,7 @@ BlockInputStreamPtr MPPTaskTestUtils::prepareMPPStreams(DAGRequestBuilder builde std::vector 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(); diff --git a/dbms/src/TestUtils/MPPTaskTestUtils.h b/dbms/src/TestUtils/MPPTaskTestUtils.h index 7f5ae002ec3..3023cf24b85 100644 --- a/dbms/src/TestUtils/MPPTaskTestUtils.h +++ b/dbms/src/TestUtils/MPPTaskTestUtils.h @@ -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) \