Repository navigation
Fix race between INSERT and DROP_RANGE causing LOGICAL_ERROR in paranoid check of covered parts. - #96164
Merged
Conversation
…oid check
The `paranoidCheckForCoveredPartsInZooKeeper` assertion was failing sporadically
in test `01154_move_partition_long` because a part's ZooKeeper node remained
after `executeDropRange` removed all known parts from ZK.
Root cause: a race between a concurrent INSERT on the originating replica and
`executeDropRange` processing on the same replica.
The sequence of events:
1. INSERT thread calls `renameTempPartAndAdd` — the part enters `data_parts`
in PreActive state, then the data_parts lock is released.
2. INSERT thread executes the ZK multi-op (`commitPart`) — the part node is
created in ZooKeeper under `/replicas/{replica}/parts/{part_name}`.
The ephemeral block number lock is removed atomically by this multi-op.
3. `executeDropRange` runs on the same replica:
- `removePartProducingOpsInRange` waits for currently executing queue
entries, but INSERT on the originating replica bypasses the queue.
- `removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper`
enumerates local parts filtered to Active/Outdated/Deleting states —
PreActive parts are skipped.
- `removePartsFromZooKeeperWithRetries` removes ZK nodes only for the
parts it found — the INSERT's ZK node is not in the list.
- `paranoidCheckForCoveredPartsInZooKeeper` finds the INSERT's ZK node
still present — throws `LOGICAL_ERROR`.
4. INSERT thread calls `transaction.commit()` — the part transitions from
PreActive to Active, but the DROP_RANGE has already completed.
`clearLockedBlockNumbersInPartition` (called before the DROP_RANGE log entry
is created) cannot prevent this race: by the time it runs, the INSERT has
already completed its ZK multi-op, which atomically removed the block number
lock and created the part node.
Fix: add `waitForPreActivePartsInRange` that waits on a condition variable
(`preactive_parts_cv`) for all PreActive parts in the drop range to finish
committing or rolling back. The condition variable is notified by
`Transaction::commit` and `Transaction::rollback`. Since
`clearLockedBlockNumbersInPartition` prevents new INSERTs from committing
in the range, the wait is guaranteed to terminate.
The wait is added before `removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper`
in `executeDropRange` and both removal sites in `executeReplaceRange`.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
Workflow [PR], commit [30c81e8] Summary: ❌
|
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Apr 16, 2026
…rOnStart The paranoid check on startup verifies that all ZK parts covered by another ZK part either exist on disk or are in the parts_to_fetch list. However, it does not check whether a local active part already covers the ZK part. This legitimately happens after a merge or mutation: the covering part is active locally, the covered part was cleaned from disk by clearOldPartsAndRemoveFromZK, but the covered part's ZK entry has not been cleaned up yet (ZK cleanup can lag behind disk cleanup, or the server was restarted between the two). The data is preserved in the local covering part, and the stale ZK entry will be removed by the cleanup thread after startup. Without this fix, the chassert(false) fires as a false positive in debug/sanitizer builds during stress tests, particularly in the createLogEntriesToFetchBrokenParts() call path (STID: 2508-5dc3, 2508-6644). Prior fixes PR ClickHouse#96164, ClickHouse#96705, and ClickHouse#100652 addressed other false-positive scenarios in this function but missed the case where a local active part covers the ZK part. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is very interesting and not easy to understand, but the explanation looks correct.
The
paranoidCheckForCoveredPartsInZooKeeperassertion was failing sporadically in test01154_move_partition_longbecause a part's ZooKeeper node remained afterexecuteDropRangeremoved all known parts from ZK.Root cause: a race between a concurrent INSERT on the originating replica and
executeDropRangeprocessing on the same replica.The sequence of events:
INSERT thread calls
renameTempPartAndAdd— the part entersdata_partsin PreActive state, then the data_parts lock is released.INSERT thread executes the ZK multi-op (
commitPart) — the part node is created in ZooKeeper under/replicas/{replica}/parts/{part_name}. The ephemeral block number lock is removed atomically by this multi-op.executeDropRangeruns on the same replica:removePartProducingOpsInRangewaits for currently executing queue entries, but INSERT on the originating replica bypasses the queue.removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeperenumerates local parts filtered to Active/Outdated/Deleting states — PreActive parts are skipped.removePartsFromZooKeeperWithRetriesremoves ZK nodes only for the parts it found — the INSERT's ZK node is not in the list.paranoidCheckForCoveredPartsInZooKeeperfinds the INSERT's ZK node still present — throwsLOGICAL_ERROR.INSERT thread calls
transaction.commit()— the part transitions from PreActive to Active, but the DROP_RANGE has already completed.clearLockedBlockNumbersInPartition(called before the DROP_RANGE log entry is created) cannot prevent this race: by the time it runs, the INSERT has already completed its ZK multi-op, which atomically removed the block number lock and created the part node.Fix: add
waitForPreActivePartsInRangethat waits on a condition variable (preactive_parts_cv) for all PreActive parts in the drop range to finish committing or rolling back. The condition variable is notified byTransaction::commitandTransaction::rollback. SinceclearLockedBlockNumbersInPartitionprevents new INSERTs from committing in the range, the wait is guaranteed to terminate.The wait is added before
removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeperinexecuteDropRangeand both removal sites inexecuteReplaceRange.Also,
Changelog category (leave one):
Version info
26.2.1.339