Repository navigation
Conversation
A patch part records the data-version range of the rows it patches, and a patch applies whole or not at all. SourcePartsSetForPatch::merge unions those ranges, so merging patches for data versions 1 and 6 produces one patch spanning 1..6. A mutation cutting at version 2 has no valid way to apply that patch, so patchHasHigherDataVersion throws LOGICAL_ERROR from MutateTask::prepare, the MUTATE_PART entry fails and retries forever, and the mutation never completes. Debug and sanitizer builds abort instead, which is how this surfaces in the stress tests. Reported as ClickHouse#98898. DistributedMergePredicate::canMergeParts already refuses to merge two parts whose current mutation versions differ, and it is applied to every adjacent pair, so with durable metadata it does refuse this pair. It fails because ReplicatedMergeTreeQueue::getCurrentMutationVersion returns 0 for a partition that is absent from mutations_by_partition, which is indistinguishable from a partition that has no mutations at all. The finished-mutation cleanup thread deletes the /mutations znodes once every replica's mutation_pointer has passed them and updateMutations erases the in-memory entries, while the MUTATE_PART queue entries survive. Every patch then maps to version 0, both endpoints compare equal, and every pair looks mergeable. Take the pending mutation versions from the replication queue instead, which is the durable record: a queued MUTATE_PART entry's new_part_name encodes its target version. isMergeOfPatchPartsCrossingMutation postpones a patch MERGE_PARTS entry whose source data versions would span such a version, modelled on the existing isDropOfPatchPartBlocked. Postponing is self-healing: the patches stay unmerged with singleton spans, the mutation proceeds, and the merge runs afterwards. The assertion in patchHasHigherDataVersion is left untouched, since after this change a straddling patch is never constructed. This prevents the bad state from being created. It does not repair a patch that already spans a mutation version on disk, so a table already in that state stays stuck; recovering those requires filtering patch rows by their per-row _data_version in the patch apply path. The plain MergeTree predicate has no equivalent hole: StorageMergeTree:: clearOldMutations bounds deletion by getMinPartDataVersion(), so a mutation with pending work is never pruned from current_mutations_by_version. The new test reproduces the failure deterministically by holding the MUTATE_PART in prepare() with the rmt_mutate_task_pause_in_prepare fail point while the patch merge is decided. It asserts that the mutation completes, that the replication queue drains, and that the values are fully patched, so neither a postponed-forever merge nor a silently dropped patch can pass it.
…ation The wait loop broke out as soon as a patch MERGE_PARTS entry was present in system.replication_queue. Presence is established by pullLogsToQueue, which strictly precedes selectEntryToProcess evaluating the entry, so the test could disable the fail point while the patches were still unmerged singletons. Without the guard the released mutation then snapshots singleton spans, finds no straddle and completes, the MUTATE_PART entry is gone, and the later patch merge produces the straddling patch with nothing left to trip on it. The queue drains, the values are fully patched, and the test passes on a binary that still has the bug. The loop also had no failure branch, so a timeout was indistinguishable from success. Wait for a positive, guard-specific observation instead: a patch MERGE_PARTS entry with num_postponed > 0 whose postpone_reason names the version span, or an already merged level > 0 patch part. The reason substring occurs once in the whole source tree, and postpone_reason is filled regardless of log level because LogToStrImpl::log assigns the string before the propagation check. Post-fix only the postponed branch can fire while the MUTATE_PART is queued, and pre-fix only the merged branch exists, so the loop is satisfiable in both directions while the branch taken is what discriminates. Neither arm can reach the other's branch. A timeout is now a hard failure that dumps the queue and the active parts, following 03716_mutations_parts_postpone_reasons_mt. Verified against four binaries: the fix passes and takes the postponed branch, pristine master and a variant with the guard call deleted both fail with the original abort, and the fix with the postpone_reason pattern corrupted fails on the timeout branch, which proves the new condition is load-bearing.
…ide effect The wait loop accepted either the guard's refusal or the mere existence of a merged patch part. The second alternative is satisfiable by a merge of patches that all sit above the mutation version, which the guard correctly permits, so the crossing merge was never necessarily evaluated against the queued mutation and the test could pass on a binary without the guard. Only the guard-specific postpone reason is accepted now, and failing to observe it is a hard failure rather than a fall-through. Stopped merges block execution of MERGE_PARTS and MUTATE_PART alike while assignment of both keeps running, so the scenario is now built up entirely inside the stopped window and released afterwards. The mutation entry is waited for before its metadata is killed, because ALTER returns before the entry is assigned when mutations_sync is 0, and its survival past the kill is asserted: that state is the subject of the test. The failpoint is PAUSEABLE and pauses every MUTATE_PART on the server with no timeout, so an early exit under set -e would hang later unrelated tests to their timeout. Release it from an EXIT trap as well.
Internal second-model review (3 rounds, 4 gate runs) - 1 accepted, 4 noted, all resolved before publishingI put this through three independent cold-review rounds plus four adversarial gate runs before opening it. Recording what was raised and how I resolved it, so nobody re-derives it. Rounds 1-2 (test oracle, both accepted and fixed). The first version of the regression test could pass GREEN on a binary without the fix. It waited for a patch ❌ Round 3, accepted: the description over-claimed its own scope. A reviewer pass argued a replica can still end up with a spanning patch without ever merging one, by fetching it as a covering part. I could not refute any step of that: the
💡 The test carries no For calibration: after the description was corrected, the final gate run over the byte-identical tree returned zero findings. Session id: cron:clickhouse-review-slot-49:20260808-231800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-49:20260808-231800 |
|
cc @CurtizJ @tavplubix, could you review this? Merging patch parts unions their source data-version ranges, so a merge can produce a patch spanning a queued mutation's version, which no mutation can apply; the pair check that should refuse it reads mutation versions from |
|
Workflow [PR], commit [2c3cf9c] Summary: ✅
AI ReviewSummaryThis PR moves the "do not merge patch parts across a queued mutation version" check from Findings❌ Blockers
Tests
Final VerdictRequest changes: the queue-side guard is only a partial mitigation, and the original permanently stuck replication state is still reachable through covering-part fetch. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 34/35 (97.14%) · Uncovered code |
|
|
||
| auto original_partition_id = new_part_info.getOriginalPartitionId(); | ||
|
|
||
| for (const auto & mutate_entry : queue) |
There was a problem hiding this comment.
queue is only one carrier of the "pending mutation version" invariant here, so blocking local MERGE_PARTS execution is not sufficient to eliminate the stuck state.
A replica can still have a queued MUTATE_PART plus missing lower-version patch GET_PARTs (ReplicatedMergeTreeQueue::havePendingPatchPartsForMutation, lines 446-456). If another replica has already produced the merged patch, StorageReplicatedMergeTree::findReplicaHavingCoveringPartImplLowLevel will substitute the missing patch with the largest covering remote part, and ReplicatedMergeTreeQueue::addFuturePartIfNotCoveredByThem only checks queue/drop/future-part ordering, not whether that covering patch spans a queued mutation version. After that fetch, ReplicatedMergeTreeQueue::getMutationsSnapshot still reloads the active spanning patch and patchHasHigherDataVersion throws the same LOGICAL_ERROR.
So this closes the local merge path, but a lagging replica can still import the bad patch via covering-part fetch. I think the same boundary check needs to be enforced in the covering-fetch/substitution path as well, or the permanently stuck replicated state remains reachable.
There was a problem hiding this comment.
The mechanism is real, and it is already stated in the PR. I reached the same conclusion in review before publishing and could not refute any step of it: the MERGE_PARTS entry is a cluster-wide log entry, this check is execution-side and reads only the local queue, a replica that already finished the mutation no longer holds the MUTATE_PART entry and so permits the merge, and findReplicaHavingCoveringPartImplLowLevel picks the largest containing remote part while addFuturePartIfNotCoveredByThem validates only virtual-parts containment, drop-part intersection and future-part overlap, never a mutation boundary.
That is why the description states the scope rather than claiming the state cannot be created: "this is an execution-side per-replica check: it stops a replica merging across a mutation queued there, not every route by which a spanning patch could reach one". The same limit is recorded in full in the adjudication comment, round 3: #113998 (comment)
Two reasons the boundary check is not added to the fetch path here:
- This diff touches no fetch path. It is two functions in
ReplicatedMergeTreeQueueplus one test, so validating a fetched substitute is a separate change inStorageReplicatedMergeTree. - Refusing a fetch has none of the self-healing postpone semantics that make refusing a merge safe. An earlier design that refused the operation outright was rejected on exactly that liveness dimension, and getting it wrong trades an exception for a stall.
On the suggested two-replica test: it would assert that the lagging replica does not fetch the covering patch, which is the behaviour this PR does not claim, so it would fail. I am not promising a follow-up I have not measured.
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units
|
CI finish ledger - 2c3cf9cCI is fully finished on this commit: 161 checks pass, 17 skipped, 0 failed, 0 queued or running, and both No failed check to own. CIDB reports zero Session id: cron:our-pr-ci-monitor:20260809-123000 |
|
The merge-queue run at Measured locally on this branch merged with current master, three arms, binary identity asserted per arm with
The third arm is the point: with this PR's check removed and #115064 in place, no patch merge is assigned at all and the logical error does not occur. For the record the CI signature is the arming path failing, not the property: the surviving I have pushed nothing. I would rather not make the test pass, since that means asserting something that can no longer happen. The one case I did not measure is a mixed-version cluster, where an older replica could still assign such a merge and this check would refuse the entry on an upgraded one. Should this be closed as covered by #115064, or kept for that case? |
|
@groeneai, a redundant test should be removed. If the code changes are no longer relevant, you can close this. |
|
Closing: the code change is no longer relevant. Arm 3 of the matrix above is the answer. With this check removed and #115064 in place, no patch merge is assigned at all, so there is nothing left for an execution-side check to refuse on any path I could reach. #115064 takes the data versions from The one part not covered is the cross-replica route this PR already scoped itself out of: a I am still tracking the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a permanently stalled mutation on
ReplicatedMergeTreetables with lightweight updates enabled. A merge of patch parts could produce a patch whose source data versions span the version of a mutation that is still queued, which no mutation can then apply, so theMUTATE_PARTentry failed and retried forever (Found patch part ... that intersects mutation with version ...). Such merges are now postponed until the mutation completes.Description
Related: #98898
A patch part records the data-version range of what it patches, and applies whole or not at all. Merging patch parts unions those ranges, so merging patches for versions 1 and 6 yields one spanning 1..6. A mutation cutting at version 2 cannot apply it,
patchHasHigherDataVersionthrows, and theMUTATE_PARTentry retries forever. Debug and sanitizer builds abort, hence the stress failures.Root cause: the merge predicate already refuses parts whose current mutation versions differ, but derives them from
mutations_by_partition, wheregetCurrentMutationVersionreturns 0 for an absent partition. The finished-mutation cleaner removes the/mutationsznodes once every replica'smutation_pointerpassed them, while theMUTATE_PARTentries survive. Every patch then maps to 0 and every pair looks mergeable. The logs showThere are no mutations for partition ID alljust before the abort.The fix takes the pending versions from the replication queue instead, which is durable: a queued
MUTATE_PARTentry'snew_part_nameencodes its target version. A patchMERGE_PARTSwhose sources would span one is postponed, so it proceeds once the mutation completes. No assertion is relaxed, and the cost is one walk of a queue the neighbouring guards already walk.The repro is deterministic: pristine master aborts with the exact message, the fix passes, and deleting only the new guard call brings the abort back. The test asserts the mutation completes, the queue drains and the data is fully patched, so no deadlock or dropped patch passes.
Two limits. Like the guards beside it, this is an execution-side per-replica check: it stops a replica merging across a mutation queued there, not every route by which a spanning patch could reach one. And it does not repair a patch already spanning a version on disk, so such a table stays stuck; that needs per-row
_data_versionfiltering when applying patches.