Merge pull request #4399 from yandex/better-replica-repair

Better replica repair
This commit is contained in:
alexey-milovidov 2019-02-14 21:50:20 +03:00 committed by GitHub
commit ed3a8a66a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.