diff --git a/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h b/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h index 2d4ee2a153f..ea8f4b7dbc7 100644 --- a/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h +++ b/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h @@ -17,12 +17,12 @@ public: void write(const Block & block) override { + assertSessionIsNotExpired(); auto part_blocks = storage.writer.splitBlockIntoParts(block); for (auto & current_block : part_blocks) { - if (storage.zookeeper->expired()) - throw Exception("ZooKeeper session has been expired.", ErrorCodes::NO_ZOOKEEPER); + assertSessionIsNotExpired(); /// TODO Можно ли здесь не блокировать структуру таблицы? storage.data.delayInsertIfNeeded(&storage.restarting_event); @@ -145,6 +145,14 @@ private: size_t block_index; Logger * log; + + + /// Позволяет проверить, что сессия в ZooKeeper ещё жива. + void assertSessionIsNotExpired() + { + if (storage.zookeeper->expired()) + throw Exception("ZooKeeper session has been expired.", ErrorCodes::NO_ZOOKEEPER); + } }; } diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index ec9d0410297..6c6efb0642d 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -2026,16 +2026,9 @@ void StorageReplicatedMergeTree::restartingThread() { LOG_WARNING(log, "ZooKeeper session has expired. Switching to a new session."); - { - /// Запретим писать в таблицу, пока подменяем zookeeper. - auto structure_lock = lockDataForAlter(); - - partialShutdown(); - - zookeeper = context.getZooKeeper(); - - is_read_only = true; - } + partialShutdown(); + zookeeper = context.getZooKeeper(); + is_read_only = true; while (!permanent_shutdown_called && !tryStartup()) restarting_event.tryWait(10 * 1000); @@ -2043,11 +2036,7 @@ void StorageReplicatedMergeTree::restartingThread() if (permanent_shutdown_called) break; - { - auto structure_lock = lockDataForAlter(); - - is_read_only = false; - } + is_read_only = false; } restarting_event.tryWait(60 * 1000);