Skip to content

Do not copy the source part's txn_version files into a mutated part - #127074

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:mutation-skip-source-txn-version-files
Oct 22, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:mutation-skip-source-txn-version-files

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108772
Related: #124485

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Experimental transactions: a mutation that runs while a part's transaction metadata is being updated no longer copies the part's txn_version.txt.tmp, so it neither fails with FILE_DOESNT_EXIST on object storage nor produces a part that is dropped as rolled back on the next table load.

Description

A mutation that rewrites some columns of a Wide part hardlinks every other file of the source part. collectFilesToSkip excluded txn_version.txt only if it existed, and never excluded txn_version.txt.tmp, which VersionMetadataOnDisk::storeInfoToDataPartStorage writes and then renames over txn_version.txt when a commit stamps the part's CSN. A mutation that lists the part inside that window copies the temporary file:

  • on a local disk the mutated part keeps a .tmp with the source part's version info, so it is loaded as an uncommitted transaction and dropped on the next load, and its rows are lost;
  • on object storage the hardlink runs at the disk transaction commit, after the rename, and the mutation fails with Can't create hardlink for file .../txn_version.txt.tmp (FILE_DOESNT_EXIST).

The mutated part writes its own version metadata, so both files are now skipped by name. #108772 made the readers tolerate a stray .tmp; this stops the mutation from producing one.

This is the flaky 03752_attach_as_replicated_transaction_metadata, 6 times since June, twice on master: the FILE_DOESNT_EXIST variant (latest) and on master the lost-rows variant (report, count() 1271 instead of 0).

The new test uses two pauseable failpoints to stop COMMIT before the rename and the mutation before it adds its part. Without the fix it fails on every run on local and on encrypted S3 storage; with it, 50/50 randomized runs pass on each.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.582-master (included in 26.11 and later)

groeneai and others added 2 commits October 20, 2026 22:24
Two pauseable failpoints make the race deterministic:
`version_metadata_store_pause_before_rename` stops
`VersionMetadataOnDisk::storeInfoToDataPartStorage` after `txn_version.txt.tmp`
is written and before it replaces `txn_version.txt` (the same name and spot as
in open PR ClickHouse#124485), and `mt_mutate_task_pause_before_rename_part` stops a
plain MergeTree mutation after its disk transaction is committed and before
the new part is renamed into the table.

The test stamps a part's creation CSN with COMMIT paused at the first point,
runs a non-transactional mutation over the part while `txn_version.txt.tmp`
exists, then reloads the table and checks that the mutated part is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`MutateSomePartColumnsTask` hardlinks every file of the source part that is
not in `collectFilesToSkip`. That set took `txn_version.txt` from
`getFileNamesWithoutChecksums`, which lists it only if it exists at that
moment, and never contained `txn_version.txt.tmp`. When the source part's
version metadata is rewritten concurrently (a commit stamping its creation CSN,
e.g. a background merge transaction finalized by the TransactionLog updating
thread), `VersionMetadataOnDisk::storeInfoToDataPartStorage` writes
`txn_version.txt.tmp` and then renames it over `txn_version.txt`, and the
mutation copies the transient file:

- on a local disk the mutated part keeps a `.tmp` with the source part's
  version info and no `txn_version.txt`, so on the next load
  `VersionMetadataOnDisk::loadMetadata` treats it as rolled back and the
  part's rows disappear (the source part is already removed);
- on object storage the hardlink is deferred to the disk transaction commit,
  and if the rename happened first the mutation fails with
  `Can't create hardlink for file .../txn_version.txt.tmp (FILE_DOESNT_EXIST)`.

The new part always writes its own version metadata, so skip both files by
name. ClickHouse#108772 made the consumers tolerate a stray `.tmp`; this closes the
producer.

This is the failure of `03752_attach_as_replicated_transaction_metadata` on
`Stateless tests (amd_debug, distributed plan, s3 storage, parallel)`.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review of the diff.

# Sev Finding Verdict Evidence / action
1 💡 The mutation's untouched-part clone (cloneAndLoadDataPart -> freeze) also copies a live txn_version.txt.tmp DISAGREE (out of scope) Different code: freeze/freezeRemote already remove both files from the copy (#108772), and Backup retries a vanished file on local disks. No CI occurrence of that shape.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261021-000000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05441_mutation_skips_source_txn_version_files pauses COMMIT after txn_version.txt.tmp is written and the mutation after its disk transaction commits. Without the fix it fails on every run: local disk 8/8, encrypted S3 10/10.
b Root cause explained? The some-columns mutation path hardlinks every source file not in collectFilesToSkip, which named txn_version.txt only if it existed and never txn_version.txt.tmp.
c Fix matches root cause? Yes. Both files are skipped by name at the only site that copies a live part's files without an allowlist.
d Test intent preserved / new tests added? New test with a data-loss oracle after DETACH/ATTACH (3 36) plus a guard row (Wide Full) proving the affected path ran. 03752 is not modified.
e Both directions demonstrated? Yes, on local and on encrypted S3 storage: unfixed binary prints 0 0, fixed binary passes 50/50 randomized runs on each storage.
f Fix is general across code paths? The all-columns path hardlinks an allowlist; freeze/freezeRemote already strip both files from the copy.
g Fix generalizes across inputs (params/datatypes/wrappers)? The skip is by file name, independent of column types and settings.
h Backward compatible? (maintainer-approved exception only) Yes. No setting and no on-disk format change; existing parts load as before.
i Invariants and contracts preserved? Every other user of files_to_skip only looks up column, statistics and projection names. 294 transaction/mutation tests show no new failure against the unfixed build.

Session id: cron:clickhouse-impl-slot-4:20261020-222200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano @CurtizJ, could you review this and add the can be tested label so CI runs? A mutation that rewrites some columns hardlinked the source part's txn_version.txt.tmp while a concurrent commit was rewriting it, so on object storage the mutation failed with FILE_DOESNT_EXIST and on a local disk the mutated part was dropped as rolled back on the next load; collectFilesToSkip now skips both txn version files by name.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8a7b6d2]

Summary: ✅


AI Review

Summary

The PR prevents partial-column MergeTree mutations from copying the source part's txn_version.txt and txn_version.txt.tmp, avoiding mutation failures and discarded data on reload. It adds a deterministic regression test for the concurrent metadata rewrite. No actionable findings at commit 8a7b6d25fca742970d5996acc3581f12f2f8e7d0.

Missing context / blind spots
  • ⚠️ Stateless CI results for this revision were pending during review, and tests were not rerun locally because this checkout has no build directory. The PR reports successful local before/after validation on local and encrypted object storage; completed stateless CI would provide independent runtime confirmation.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-experimental Experimental Feature comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). labels Oct 21, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
In the AsyncInsert CI profile (async_insert = 1 in the default user
profile) the INSERT inside the transaction is rejected with
NOT_IMPLEMENTED (async inserts inside transactions are not supported), so
the transaction holds no part, COMMIT never writes version metadata and
SYSTEM WAIT FAILPOINT version_metadata_store_pause_before_rename waits
until the test timeout. Same pinning as 04408, 05161, 05175 and 05385.

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

clickhouse-gh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8a7b6d25f with master 3f1c2fc7b (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.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +2.4 s (+6%) in total before that adjustment.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reasonable.

@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 22, 2026
Merged via the queue into ClickHouse:master with commit 40143fb Oct 22, 2026
179 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants