Skip to content

Do not let cancellation interrupt the rollback of a merge or mutation - #127263

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-transaction-rollback-cancellation
Oct 23, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-transaction-rollback-cancellation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

When a mutation is killed while its part is being committed, the commit fails, and MergeTreeData::Transaction::rollback runs in the mutation's thread, under the mutation's query cancellation predicates. Reading the version metadata in setAndStoreCreationCSN then threw Cancelled mutating parts (in ClickHouse Cloud, from the distributed cache read buffer). As a result, the rolled-back part was left Outdated without RolledBackCSN. getMaxLevelMutationInBetween does not skip such a part, so merges of its neighbours, including OPTIMIZE ... FINAL, are refused with There is an outdated part in a gap between two active parts until the part is removed.

This made 01168_mutations_isolation flaky in the private repository. Sequence: kill mutation cancelled mutation_15.txt of tx 8 just as it was committing all_1_1_0_15. The RolledBackCSN store for that part failed. OPTIMIZE TABLE mt FINAL in tx 7 then did nothing, the mutation of tx 10 succeeded instead of getting the expected serialization error, and the mutation of tx 7 failed with part all_1_1_0_13 is locked by transaction ....

The fix holds a ThreadStatus::QueryCancellationBlocker during the rollback, as MergeTreeTransaction::rollback already does. The blocker is also carried into ThreadPool jobs, so it covers the asynchronous remote reader.

Example failure: https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/praktika.html?PR=82719&sha=b87fa9bb1fa635e3ef67043098f0931d959a45ca&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20cache%2C%20meta%20in%20keeper%2C%20s3%20storage%2C%20parallel%29

Related: https://github.com/ClickHouse/clickhouse-private/pull/82719
Related: https://github.com/ClickHouse/clickhouse-private/issues/13092

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127263]

Version info

  • Merged into: 26.11.1.694-master (included in 26.11 and later)
  • Backported to: 26.10.3.19

When a mutation is killed while its part is being committed, the commit fails and
`MergeTreeData::Transaction::rollback` runs in the thread of the mutation, under its query
cancellation predicates. Reading the version metadata in `setAndStoreCreationCSN` then threw
`Cancelled mutating parts` (in ClickHouse Cloud, from the distributed cache read buffer), so the
rolled back part was left Outdated without `RolledBackCSN`. Such a part is not skipped by
`getMaxLevelMutationInBetween`, and merges of its neighbours (including `OPTIMIZE ... FINAL`) are
refused with "There is an outdated part in a gap between two active parts" until it is removed.

This made `01168_mutations_isolation` flaky: `OPTIMIZE TABLE mt FINAL` in tx 7 did nothing, so the
mutation of tx 10 did not get the expected serialization error, and the mutation of tx 7 failed instead.

Use `ThreadStatus::QueryCancellationBlocker` during the rollback, as `MergeTreeTransaction::rollback` does.

Related: ClickHouse/clickhouse-private#13092
Example failure: https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/praktika.html?PR=82719&sha=b87fa9bb1fa635e3ef67043098f0931d959a45ca&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20cache%2C%20meta%20in%20keeper%2C%20s3%20storage%2C%20parallel%29
PR: ClickHouse/clickhouse-private#82719

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1e772fe]

Summary: ✅


AI Review

Summary

Reviewed PR #127263 at 1e772feac2e41afa0e3b3ff60ec8a7fd54a55019. The change protects MergeTreeData::Transaction::rollback from query cancellation while persisting rollback metadata and updating the working set, including reads scheduled through ThreadPool. No actionable findings.

Missing context / blind spots
  • ⚠️ No local build or test run. The existing 01168_mutations_isolation and 01168_mutations_isolation_2 tests passed in the initial fix commit's debug job. The corresponding current-head results were not yet available; a completed distributed-cache run would provide end-to-end confirmation in the originally affected environment.
Final Verdict

✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Oct 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1e772feac with master 479496ca1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

7 object files changed (-74.43 KiB total), 1 added.

Object file Master PR Δ
base/poco/NetSSL_OpenSSL/CMakeFiles/_poco_net_ssl.dir/src/EmbeddedCertificates.cpp.o 601.84 KiB 521.19 KiB -80.64 KiB (-13.40%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 45 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127263&sha=85c0301d2b5d76006ff1e2096b1bcfac0dce2689&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 (Logical error: Part A intersects previous part B while loading tables in Upgrade check (amd_release)) and provide a fix in a separate PR. If the fix is already in progress, link it here. It is unrelated to this PR: in the last 30 days it failed in about 50 different PRs, and no tracking issue exists yet.

The other failures (02317_distinct_in_order_optimization, 05407_merge_tree_max_rows_to_use_cache_max_value under parallel replicas) are fixed on master by #127002 and #127290; master is now merged into this branch.

@groeneai

Copy link
Copy Markdown
Collaborator

This is the rolled-back TRUNCATE empty-part leak fixed by #122375, in the old release that the Upgrade check runs before upgrading.

In this run the stress phase ran v26.9.24.8. TRUNCATE TABLE dedup_alias_target (04102_storage_alias_insert_dedup_token.sql) created the empty parts all_1_1_1 to all_5_5_1, the injected MEMORY_LIMIT_EXCEEDED in MetadataOperationsHolder::commit rolled it back, and the empty parts stayed on disk. A merge of the original parts then produced all_1_5_1, and the 26.11 server fails at startup with Part all_1_5_1 intersects previous part all_1_1_1.

#122375 (merged 2026-10-09) is in master and in the 26.10 branch, but in no 26.9 release (checked up to v26.9.25.15). The Upgrade check installs the newest release below the PR's version (ci/tools/get_previous_release_tag.py), so this stops with the first 26.10 release, or earlier if #122375 gets v26.9-must-backport (asked on #118681).

Until then, PR CI stops blocking on it if an open issue labelled testing has Test name: Logical error: Part A intersects previous part B. It is a bug or a result of manual intervention (STID: 2002-2037) in its body (ci/praktika/issue.py). I can open that issue if you want, but I cannot set the label.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai. So this is the rolled-back TRUNCATE empty-part leak in 26.9 releases, which #122375 fixes. Nothing needs to change in this PR. Please open the tracking issue with the Test name line; a maintainer can add the testing label. The Upgrade check on the current head (1e772fea, which includes the latest master) did not fail.

@groeneai

Copy link
Copy Markdown
Collaborator

Opened #127591 with the Test name line. CI starts matching it once it has the testing label. I will close it when the first 26.10 release, or a 26.9 backport of #122375, is out.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 23, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, approved.

@alexey-milovidov alexey-milovidov self-assigned this Oct 23, 2026
Merged via the queue into master with commit afe17f6 Oct 23, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-transaction-rollback-cancellation branch October 23, 2026 23:45
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 23, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 29, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 29, 2026
Backport #127263 to 26.10: Do not let cancellation interrupt the rollback of a merge or mutation
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants