Better replica repair logic: clearing obsolete queue

This commit is contained in:
Alexey Milovidov 2019-02-14 17:04:28 +03:00
parent 2efb4bdca2
commit 21247ebfac
3 changed files with 22 additions and 0 deletions

View File

@ -523,6 +523,22 @@ int32_t ZooKeeper::tryMulti(const Coordination::Requests & requests, Coordinatio
}
void ZooKeeper::removeChildren(const std::string & path)
{
Strings children = getChildren(path);
while (!children.empty())
{
Coordination::Requests ops;
for (size_t i = 0; i < MULTI_BATCH_SIZE && !children.empty(); ++i)
{
ops.emplace_back(makeRemoveRequest(path + "/" + children.back(), -1));
children.pop_back();
}
multi(ops);
}
}
void ZooKeeper::removeChildrenRecursive(const std::string & path)
{
Strings children = getChildren(path);

View File

@ -177,6 +177,9 @@ public:
/// result would be the same as for the single call.
void tryRemoveRecursive(const std::string & path);
/// Remove all children nodes (non recursive).
void removeChildren(const std::string & path);
/// Wait for the node to disappear or return immediately if it doesn't exist.
void waitForDisappear(const std::string & path);

View File

@ -2036,6 +2036,9 @@ void StorageReplicatedMergeTree::cloneReplicaIfNeeded(zkutil::ZooKeeperPtr zooke
if (source_replica.empty())
throw Exception("All replicas are lost", ErrorCodes::ALL_REPLICAS_LOST);
/// Clear obsolete queue that we no longer need.
zookeeper->removeChildren(replica_path + "/queue");
/// Will do repair from the selected replica.
cloneReplica(source_replica, source_is_lost_stat, zookeeper);
/// If repair fails to whatever reason, the exception is thrown, is_lost will remain "1" and the replica will be repaired later.