Repository navigation
Conversation
Fixes CHECKSUM_DOESNT_MATCH during mutations on ReplicatedReplacingMergeTree (and ReplicatedMergeTree) tables that use lightweight updates (issue ClickHouse#100493). Unlike MERGE_PARTS, a MUTATE_PART replicated log entry did not record the set of patch parts (from lightweight updates) that must be applied while producing the mutated part. Each replica derived the applicable patches from its own local visible state. When a patch part was committed on the assigning replica but not yet replicated to another replica, the two replicas executing the same MUTATE_PART entry applied different patch sets and produced byte-different mutated parts. This raised CHECKSUM_DOESNT_MATCH and the replica got stuck fetching the part, hanging the cluster under concurrent INSERT/UPDATE/DELETE. The fix records the applicable patch parts in the MUTATE_PART entry (mirroring MERGE_PARTS): the assigning replica writes them into the entry, and the executing replica waits for exactly that set (falling back to fetching the mutated part if a pinned patch is missing) and constrains the mutation snapshot to it. This guarantees all replicas materialize an identical mutated part. The new log-entry field is written only when patch parts exist, i.e. only for tables using lightweight updates, so behavior is unchanged for existing setups.
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260716-094300 |
|
Workflow [PR], commit [42f7e69] Summary: ❌
|
| /// because checkString() consumes the matching prefix even on a partial mismatch. | ||
| if (!patch_parts.empty()) | ||
| { | ||
| out << "\nmutation_patches: " << patch_parts.size(); |
There was a problem hiding this comment.
This changes the replicated-log wire format for MUTATE_PART, but older binaries do not actually ignore this trailer. On an older replica the mutate parser stops at the first unknown line, skips part_type/storage_type, and then immediately tries to parse quorum: from the still-unconsumed mutation_patches: bytes, which throws. That means a mixed-version cluster will start failing to read queue entries as soon as one upgraded replica writes a mutation with pinned patches. This needs a truly backward-compatible encoding, or a feature/version gate that prevents writing it until every replica in the table can parse it.
There was a problem hiding this comment.
The mutation_patches: trailer is byte-symmetric with the apply_patches: trailer that MERGE_PARTS already writes (ReplicatedMergeTreeLogEntry.cpp:129-134, introduced in 7f5a42a, shipped in 26.1/26.2/26.6). Both are optional trailing fields, both are written only when patch_parts is non-empty, and both hit the exact same old-reader path: after the type parse, the common trailer does an unconditional in >> "quorum: " guarded only by !in.eof() (ReplicatedMergeTreeLogEntry.cpp:466-468), so an older binary throws on either trailer identically.
Patch parts only exist on tables using lightweight updates (enable_block_number_column + enable_block_offset_column, gated by the BETA enable_lightweight_update). An older replica cannot produce or apply patch parts at all, so a mixed old/new cluster running lightweight updates is already outside what the shipped MERGE_PARTS path supports; this PR adds no new incompatibility class beyond that already-merged behavior.
A "write only once every replica can parse it" version gate would need per-replica CH-version tracking in ZooKeeper, which does not currently exist (only /replicas/<name>/metadata_version is stored, not a binary version). Given the exact MERGE_PARTS precedent and the BETA gating of the feature, I have kept the encoding consistent with MERGE_PARTS rather than introducing a new gating mechanism. If maintainers want a hard version gate here, it would have to cover the pre-existing MERGE_PARTS trailer too; happy to follow whichever direction they prefer.
isMergeOfPatchPartsBlocked only scanned queued MERGE_PARTS entries. Now that MUTATE_PART entries also pin patch_parts, a patch-part merge could consume a patch part pinned by a queued mutation before that mutation runs; the mutation then rejects the covering patch part and every replica falls back to fetching a mutated part nobody produced, stalling the queue. Scan MUTATE_PART entries too, matching the sibling isDropOfPatchPartBlocked which already handles both types. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed both automated review findings in baa86e0:
|
…t_deletes_sync=1 The DELETE runs as a heavyweight mutation (lightweight_delete_mode defaults to alter_update) whose sync mode comes from lightweight_deletes_sync (default 2 = wait on all replicas), which overrides the test's mutations_sync=0. The test stops fetches on node2 on purpose, so with sync=2 the DELETE on node1 blocks waiting for node2 to apply the mutation and hangs until the query timeout. Set lightweight_deletes_sync=1 so the DELETE waits only for the local replica. The MUTATE_PART entry that pins the patch parts is still created and applied by node2 later via SYSTEM SYNC REPLICA, so the regression assertion is preserved. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed the flaky-check hang in Root cause (from the node1 server log in the failing run): the mutation A Fix: set Verified both directions locally (Integration tests amd, single worker): passes in 20s with the fix; hangs to timeout without it. |
… by exact name Pinning exact patch-part names in a MUTATE_PART log entry (issue ClickHouse#100493) created a residual queue-deadlock window that the isMergeOfPatchPartsBlocked blocker cannot cover: that blocker only postpones a patch-part merge that is still queued. A patch-part merge that already committed on a replica before the mutation was assigned replaces the pinned patch parts with a single covering merged patch. MutateFromLogEntryTask::prepare then rejected the covering patch by exact name (patch_part->name != patch_part_name) and fell back to fetch. If that happened on every replica, no replica could materialize the mutated part and the queue got stuck fetching a part nobody produced. Accept a covering already-merged patch, exactly like source parts already accept a covering part. This is byte-identical to applying the individual pinned patches: patch merges never cross a mutation-version boundary (canMergeParts requires equal mutation versions), the mutation pins every patch in that version bucket, and patch application is version-bounded and keyed by (_block_number, _block_offset) with highest-version-wins. Duplicate pinned names that resolve to the same covering patch are added once. Adds a rmt_merge_task_pause_in_prepare pauseable failpoint so the covering scenario can be reproduced deterministically, and a regression test that fails without the fix (node2 never materializes the mutated part) and passes with it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — fd47e5fCI is fully finished on this head. Every failure below has an owner (a fixing PR or a full-effort fix task); only
Bot review threads (wire-format backward-compat + patch-merge blocker completeness) are all replied to; the covering-patch fix is in fd47e5f. Ready for human review. Session id: cron:clickhouse-worker-slot-4:20260717-005000 |
CI finish ledger — fd47e5fEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260717-070000 |
CI status update — merged master @
|
| Check | Reason | Owner / fixing PR |
|---|---|---|
| AST fuzzer (amd_debug) | client-tool abort Logical error '!part.empty()' in QueryFuzzer::fuzzExpressionList (trunk-wide, 30+ unrelated PRs incl. master) |
#110712 (merged 02:20Z) — merged master @ 50466ace27dde to pick it up |
| Stress test (arm_tsan) | Cannot convert nested result of function JSON_EXISTS ... (STID 4811-66fc, trunk fuzzer, tracked #110345) |
#109944 (ours, open) |
| LLVM Coverage | job killed by a single transient GitHub API 503 in the gh auth pre-step (no retry) |
#110769 (ours, open) |
| Sync | — | CH Inc sync (private, not actionable) |
CI will re-run on 50466ace27dde with the AST fuzzer fix present.
Session id: cron:clickhouse-worker-slot-5:20260717-072500
The assigning replica derived the pinned patch set from its locally visible active patch parts (getPatchPartsVectorForInternalUsage). If that replica lagged on patch replication (a patch part present only as a queued GET_PART, not yet materialized), it pinned an incomplete set, so every replica applied too few patches and converged on the same wrong bytes (silent data loss, issue ClickHouse#100493). Derive the pinned set from the merge predicate's virtual-parts snapshot (current_parts + queue), reusing the same selection MERGE_PARTS applies, so a lagging assigner still pins the complete set. Add a regression test where the assigning replica lags a queued patch and assert the logical post-update result (the previous test only checked replica convergence, which this case satisfies while still being wrong). Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger - 1677845Every failure below has an owner: a fixing PR (ours). Only
The 26 Session id: cron:our-pr-ci-monitor:20260717-193000 |
…-pin-patch-parts # Conflicts: # src/Common/FailPoint.cpp
CI finish ledger — 4673fb4CI fully finished on this head (merge-conflict resolution). Every failure has an owner.
Blocker 1 (MUTATE_PART wire-format) remains explained/deferred to maintainers; blocker 2 (covering-patch accept) + lagging-assigner fix stand. Session id: cron:our-pr-ci-monitor:20260718-160000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 106/107 (99.07%) · Uncovered code |
CI finish ledger — 369fe60Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these is caused by this PR's diff. The Session id: cron:our-pr-ci-monitor:20260729-060000 Correction (2026-08-06): the commit hash in the heading of this comment was wrong. It read |
|
Fixing PR for the |
| /// queue) instead of the replica's locally visible patch parts guarantees that a replica lagging on | ||
| /// patch replication still pins the complete set (issue #100493). | ||
| PartsRange source_range{PartProperties{.name = part.name, .info = part.info}}; | ||
| auto patches = DB::getPatchesToApplyOnMerge(it->second, source_range, mutation_version); |
There was a problem hiding this comment.
The pin is taken from patches_by_partition, which is deliberately truncated by committing blocks; combined with need_patch_parts = !patches_pinned, a lightweight update below the mutation version can be dropped on every replica can this produce a silent data loss?
There was a problem hiding this comment.
Confirmed, and it is worse than a maybe. Two reads of committing blocks are involved and they disagree.
The pin is built from the predicate's patches_by_partition, which comes from the committing-blocks overload that drops every patch with data_version >= it->second.begin()->number (PatchPartsUtils.cpp:391, built at ReplicatedMergeTreeMergePredicate.cpp:137). The predicate loads those blocks with with_data=false (:105), so every block arrives as Op::Unknown and the truncation cannot even tell an Update from an ordinary insert: any concurrent in-flight insert with a lower block number truncates the list.
On the executing side need_patch_parts = !patches_pinned (MutateTask.cpp:3651) plus addPatches (:3659) mean that once anything is pinned, local re-derivation is off and exactly the pinned set is applied. So a patch that is below the mutation version but truncated out of the assignment-time snapshot is dropped on every replica identically: no checksum mismatch, no stalled queue, just missing rows. That is strictly worse than the divergence this PR set out to fix.
havePendingPatchPartsForMutation does not cover it. It postpones on an uncommitted Op::Update block or a queued patch GET_PART (ReplicatedMergeTreeQueue.cpp:366-411), at execution time, against a separate with_data=true read (:2126). It says nothing about a patch that was already committed and merely truncated out of the assignment snapshot.
The root mistake is mine: I reused the merge-side selection for the pin. For MERGE_PARTS an under-selected patch set is safe, because the patch stays active and a later merge or read still applies it. For a MUTATE_PART that pins, the same under-selection is permanent, precisely because pinning disables re-derivation. So the selection cannot be shared as-is.
I am reworking it rather than patching the guard. The direction I intend is to derive the pin from the untruncated patch snapshot and refuse to assign the mutation at all while any patch at or below the target mutation version is not yet resolvable, so the entry is either complete or not written. If you would rather see the pin dropped entirely for versions with in-flight blocks, say so and I will do that instead.
| /// because checkString() consumes the matching prefix even on a partial mismatch. | ||
| if (!patch_parts.empty()) | ||
| { | ||
| out << "\nmutation_patches: " << patch_parts.size(); |
There was a problem hiding this comment.
New trailing field is not readable by older binaries; the entry parse throws, so it takes down queue loading on that replica.
There was a problem hiding this comment.
Confirmed. My earlier answer on this thread was wrong to leave it as a policy question.
Old binaries know only alter_version and to_uuid in the mutate loop, so mutation_patches: falls through to the else that sets trailing_newline_found. The bytes stay unconsumed, and the reader then reaches the unconditional in >> "quorum: " guarded only by !in.eof(), which throws. Independently of that, ReplicatedMergeTreeLogEntry::parse ends in assertEOF (ReplicatedMergeTreeLogEntry.cpp:532), so any unconsumed trailer throws by construction. The throw lands while loading queue entries (StorageReplicatedMergeTree.cpp:3635, :7787, :7858), which is the queue-loading break you describe.
What I argued before was that this trailer is byte-symmetric with the apply_patches: trailer MERGE_PARTS already ships (7f5a42a). That part is true, but it is not a licence: that commit is in 26.6 and 26.7 and absent from every older tag, so the set of binaries that can parse apply_patches: is not the set that can parse mutation_patches:, and one already-existing break does not justify adding a second. This needs a real gate rather than an explanation, and I will not push the trailer without one.
Which gate do you want: a ReplicatedMergeTreeLogEntry format-version bump, or writing the field only once every replica is known to understand it? I have no per-replica binary version in ZooKeeper to key the second on (only metadata_version per replica), so unless you know of one I would go with the format-version bump.
| # that node2 executes to completion (node1's copy of it stays paused), so node2 ends up with only | ||
| # the covering merged patch and the two pinned names become inactive there. | ||
| node2.query( | ||
| f"OPTIMIZE TABLE t_lwu_cover PARTITION ID '{patch_partition}' FINAL", |
There was a problem hiding this comment.
IIUC test_lwu_replicated_mutation_accepts_covering_patch cannot reach the covering-patch branch; it exists to protect and that branch is now untested?
There was a problem hiding this comment.
Correct, and it is my own later commit that broke it. Not the earlier oracle gap: that one was about the pins_patches test using node1 as its own oracle. This is a reachability defect, newly introduced.
The test pauses node1's merge and runs the OPTIMIZE on node2 so that node1 still holds the two individual patch parts and pins their exact names. That worked when the pin came from node1's local active parts (fd47e5f). After 1677845 the pin comes from the queue virtual-parts snapshot instead: the OPTIMIZE creates a replicated MERGE_PARTS entry, the predicate constructor pulls the log (ReplicatedMergeTreeMergePredicate.cpp:107), insertUnlocked adds the entry's virtual part name (ReplicatedMergeTreeQueue.cpp:417-423), and ActiveDataPartSet::addImpl erases the parts it covers (ActiveDataPartSet.cpp:128-143). So node1 pins the covering name even with its own merge paused, node2 resolves that name directly, and the accept-covering branch at MutateFromLogEntryTask.cpp:163-190 is never entered.
The branch itself is still needed, for a patch merge that committed before the assigning predicate pulled the log, so the fix is to restructure the test to produce that ordering rather than to drop the branch. The two commits were validated in separate rounds and nothing re-ran the older test against the newer pin source, which is how it went unnoticed.
I will fold this in with the pin rework on the other thread, and I will gate it on a mutation that breaks the branch deliberately and shows the test failing, so reachability is demonstrated rather than assumed.
…-pin-patch-parts Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #100493
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
CHECKSUM_DOESNT_MATCHerrors and a stuck mutation loop that could occur onReplicatedMergeTreetables using lightweight updates (enable_block_number_column/enable_block_offset_column) under concurrentINSERT/UPDATE/DELETE. AMUTATE_PARTreplicated log entry now records the exact set of patch parts to apply, so all replicas produce a byte-identical mutated part.Description
Fixes #100493.
Unlike
MERGE_PARTS, aMUTATE_PARTreplicated log entry did not record the set of patch parts (produced by lightweight updates) that must be applied while producing the mutated part. Each replica derived the applicable patches from its own local visible state (MutateTask::prepare->getMutationsSnapshot(need_patch_parts=true)). When a patch part was committed on the replica that assigned the mutation but not yet replicated to another replica, the two replicas executing the sameMUTATE_PARTentry applied different patch sets and produced byte-different mutated parts. This raisedCHECKSUM_DOESNT_MATCH("Data after mutation is not byte-identical to data on another replicas"), and the losing replica got stuck fetching the part, hanging the cluster under load. This matches the reporter's setup exactly: same-version 2-node cluster,ReplicatedReplacingMergeTreewith block-number/offset columns, concurrentINSERT/UPDATE/DELETE.The fix mirrors how merges already pin patch parts:
createLogEntryToMutatePartrecords the applicable patch parts (partition match +data_version < mutation_version) intoentry.patch_parts.ReplicatedMergeTreeLogEntryserializes/parses them forMUTATE_PART(fieldmutation_patches:; distinct leading character from the other mutate fields becausecheckStringconsumes a matching prefix).MutateFromLogEntryTask::prepareresolves the pinned patch parts locally, waiting for exactly that set and falling back to fetching the mutated part if one is missing (mirrorsMergeFromLogEntryTask).MutateTask::prepareapplies exactly the pinned set instead of deriving from local visible state.The new log-entry field is written only when patch parts exist, i.e. only for tables using lightweight updates, so behavior is unchanged for existing setups.
Validation (single server, two co-located
ReplicatedMergeTreereplicas, block columns on, 200k rows, concurrent mixed lightweightUPDATE+DELETE+OPTIMIZE FINAL, identical config):CHECKSUM_DOESNT_MATCH("Data after mutation is not byte-identical") onMutateFromLogEntryTask.Note: the added integration test (
test_lwu_replicated_mutation_pins_patches) was authored to exercise the divergent-patch window deterministically, but I was unable to run the Docker-based integration suite locally in this environment; the fix itself was validated with the stress reproducer above.Workflow [PR]
Sync PR [sync-upstream/pr/110674]