From fe7c3cb865c8c504502766d5f4620cdf31dd7259 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Mon, 30 Nov 2020 18:31:02 +0300 Subject: [PATCH] fix race on is_circular_replicated --- src/Interpreters/DDLWorker.cpp | 6 +++--- src/Interpreters/DDLWorker.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Interpreters/DDLWorker.cpp b/src/Interpreters/DDLWorker.cpp index 1ba1fc0cb0d..57bbf95bdbe 100644 --- a/src/Interpreters/DDLWorker.cpp +++ b/src/Interpreters/DDLWorker.cpp @@ -186,6 +186,7 @@ struct DDLTask Cluster::Address address_in_cluster; size_t host_shard_num; size_t host_replica_num; + bool is_circular_replicated = false; /// Stage 3.3: execute query ExecutionStatus execution_status; @@ -594,7 +595,7 @@ void DDLWorker::parseQueryAndResolveHost(DDLTask & task) * To distinguish one replica from another on the same node, * every shard is placed into separate database. * */ - is_circular_replicated = true; + task.is_circular_replicated = true; auto * query_with_table = dynamic_cast(task.query.get()); if (!query_with_table || query_with_table->database.empty()) { @@ -770,7 +771,6 @@ void DDLWorker::processTask(DDLTask & task) { try { - is_circular_replicated = false; parseQueryAndResolveHost(task); ASTPtr rewritten_ast = task.query_on_cluster->getRewrittenASTWithoutOnCluster(task.address_in_cluster.default_database); @@ -787,7 +787,7 @@ void DDLWorker::processTask(DDLTask & task) storage = DatabaseCatalog::instance().tryGetTable(table_id, context); } - if (storage && taskShouldBeExecutedOnLeader(rewritten_ast, storage) && !is_circular_replicated) + if (storage && taskShouldBeExecutedOnLeader(rewritten_ast, storage) && !task.is_circular_replicated) tryExecuteQueryOnLeaderReplica(task, storage, rewritten_query, task.entry_path, zookeeper); else tryExecuteQuery(rewritten_query, task, task.execution_status); diff --git a/src/Interpreters/DDLWorker.h b/src/Interpreters/DDLWorker.h index 75d0ce3f5a4..7dd9c38e9da 100644 --- a/src/Interpreters/DDLWorker.h +++ b/src/Interpreters/DDLWorker.h @@ -104,7 +104,6 @@ private: void attachToThreadGroup(); private: - std::atomic is_circular_replicated = false; Context context; Poco::Logger * log;