Skip to content

Cover the outdated parts left on disk with the empty part of a drop range - #120980

Merged
alexey-milovidov merged 10 commits into
masterfrom
fix-intersecting-covering-part
Oct 5, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
fix-intersecting-covering-part

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

REPLACE PARTITION (and the DROP_RANGE handling of ReplicatedMergeTree) writes an empty part covering the range it drops, so that a restart before the removed parts are unlinked does not resurrect them. The block range, the level and the mutation version of that covering part were derived from the active parts being removed only.

Parts that had been outdated earlier are still on disk — they are unlinked only once old_parts_lifetime has passed — and the ones that no active part covers (a part removed by DROP PART, or an empty part dropped in the background) are seen by the part loader after a restart. MergeTreePartInfo::contains demands a strictly greater level when the block ranges differ, so such a leftover whose level is not below the level of the covering part is neither contained in it nor disjoint from it, and PartLoadingTree::add throws:

Part 1_2_2_1 intersects previous part 1_1_3_1. It is a bug or a result of manual intervention. (LOGICAL_ERROR)

The table cannot be attached; when this happens while loading tables at startup, the server does not start.

The same mismatch also defeated the removal ordering in grabOldParts, which keeps an empty covering part until everything it covers is gone — a part the covering part does not formally contain can be unlinked in any order.

Now the leftovers inside the dropped block range are taken into account as well when computing the range, the level and the mutation version of the covering part.

Found by Stress test (arm_debug) on master, where the concurrent ATTACH PARTITION FROM / REPLACE PARTITION / MOVE PARTITION of 04004_move_partition_bidirectional_deadlock left 1_17_17_1 on disk next to the covering part 1_12_60_1, after which the server could not start:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=bac1295e647c578c6f181ee07b693bcbe8daf328&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29

The same failure (STID 3562-495d) has been appearing on master and in pull requests since July 2026. There is no tracking issue for it.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix Part ... intersects previous part ... when attaching a MergeTree table after REPLACE PARTITION, if parts outdated by an earlier DROP PART were still on disk. The server could fail to start because of it.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


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

Version info

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

…ange

`removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper` writes an
empty part covering the range it drops, so that a restart before the removed
parts are unlinked does not resurrect them. Its block range, level and mutation
version were derived from the active parts being removed only.

Parts that had been outdated earlier are still on disk - they are unlinked only
once `old_parts_lifetime` has passed - and the ones that no active part covers
(a part removed by `DROP PART`, or an empty part dropped in the background) are
seen by the part loader after a restart. `MergeTreePartInfo::contains` demands a
strictly greater level when the block ranges differ, so such a leftover whose
level is not below the level of the covering part is neither contained in it nor
disjoint from it, and `PartLoadingTree::add` throws `Part {} intersects previous
part {}. It is a bug or a result of manual intervention`. The table cannot be
attached, and when it happens during startup the server cannot start at all.

Take the leftovers inside the dropped block range into account as well when
computing the range, the level and the mutation version of the covering part.

Found by the `Stress test (arm_debug)` job on master, where concurrent
`ATTACH PARTITION FROM` / `REPLACE PARTITION` / `MOVE PARTITION` between two
tables (`04004_move_partition_bidirectional_deadlock`) left `1_17_17_1` on disk
next to a covering part `1_12_60_1`:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=bac1295e647c578c6f181ee07b693bcbe8daf328&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29

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

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47857be]

Summary: ✅


AI Review

Summary

This PR fixes the empty covering-part that REPLACE PARTITION / replicated DROP_RANGE writes before old parts are unlinked: the helper now widens that synthetic part across stale on-disk leftovers and raises its level / mutation high enough for MergeTreePartInfo::contains to actually treat those leftovers as covered. I re-checked the previously discussed edge cases against the current code and tests, including the replicated path and the "no active parts left" case, and I did not find a remaining correctness issue in the changed path.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 47857be.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.70% +0.10%

Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 47857be2ccea0aa76e3eab071eb2ddf752283330 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

…rts left

`REPLACE PARTITION` into a partition whose parts were all dropped earlier reaches
`removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper` with an empty
`parts_to_remove` and writes no covering part. It does not have to: `DROP PART` of the part that
covered the others leaves an empty part of a higher level on top of them, so the leftovers still
cover one another. The loader activates that empty part, not the data underneath it, and
`grabOldParts` unlinks it only once everything it covers is gone
(`EMPTY_PART_COVERS_OTHER_PARTS`).

