Dropping a replica makes a concurrent mutation abort with "Part ... has empty header and does not have columns and checksums"
Describe what's wrong
With use_minimalistic_part_header_in_zookeeper = 0, a part's ZooKeeper node
/replicas/<r>/parts/<part> is an empty node with two children, columns and checksums.
StorageReplicatedMergeTree::dropReplica deletes that subtree in a way that leaves the part node
behind for a moment with both children already gone, and a concurrent
checkPartChecksumsAndAddCommitOps on another replica treats exactly that state as impossible and
throws LOGICAL_ERROR, which aborts a debug or sanitizer build.
Does it reproduce on the most recent release?
Observed on master (26.10) in CI. The default use_minimalistic_part_header_in_zookeeper = 1
hides it, because then the part node is a leaf.
How to reproduce
02962_system_sync_replica_lightweight_from_modifier with
--use_minimalistic_part_header_in_zookeeper 0. The test runs inserts, mutations and
DROP TABLE of seven replicas of the same table concurrently, which is the collision this needs.
Error message and/or stacktrace
Logical error: 'Part /clickhouse/tables/.../test_table/replicas/2/parts/all_0_54_25_58 has empty
header and does not have columns and checksums. Looks like a bug.'.
src/Storages/StorageReplicatedMergeTree.cpp:2316: DB::StorageReplicatedMergeTree::checkPartChecksumsAndAddCommitOps(...)
src/Storages/StorageReplicatedMergeTree.cpp:2384: DB::StorageReplicatedMergeTree::getOpsToCheckPartChecksumsAndCommit(...)
src/Storages/StorageReplicatedMergeTree.cpp:2436: DB::StorageReplicatedMergeTree::checkPartChecksumsAndCommit(...)
src/Storages/MergeTree/MutateFromLogEntryTask.cpp:340: DB::MutateFromLogEntryTask::finalize(...)
src/Storages/MergeTree/ReplicatedMergeMutateTaskBase.cpp:242: DB::ReplicatedMergeMutateTaskBase::executeImpl()Where it happens
dropReplica removes the parts subtree with probably_flat = true
(StorageReplicatedMergeTree.cpp, "Then try to remove paths that are known to be flat"):
flat_nodes.emplace_back("parts");
...
bool removed_quickly = zookeeper->tryRemoveChildrenRecursive(fs::path(remote_replica_path) / node, /* probably flat */ true);That assumption only holds for the minimalistic header. With the old format the bulk multi fails
with ZNOTEMPTY, and tryRemoveChildrenRecursive falls back to two separate calls
(ZooKeeper.cpp:1183-1191):
if (res.error == Coordination::Error::ZNOTEMPTY)
{
if (probably_flat)
{
/// It actually has children, let's remove them
tryRemoveChildrenRecursive(batch[i]);
tryRemove(batch[i]);
}
continue;
}Between those two lines the part node exists with no columns and no checksums. A concurrent
reader lands in the branch that is written as unreachable
(StorageReplicatedMergeTree.cpp:2303-2320):
if (zookeeper->tryGet(fs::path(current_part_path) / "columns", columns_str) &&
zookeeper->tryGet(fs::path(current_part_path) / "checksums", checksums_str))
{
replica_part_header = ReplicatedMergeTreePartHeader::fromColumnsAndChecksumsZNodes(columns_str, checksums_str);
}
else
{
if (zookeeper->exists(current_part_path))
throw Exception(ErrorCodes::LOGICAL_ERROR, "Part {} has empty header and does not have columns and checksums. "
"Looks like a bug.", current_part_path);
LOG_INFO(log, "Not checking checksums of part {} with replica {} because part was removed from ZooKeeper", part_name, replica);
continue;
}The LOG_INFO path right below is the correct handling — the replica is going away, so its copy of
the part carries no information to check against. Only the exists probe distinguishes the two,
and it cannot tell "being deleted" from "corrupt".
Expected behavior
A replica that is being dropped should not abort a mutation on another replica. Either treat a part
node with no columns/checksums as removed (the LOG_INFO path), or have dropReplica remove
each part node and its children atomically instead of relying on probably_flat.
Additional context
Found by the CI settings randomizer (https://github.com/ClickHouse/ClickHouse/pull/106734), which
newly randomizes use_minimalistic_part_header_in_zookeeper over [0, 1]:
The abort also failed the job's server liveness check.
Source: ClickHouse/ClickHouse