Merge pull request #26321 from ClickHouse/tavplubix-patch-2

Fix rare logical race in `cloneReplica(...)`
This commit is contained in:
alexey-milovidov 2021-07-15 08:00:26 +03:00 committed by GitHub
commit 323b60fcea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2781,6 +2781,16 @@ void StorageReplicatedMergeTree::cloneReplica(const String & source_replica, Coo
}
}
{
/// Check "is_lost" version after retrieving queue and parts.
/// If version has changed, then replica most likely has been dropped and parts set is inconsistent,
/// so throw exception and retry cloning.
Coordination::Stat is_lost_stat_new;
zookeeper->get(fs::path(source_path) / "is_lost", &is_lost_stat_new);
if (is_lost_stat_new.version != source_is_lost_stat.version)
throw Exception(ErrorCodes::REPLICA_STATUS_CHANGED, "Cannot clone {}, because it suddenly become lost", source_replica);
}
tryRemovePartsFromZooKeeperWithRetries(parts_to_remove_from_zk);
auto local_active_parts = getDataParts();