Merge pull request #4472 from yandex/speedup-ddl-cleanup

Fix hangup on server shutdown if distributed DDLs were used.
This commit is contained in:
Alex Zatelepin 2019-02-22 21:42:05 +03:00 committed by GitHub
commit 34346e37eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -513,7 +513,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
{ {
/// DDL worker should be started after all tables were loaded /// DDL worker should be started after all tables were loaded
String ddl_zookeeper_path = config().getString("distributed_ddl.path", "/clickhouse/task_queue/ddl/"); String ddl_zookeeper_path = config().getString("distributed_ddl.path", "/clickhouse/task_queue/ddl/");
global_context->setDDLWorker(std::make_shared<DDLWorker>(ddl_zookeeper_path, *global_context, &config(), "distributed_ddl")); global_context->setDDLWorker(std::make_unique<DDLWorker>(ddl_zookeeper_path, *global_context, &config(), "distributed_ddl"));
} }
std::unique_ptr<DNSCacheUpdater> dns_cache_updater; std::unique_ptr<DNSCacheUpdater> dns_cache_updater;

View File

@ -41,6 +41,7 @@
#include <Interpreters/QueryThreadLog.h> #include <Interpreters/QueryThreadLog.h>
#include <Interpreters/PartLog.h> #include <Interpreters/PartLog.h>
#include <Interpreters/Context.h> #include <Interpreters/Context.h>
#include <Interpreters/DDLWorker.h>
#include <Common/DNSResolver.h> #include <Common/DNSResolver.h>
#include <IO/ReadBufferFromFile.h> #include <IO/ReadBufferFromFile.h>
#include <IO/UncompressedCache.h> #include <IO/UncompressedCache.h>
@ -141,7 +142,7 @@ struct ContextShared
std::optional<BackgroundSchedulePool> schedule_pool; /// A thread pool that can run different jobs in background (used in replicated tables) std::optional<BackgroundSchedulePool> schedule_pool; /// A thread pool that can run different jobs in background (used in replicated tables)
MultiVersion<Macros> macros; /// Substitutions extracted from config. MultiVersion<Macros> macros; /// Substitutions extracted from config.
std::optional<Compiler> compiler; /// Used for dynamic compilation of queries' parts if it necessary. std::optional<Compiler> compiler; /// Used for dynamic compilation of queries' parts if it necessary.
std::shared_ptr<DDLWorker> ddl_worker; /// Process ddl commands from zk. std::unique_ptr<DDLWorker> ddl_worker; /// Process ddl commands from zk.
/// Rules for selecting the compression settings, depending on the size of the part. /// Rules for selecting the compression settings, depending on the size of the part.
mutable std::unique_ptr<CompressionCodecSelector> compression_codec_selector; mutable std::unique_ptr<CompressionCodecSelector> compression_codec_selector;
std::optional<MergeTreeSettings> merge_tree_settings; /// Settings of MergeTree* engines. std::optional<MergeTreeSettings> merge_tree_settings; /// Settings of MergeTree* engines.
@ -274,6 +275,7 @@ struct ContextShared
external_models.reset(); external_models.reset();
background_pool.reset(); background_pool.reset();
schedule_pool.reset(); schedule_pool.reset();
ddl_worker.reset();
} }
private: private:
@ -1360,12 +1362,12 @@ BackgroundSchedulePool & Context::getSchedulePool()
return *shared->schedule_pool; return *shared->schedule_pool;
} }
void Context::setDDLWorker(std::shared_ptr<DDLWorker> ddl_worker) void Context::setDDLWorker(std::unique_ptr<DDLWorker> ddl_worker)
{ {
auto lock = getLock(); auto lock = getLock();
if (shared->ddl_worker) if (shared->ddl_worker)
throw Exception("DDL background thread has already been initialized.", ErrorCodes::LOGICAL_ERROR); throw Exception("DDL background thread has already been initialized.", ErrorCodes::LOGICAL_ERROR);
shared->ddl_worker = ddl_worker; shared->ddl_worker = std::move(ddl_worker);
} }
DDLWorker & Context::getDDLWorker() const DDLWorker & Context::getDDLWorker() const

View File

@ -371,7 +371,7 @@ public:
BackgroundProcessingPool & getBackgroundPool(); BackgroundProcessingPool & getBackgroundPool();
BackgroundSchedulePool & getSchedulePool(); BackgroundSchedulePool & getSchedulePool();
void setDDLWorker(std::shared_ptr<DDLWorker> ddl_worker); void setDDLWorker(std::unique_ptr<DDLWorker> ddl_worker);
DDLWorker & getDDLWorker() const; DDLWorker & getDDLWorker() const;
Clusters & getClusters() const; Clusters & getClusters() const;