Co-Authored-By: Claude Opus 5 (1M context) <[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.

Wow! This is fantastic!

@alexey-milovidov alexey-milovidov self-assigned this Sep 21, 2026
@alexey-milovidov

alexey-milovidov commented Sep 21, 2026 •

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120980&sha=4a3c11e3e89b36cd7bc4144c52835f0bb1f99188&name_0=PR&name_1=Stress%20test%20%28amd_asan_ubsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

It is unrelated to this pull request (which only changes the block range of the empty part written by a drop range in MergeTreeData). The exception is a planned-vs-actual result type mismatch of plus under an arrayMap lambda:

Logical error: 'Unexpected return type from plus. Expected Nullable(UInt64). Got Nullable(UInt16). Action:
FUNCTION plus(moduloOrNull(value, 1_UInt8) :: 1, value :: 0) -> plus(moduloOrNull(value, 1_UInt8), value) Nullable(UInt64) : 2,
input block structure:moduloOrNull(value, 1_UInt8) Nullable(UInt8) Nullable(size = 1, UInt8(size = 1), UInt8(size = 1)), value UInt8 UInt8(size = 1)'

thrown from DB::executeAction at src/Interpreters/ExpressionActions.cpp:696, reached through DB::ColumnFunction::reduce from FunctionArrayMapped<ArrayMapImpl, NameArrayMap>::executeImplCommon. The lambda's value argument is UInt8 in the executed block while the actions DAG was built for a wider type, so plus yields Nullable(UInt16) where Nullable(UInt64) was planned.

It is a master failure, not a branch one — STID: 1611-45e7 fired on master (pull_request_number = 0) on 2026-09-19 and 2026-09-20 across Stress test (arm_release), Stress test (amd_msan) and Stress test (arm_asan_ubsan, s3), and on 10 unrelated pull requests on 2026-09-20 alone. I could not find a tracking issue for it.

Tracking issue with a deterministic one-query reproducer and the root-cause analysis: #121254

@groeneai

Copy link
Copy Markdown
Collaborator

A fix is already in progress: #121230 (opened 2026-09-20 19:41 UTC, 636cc16e).

It covers this carrier. The failing action here, plus(moduloOrNull(value, 1_UInt8), value) built for Nullable(UInt64) and executed against a block whose value is UInt8, is the shape its test pins with a different modulus: INTERPOLATE (value AS (moduloOrNull(value, 3) AS d) + arrayMap(value -> d + value, [1])[1]).

Two things that are not linked on either thread yet:

#121254 puts the defect in the analyzer rather than in visitColumn, so #121230 may leave part of this signature alive. I will run #121254's modulo(d, value) reproducer against #121230 and report there.

alexey-milovidov and others added 2 commits September 27, 2026 04:45
…er inside the dropped range

The regression test `05229_replace_partition_covers_outdated_parts` only covers plain `MergeTree`.
The new test builds the same state for `ReplicatedMergeTree`: a mutated part `1_1_1_0_2` removed
by `DROP PART` stays on disk (cleanup is stopped) while the mutation is stuck on the only active
part `1_0_0_0`. The covering part written by `REPLACE PARTITION` must take the mutation version of
the leftover (`1_0_3_1_2`), otherwise (`1_0_3_1`) the table fails to attach after DETACH + ATTACH
with "Part ... intersects previous part ...".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits October 3, 2026 13:42
A retry of `INSERT` after an injected Keeper fault allocates a new block number,
so the parts got different names than the ones the test refers to. Disable
`insert_keeper_fault_injection_probability` for the inserts.

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

Copy link
Copy Markdown
Member Author

🕵 Fixed the flaky 05259_replace_partition_covers_outdated_parts_replicated (failing in every flaky check): when an INSERT is retried after an injected Keeper fault, it allocates a new block number. The parts then got other names (e.g. 1_2_2_0 instead of 1_1_1_0), and the test waited for 1_1_1_0_2 in vain. The inserts now set insert_keeper_fault_injection_probability = 0. With insert_keeper_fault_injection_probability = 0.5 in the server profile, the old version of the test hangs locally and the new one passes 8/8. I also merged master, which brings in #122532, the fix for the unrelated 05153_alias_truncate_lock failure.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120980&sha=bd5b410bfdba8b88ae6ea1eab2485697fd47fbe0&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29 (05237_with_expression_alias_scope_descendant: view returns 10 instead of 100 under DatabaseReplicated; 204 failures across many PRs in the last 3 days) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The other failures are unrelated to this PR: the Build (amd_fuzzers) and 05218_timeseries_alp_codec fixes are already on master and were merged into this branch; 01660_join_or_any is addressed by #123683 and 04266_text_index_tokens_cardinality_order by #123688.

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

The fix is in progress: #123790 (it includes the change from my #123774, closed in its favor). In its own run on 2a290a03b667, 05237_with_expression_alias_scope_descendant passes in the arm_binary DBReplicated job.

It is not flaky: under a Replicated database the stored view qualifies the descendant WITH alias nested as a table, so view reads the table (10). Reruns pass because the diagnostic rerun runs without the Replicated database (#112247). The failing run on bd5b410bfdb is from 2026-10-03 16:07Z; the current head 47857be2cce includes #123789, so this job does not run on it until #123790 brings it back with the fix. The newest failure of this test in CIDB is 2026-10-04 18:15Z, on a head older than #123789.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 5, 2026
Merged via the queue into master with commit cbf78c3 Oct 5, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-intersecting-covering-part branch October 5, 2026 19:38
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 5, 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-bugfix Pull request with bugfix, not backported by default 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