diff --git a/dbms/src/Storages/Distributed/DirectoryMonitor.cpp b/dbms/src/Storages/Distributed/DirectoryMonitor.cpp index 111d1ff7aab..94327d129dd 100644 --- a/dbms/src/Storages/Distributed/DirectoryMonitor.cpp +++ b/dbms/src/Storages/Distributed/DirectoryMonitor.cpp @@ -80,11 +80,15 @@ namespace StorageDistributedDirectoryMonitor::StorageDistributedDirectoryMonitor( - StorageDistributed & storage_, const std::string & name_, const ConnectionPoolPtr & pool_, ActionBlocker & monitor_blocker_) + StorageDistributed & storage_, std::string name_, ConnectionPoolPtr pool_, ActionBlocker & monitor_blocker_) + /// It's important to initialize members before `thread` to avoid race. : storage(storage_) - , pool{pool_} - , name{name_} + , pool(std::move(pool_)) + , name(std::move(name_)) , path{storage.path + name + '/'} + , should_batch_inserts(storage.global_context.getSettingsRef().distributed_directory_monitor_batch_inserts) + , min_batched_block_size_rows(storage.global_context.getSettingsRef().min_insert_block_size_rows) + , min_batched_block_size_bytes(storage.global_context.getSettingsRef().min_insert_block_size_bytes) , current_batch_file_path{path + "current_batch.txt"} , default_sleep_time{storage.global_context.getSettingsRef().distributed_directory_monitor_sleep_time_ms.totalMilliseconds()} , sleep_time{default_sleep_time} @@ -92,10 +96,6 @@ StorageDistributedDirectoryMonitor::StorageDistributedDirectoryMonitor( , log{&Logger::get(getLoggerName())} , monitor_blocker(monitor_blocker_) { - const Settings & settings = storage.global_context.getSettingsRef(); - should_batch_inserts = settings.distributed_directory_monitor_batch_inserts; - min_batched_block_size_rows = settings.min_insert_block_size_rows; - min_batched_block_size_bytes = settings.min_insert_block_size_bytes; } diff --git a/dbms/src/Storages/Distributed/DirectoryMonitor.h b/dbms/src/Storages/Distributed/DirectoryMonitor.h index 7e8f6a298f7..ec642d93819 100644 --- a/dbms/src/Storages/Distributed/DirectoryMonitor.h +++ b/dbms/src/Storages/Distributed/DirectoryMonitor.h @@ -20,7 +20,7 @@ class StorageDistributedDirectoryMonitor { public: StorageDistributedDirectoryMonitor( - StorageDistributed & storage_, const std::string & name_, const ConnectionPoolPtr & pool_, ActionBlocker & monitor_blocker_); + StorageDistributed & storage_, std::string name_, ConnectionPoolPtr pool_, ActionBlocker & monitor_blocker_); ~StorageDistributedDirectoryMonitor(); @@ -44,22 +44,22 @@ private: std::string getLoggerName() const; StorageDistributed & storage; - ConnectionPoolPtr pool; - std::string name; + const ConnectionPoolPtr pool; + const std::string name; std::string path; - bool should_batch_inserts = false; - size_t min_batched_block_size_rows = 0; - size_t min_batched_block_size_bytes = 0; + const bool should_batch_inserts = false; + const size_t min_batched_block_size_rows = 0; + const size_t min_batched_block_size_bytes = 0; String current_batch_file_path; struct BatchHeader; struct Batch; size_t error_count{}; - std::chrono::milliseconds default_sleep_time; + const std::chrono::milliseconds default_sleep_time; std::chrono::milliseconds sleep_time; - std::chrono::milliseconds max_sleep_time; + const std::chrono::milliseconds max_sleep_time; std::chrono::time_point last_decrease_time {std::chrono::system_clock::now()}; std::atomic quit {false}; std::mutex mutex;