Allow to startup with replicated tables in readonly mode when there is no ZooKeeper configured [#CLICKHOUSE-2]

This commit is contained in:
Alexey Milovidov 2018-04-21 21:41:06 +03:00
parent bd23b8790c
commit 499b67642f
3 changed files with 6 additions and 3 deletions

View File

@ -1358,8 +1358,7 @@ zkutil::ZooKeeperPtr Context::getZooKeeper() const
bool Context::hasZooKeeper() const bool Context::hasZooKeeper() const
{ {
std::lock_guard<std::mutex> lock(shared->zookeeper_mutex); return getConfigRef().has("zookeeper");
return shared->zookeeper != nullptr;
} }

View File

@ -304,6 +304,7 @@ public:
const MergeList & getMergeList() const; 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 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<zkutil::ZooKeeper> getZooKeeper() const; std::shared_ptr<zkutil::ZooKeeper> getZooKeeper() const;
/// Has ready or expired ZooKeeper /// Has ready or expired ZooKeeper
bool hasZooKeeper() const; bool hasZooKeeper() const;

View File

@ -191,7 +191,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
const MergeTreeSettings & settings_, const MergeTreeSettings & settings_,
bool has_force_restore_data_flag) bool has_force_restore_data_flag)
: context(context_), : context(context_),
current_zookeeper(context.getZooKeeper()), database_name(database_name_), database_name(database_name_),
table_name(name_), full_path(path_ + escapeForFileName(table_name) + '/'), table_name(name_), full_path(path_ + escapeForFileName(table_name) + '/'),
zookeeper_path(context.getMacros()->expand(zookeeper_path_)), zookeeper_path(context.getMacros()->expand(zookeeper_path_)),
replica_name(context.getMacros()->expand(replica_name_)), replica_name(context.getMacros()->expand(replica_name_)),
@ -216,6 +216,9 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
zookeeper_path = "/" + zookeeper_path; zookeeper_path = "/" + zookeeper_path;
replica_path = zookeeper_path + "/replicas/" + replica_name; replica_path = zookeeper_path + "/replicas/" + replica_name;
if (context.hasZooKeeper())
current_zookeeper = context.getZooKeeper();
bool skip_sanity_checks = false; bool skip_sanity_checks = false;
if (current_zookeeper && current_zookeeper->exists(replica_path + "/flags/force_restore_data")) if (current_zookeeper && current_zookeeper->exists(replica_path + "/flags/force_restore_data"))