Skip to content

Write the empty covering part before removing the covered parts - #122610

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-empty-covering-part-before-removal
Oct 3, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-empty-covering-part-before-removal

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper removed the parts of the drop range from the working set before writing the empty covering part. If createEmptyPart threw (here: a MEMORY_LIMIT_EXCEEDED fault injected during the stress phase of the Upgrade check), the parts were already outdated with no covering part. The queued REPLACE_RANGE then saw no active parts ("Replacing 2 parts ... with empty set"), skipped the covering part because parts_to_remove was empty, and removed the parts from ZooKeeper only. They stayed on disk, and the next load of the table (02486_truncate_and_unexpected_parts, with replicated_max_ratio_of_wrong_parts = 0) failed with TOO_MANY_UNEXPECTED_DATA_PARTS and left it readonly.

The fix writes the covering part before the removal, so a failure leaves the working set unchanged. The part is activated after the removal, because renameTempPartAndAdd requires the covered parts to be gone.

There is no deterministic test: the failure needs an exception at exactly this point.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121145&sha=9a11b79684ac15a56bd16ef7491a5040688a8f7b&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
Related: #121145
Related: #120980

Changelog category (leave one):

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

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1370-master (included in 26.10 and later)

`removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper` removed the
parts in the drop range from the working set first, and only then wrote the empty
covering part with `createEmptyPart`. When writing that part threw (in CI: a
`MEMORY_LIMIT_EXCEEDED` fault injected by the stress run), the parts were already
outdated but no covering part existed. The following `REPLACE_RANGE` then found no
active parts, skipped the covering part, and removed the parts from ZooKeeper
only. They stayed on disk and on the next table load were reported as uncovered
unexpected parts (`TOO_MANY_UNEXPECTED_DATA_PARTS`), leaving the table readonly.

Write the covering part first, so a failure leaves the working set unchanged,
and only activate it after the removal (`renameTempPartAndAdd` requires the
covered parts to be gone).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121145&sha=9a11b79684ac15a56bd16ef7491a5040688a8f7b&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
PR: #121145

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [55cbede]

Summary: ✅


AI Review

Summary

This PR moves empty covering-part creation ahead of removing the covered parts, adds explicit undoTransaction support so object-storage writes are cleaned up on pre-commit failures, and resets packed-part transactions before any post-commit reader initialization. I reviewed the current diff and the prior discussion threads and did not find any remaining correctness issue that still reproduces in the updated code.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 55cbede.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 27/44 (61.36%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 55cbede0f with master 83b3ee2b6 (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

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Sep 30, 2026
Address review: #122610 (comment)

The empty covering part is now written before the covered parts leave the working set. If
`removePartsFromWorkingSet`, `renameTempPartAndAdd` or `commitTransaction` throws in between,
the part storage transaction stays uncommitted. On object storage the part directory does not
exist until the commit, so the destructor of the temporary part removes nothing, and the uploaded
blobs are stranded. Undo the transaction (best-effort) on that path.

`undoTransaction` existed only in the `CLICKHOUSE_CLOUD` build; it is promoted to
`IDataPartStorage` and implemented for `DataPartStorageOnDiskFull` and `DataPartStorageOnDiskPacked`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 33 queries analysed

This PR has no measurable effect on query performance. It changes how MergeTree writes and rolls back the empty covering part during DROP/REPLACE PARTITION, and it makes undoTransaction available on non-cloud builds too. None of the benchmarked SELECT queries run that code. The only two flagged queries are tpch_adapted_1_official Q1 (-18.5%) and Q7 (-16.0%). Both stay not_sure because master's own timings for them shifted recently, so the baseline can't support attribution, and both have noisy history. Neither delta should be read as an improvement from this PR.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 65 53 -18.5% <0.0001 The -18.5% is not attributable to this PR. Q1 is a read-only scan and aggregation, and this diff only changes part-storage transaction undo and the empty covering part written on DROP/REPLACE PARTITION.
⚠️ 7 not_sure 81 68 -16.0% <0.0001 The -16.0% is not attributable to this PR. Q7 is a read-only join query that never runs the partition-drop or part-transaction undo paths this diff changes.

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
  • StressHouse run: dbdbf284-6806-461b-af90-e7852d122f86
  • MIRAI run: e0aa1547-b010-4a87-bd65-4fd48257b8ed
  • PR check IDs:
    • clickbench_2940867_1790963986
    • clickbench_2940879_1790963986
    • clickbench_2940885_1790963986
    • tpch_adapted_1_official_2940896_1790963986
    • tpch_adapted_1_official_2940923_1790963986
    • tpch_adapted_1_official_2940937_1790963987

`DataPartStorageOnDiskPacked::commitTransaction` committed the disk transaction and only then
loaded the reader, still holding the committed transaction. If loading the reader threw, the
caller's undo guard in `removePartsInRangeFromWorkingSet` would call `undoTransaction`, which
removes the written blobs while their metadata is already committed, leaving a committed empty
covering part without its data.

Reset the transaction right after the commit, so `undoTransaction` is a no-op past the point of
no return. Do the same in `tryCommitTransaction`.

Addresses review: #122610 (comment)

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

@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.

This looks good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into master with commit e1541bf Oct 3, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-empty-covering-part-before-removal branch October 3, 2026 02:04
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

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-ci 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