Repository navigation
Leave a part alone while a lightweight update of it is uncommitted - #119155
Conversation
A lightweight update allocates its block number before it writes its patch part, and a plain `MergeTree` selected a part for a heavyweight mutation by data version alone. A mutation started in that window read the part without the patch and wrote a part at a higher data version, which the patch - committed with a lower source data version - no longer applies to: the acknowledged lightweight update was silently lost. The selection now leaves such a part for a later round, which is the counterpart of `havePendingPatchPartsForMutation` on the replicated queue. Closes: #116686
|
Workflow [PR], commit [8a53df6] Summary: ✅
AI ReviewSummaryThis PR fixes a real plain Final Verdict
LLVM Coverage ReportMeasured on commit 8a53df6.
Changed lines: Changed C/C++ lines covered: 43/44 (97.73%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units244 translation units recompiled, 2615 s compile time in total, 244 of them have a recent master baseline. |
…pending-patch-116686
Address the two review threads. `StorageMergeTree::removeCommittingBlock` now triggers `background_operations_assignee` when the released block is a `CommittingBlock::Op::Update`. The block is released by `PlainCommittingBlockHolder` on every exit of a lightweight update, including the ones that write no patch part, so a mutation that `selectPartsToMutate` left alone is retried as soon as it is allowed to run instead of on the next backoff tick. The test no longer waits for the `UPDATE` to appear in `system.processes`, which does not prove that its block number is allocated. It enables the new `mt_lightweight_update_pause_after_block_allocation` failpoint (`PAUSEABLE_ONCE`, placed in `StorageMergeTree::updateLightweight` right after the block number is reserved), waits for the pause with `SYSTEM WAIT FAILPOINT ... PAUSE`, fires the `ALTER TABLE ... UPDATE`, checks that the mutation is postponed with `PostponeReasons::PENDING_LIGHTWEIGHT_UPDATE`, and only then releases the update. Renumbered 05184 -> 05227 after merging master. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pending-patch-116686
|
Opened #122934 on top of this one (both commits kept). It covers the same class of race more broadly: besides a mutation running while a lightweight |
|
📊 Cloud Performance Report
This PR only affects MergeTree background mutations. selectPartsToMutate now holds back a mutation while a lightweight update with a lower block number has not committed yet, and releasing that update's block number now wakes the scheduler. The rest of the diff is a failpoint and a test, and none of it runs during read-only benchmark queries. The two flagged rows, tpch_adapted_1_official Q1 (-20.0%) and Q7 (-16.0%), stay not_sure: both fall on an unstable master baseline split around 2026-10-02 and have noisy history, so the speedups are not attributable to this change. No performance impact is expected from this PR. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
The test arms a fail point, and the `failpoint_tests_are_isolated` style check requires such tests to be tagged both `no-parallel` and `no-fasttest`. Merge queue failure: https://github.com/ClickHouse/ClickHouse/actions/runs/36954992663 PR: #119155 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pending-patch-116686
|
🕵 @filimonov, thanks. This pull request was merged on 2026-10-03 (merge commit 72006b7), so it does not need to be closed. #122934 is still open; because it includes both commits from this branch, merging the latest Related: #122934 |
Plain `StorageMergeTree` decided what a mutation, a merge or `OPTIMIZE FINAL` may touch from the registered mutations only, while a version can exist before it is registered: a mutation between its file write and its registration, a lightweight `UPDATE` between block allocation and patch commit. Four races followed: two mutations registered out of order because `mutate` released the alter lock before `startMutation` (ClickHouse#122083); a mutation was applied to a part while a lightweight `UPDATE` of it was uncommitted (ClickHouse#116686); a merge spanned an allocated version or recorded a metadata mutation's version past it, so the update's patch was skipped for the merged part; `OPTIMIZE FINAL` retried after waiting for running merges with the predicate and the metadata snapshot built before the wait. `committing_blocks` is the registry of allocated but not yet visible versions. Selectors take a `CommittingBlocksSnapshot` (its `Mutation`/`Update` blocks plus a watermark: the block counter at the copy, read under the allocation mutex) while holding `currently_processing_in_background_mutex` and pass it to the merge predicate. The first such block above a part's data version bounds mutation selection, refuses merges across it, caps the merged part's recorded version and patch materialization; parts (by `min_block`) and patches above the watermark do not take part in that selection, so nothing allocated after the copy can lie between two things a selection compares. `mutate` keeps the alter lock through `startMutation`; `alter` keeps its rename mutation's block reserved until the metadata is published or rolled back and finds the mutation by version on rollback; `OPTIMIZE FINAL` rebuilds the predicate, the collector and the metadata snapshot on every retry. Built on top of ClickHouse#119155 (its two commits kept) and supersedes it: the committing-block scan guarded by `supportsLightweightUpdate()` is replaced by the snapshot; its reason string and test are kept. Tests: 05291, 05292, 05294-05299, 05302, 05304 (failpoint-driven; 05294 arm 2, 05295 and the restored-part arm of 05297 are guards that also pass without the fix), 05227 from ClickHouse#119155. Closes: ClickHouse#122083 Closes: ClickHouse#116686 Signed-off-by: Mikhail Filimonov <[email protected]>
…boundaries, with two codex reviews Codex round 1 on the reservation-bound fix found it insufficient (merge predicate crosses an unregistered mutation, barrier ALTER misses it, alter lock released before startMutation by an if-initializer scope). Round 2 on the alter-lock fix accepted the production change and rejected the PAUSEABLE failpoint in the test. The design proposes one rule, superseding upstream PR ClickHouse#119155: an uncommitted Mutation or Update reservation is a provisional mutation version for mutation selection, merge predicate and patch selection, plus the alter-lock fix. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01V8mZSGiD8iJumpJMiQnrmC
… the audit of upstream PR ClickHouse#119155 Design review round 1: invariant accepted; asked for an explicit firstVersionReservationAfter helper instead of overloaded accessors, distinct postpone strings, corrected lifetime argument (update holders outlive patch commit), transaction-rollback recheck as an Antalya prerequisite, the orphan-file limitation stated, the StorageAlias::alter gap, and a test plan without the invalid mirror arm. Audit of ClickHouse#119155: its guard is skipped when supportsLightweightUpdate() is false, which a settings ALTER can cause while an update holds its reservation; its SYSTEM WAIT FAILPOINT has no timeout. rev.2 incorporates all of it. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01V8mZSGiD8iJumpJMiQnrmC
…cisions on a coherent cut Round 2 found the reservation snapshot taken before the parts are read (in the merge predicate constructor and in PR ClickHouse#119155's mutation selection), so a reservation allocated in between is missed while a part committed above it is seen. rev.3 states the cut (parts and patches first, then reservations), makes rule 3 the generalization of min_update_block with the 0-as-infinity sentinel handled, wakes on Unknown too, settles StorageAlias::alter (fix it here) and the Antalya transaction recheck (own pull request first), replaces the green S3b with two late-reservation tests, and makes S1, S2 and S3 deterministic. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01V8mZSGiD8iJumpJMiQnrmC
…omic allocate-and-announce, fresh predicate after the OPTIMIZE FINAL wait, barrier waits for registration Round 5 accepted the restated model as the shape a maintainer would take and gave three exact closures: allocation and announcement are one step under the selection mutex (MOVE announces before its parts lock; never the background mutex under a parts lock); OPTIMIZE FINAL rebuilds its predicate and collector after every wait that released the mutex; a barrier ALTER waits for a pending mutation to register before waitForMutation. Accessors renamed to boundary terminology, guard gets an erase-while-locked operation, ClickHouse#119155's removeCommittingBlock wake-up dropped, Debug logs for pending insert/erase, tests S6 and S7 added. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01V8mZSGiD8iJumpJMiQnrmC
… (spec rev.10), upstream target on top of ClickHouse#119155 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01V8mZSGiD8iJumpJMiQnrmC
…date of it is uncommitted A mutation could pick a part while a lightweight `UPDATE` with a lower block number had not written its patch part yet; the mutated part then skipped the patch and the acknowledged update was lost. This branch needs it as the base of ClickHouse#124167 (lost lightweight `DELETE` in CI). Upstream: ClickHouse#119155 Upstream merge commit: 72006b7 Commits of the upstream pull request: - 8a53df6 Merge remote-tracking branch 'origin/master' into mergetree-mutation-pending-patch-116686 - 7638e85 Tag `05227_mutation_waits_for_lightweight_update` as `no-fasttest` - d9f77ec Merge remote-tracking branch 'origin/master' into mergetree-mutation-pending-patch-116686 - 4398d33 Wake up the postponed mutation and make the test deterministic - cf21123 Merge remote-tracking branch 'origin/master' into mergetree-mutation-pending-patch-116686 - ea880f9 Merge branch 'master' into mergetree-mutation-pending-patch-116686 - 8db4dc2 Leave a part alone while a lightweight update of it is uncommitted Adaptation for antalya-26.8: - None: applied as is. (cherry picked from commit 72006b7) Signed-off-by: Mikhail Filimonov <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
On a plain
MergeTreetable, a heavyweightALTER TABLE ... UPDATE(orDELETE) that runs while a lightweightUPDATEis still in flight silently dropped the acknowledged lightweight update: both statements returned success and the updated rows reverted to their previous values, with no error anywhere.A lightweight update allocates its block number before it writes its patch part.
StorageMergeTree::selectPartsToMutateselected a part for a mutation by data version alone, so a mutation started in that window read the part without the patch and wrote a part at a higher data version; the patch, committed afterwards, has a lower source data version and no longer applies to it.ReplicatedMergeTreepostpones such an entry inReplicatedMergeTreeQueue::havePendingPatchPartsForMutation, and the plain engine has no equivalent -waitForCommittingInsertsAndMutations, its only drain primitive, deliberately skipsCommittingBlock::Op::Update. The selection now leaves a part alone while an uncommitted lightweight update holds a block number at or below the version the mutation would produce, which is the selection-side counterpart of that guard.Closes: #116686
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed a concurrent heavyweight
ALTER TABLE ... UPDATE/DELETEsilently dropping an acknowledged lightweightUPDATEon a plainMergeTreetable.Workflow [PR]
Sync PR [sync-upstream/pr/119155]
Version info
26.10.1.1374-master(included in26.10and later)