From 499b67642ffa2f1e88491c697676bc7bc405a727 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 21 Apr 2018 21:41:06 +0300 Subject: [PATCH] Allow to startup with replicated tables in readonly mode when there is no ZooKeeper configured [#CLICKHOUSE-2] --- dbms/src/Interpreters/Context.cpp | 3 +-- dbms/src/Interpreters/Context.h | 1 + dbms/src/Storages/StorageReplicatedMergeTree.cpp | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index e95e4193cf..6453dc38b3 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -1358,8 +1358,7 @@ zkutil::ZooKeeperPtr Context::getZooKeeper() const bool Context::hasZooKeeper() const { - std::lock_guard lock(shared->zookeeper_mutex); - return shared->zookeeper != nullptr; + return getConfigRef().has("zookeeper"); } diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index a8bfc5975d..4c3d4fdbf9 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -304,6 +304,7 @@ public: const MergeList & getMergeList() const; /// If the current session is expired at the time of the call, synchronously creates and returns a new session with the startNewSession() call. + /// If no ZooKeeper configured, throws an exception. std::shared_ptr getZooKeeper() const; /// Has ready or expired ZooKeeper bool hasZooKeeper() const; diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index 4dd113bcf0..636aca9bec 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -191,7 +191,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( const MergeTreeSettings & settings_, bool has_force_restore_data_flag) : context(context_), - current_zookeeper(context.getZooKeeper()), database_name(database_name_), + database_name(database_name_), table_name(name_), full_path(path_ + escapeForFileName(table_name) + '/'), zookeeper_path(context.getMacros()->expand(zookeeper_path_)), replica_name(context.getMacros()->expand(replica_name_)), @@ -216,6 +216,9 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( zookeeper_path = "/" + zookeeper_path; replica_path = zookeeper_path + "/replicas/" + replica_name; + if (context.hasZooKeeper()) + current_zookeeper = context.getZooKeeper(); + bool skip_sanity_checks = false; if (current_zookeeper && current_zookeeper->exists(replica_path + "/flags/force_restore_data")) -- GitLab