Repository navigation
Do not merge over a gap containing an outdated part with a higher mutation version - #113941
Conversation
A merge is refused when the block gap it spans holds an outdated part that the merge result would not cover, because such a pair cannot be loaded afterwards: it is neither containing nor disjoint, and `PartLoadingTree::add` throws the `LOGICAL_ERROR` "Part A intersects previous part B. It is a bug or a result of manual intervention", which aborts the server in debug and sanitizer builds. That refusal only compared the part level, while `MergeTreePartInfo::contains` requires both level >= and mutation >=. An outdated part produced by a mutation has level 0, so the level-only test could not see it, and the merge committed a part intersecting it. The table then failed to load on every subsequent `ATTACH` or server start. Such a gap arises when neighbouring parts owe different mutation stacks: a mutation that succeeds on one part and throws on the next leaves them at different versions, and once it is killed the surrounding parts can be merged into a result whose mutation version is below the one in the gap. `getMaxLevelInBetween` now also accumulates the maximum mutation version over the gap and is renamed `getMaxPropertiesInBetween` accordingly. The new test compares against `max(left.mutation, right.mutation)` rather than the exact result version, which is not available in a pairwise predicate: it is computed later in `FutureMergedMutatedPart::assign`, over a range that is itself chosen afterwards, and patch parts can raise it further. Because the exact version is a maximum over a superset of any adjacent pair, comparing against the pairwise maximum can only refuse a merge earlier than strictly necessary, never admit one it should refuse. The level test beside it already uses the same conservatism. The refusal is not fatal: the selector picks another range and the merge proceeds once `old_parts_lifetime` removes the outdated part. Only an explicit `OPTIMIZE` with `optimize_throw_if_noop` surfaces `CANNOT_ASSIGN_OPTIMIZE`. The replicated merge predicate does not share this hole. It probes the gap with a synthetic part at `MAX_LEVEL` and `MAX_BLOCK_NUMBER` and asks `getPartsCoveredBy`, which uses `contains`; that probe dominates on both terms, so a part in the gap is reported whatever its mutation version. The test builds the gap with one row-dependent mutation that empties the middle part and throws on its neighbour, and then kills it. It waits for the empty result to be committed before the `KILL`: mutation work is per part and its outcomes are published independently, so a non-empty `latest_fail_reason` can become visible first, and the `KILL` would then cancel the still pending task through `MergeList::cancelPartMutations`, leaving no gap part at all. Closes ClickHouse#113864.
Internal second-model review (click to expand)Two independent cold reviews plus three adversarial second-model passes over this change. Findings
Verification recorded for this change: a deterministic standalone reproduction (3 of 3) and the Session id: cron:clickhouse-review-slot-9:20260808-105200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260808-033700 |
|
cc @Michicosun @CheSema, could you review this? The gap guard in |
|
@groeneai It is most likely an incorrect fix. This algorithm has been working for more than 10 years. What query produced covering parts? Give me a link to the CI. If there is no link, close this pr. Remember, it is very unlikely you need to change the Compaction folder of the merge tree. |
|
@Michicosun CI links, both
The parts are not covering, they intersect: Producing sequence for
On the age: the gap guard is If you would rather the missing term were checked somewhere other than the merge predicate, tell me where and I will move it. The disposition of this PR is yours. |
|
Workflow [PR], commit [b5b6401] Summary: ✅
AI ReviewSummaryThis PR fixes the original load-time Findings
Final VerdictChanges requested. The original corruption fix is correct, but the remaining pairwise over-refusal and exact-duplicate rolled-back path are still real regressions in the current code. LLVM Coverage ReportMeasured on commit b5b6401.
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
| /// Compared against the pairwise max, not the exact result mutation version, which is only | ||
| /// known later in `FutureMergedMutatedPart::assign`. The exact version is a max over a | ||
| /// superset of this pair, so this test may over-refuse but never under-refuse. | ||
| if (max_possible.mutation > std::max(left.info.mutation, right.info.mutation)) |
There was a problem hiding this comment.
The "may over-refuse" caveat becomes user-visible in OPTIMIZE FINAL. selectAllPartsToMergeWithinPartition validates the whole partition with canMergeAllParts and aborts on the first rejected adjacent pair (MergeTreeDataMergerMutator.cpp:389-395), but the final part's mutation is computed later from the maximum across the whole range plus applied patch parts (FutureMergedMutatedPart.cpp:56-76 and MergeTreeDataMergerMutator.cpp:426-430).
That means a partition can be mergeable as a whole even though some adjacent pair is not. For example, active parts with mutations 45, 45, 100 and an outdated gap part at 59 between the first two parts should be valid for one final merge, because the result mutation is 100 and contains the gap part. This pairwise check still rejects the first pair and surfaces CANNOT_ASSIGN_OPTIMIZE before the range-level max is visible.
This needs a range-level gap check for OPTIMIZE FINAL, or the exact future mutation version passed into the whole-range validation, rather than treating the pairwise bound as harmlessly conservative.
There was a problem hiding this comment.
Confirmed: the shape is real and I reproduced it. Correcting my own "may over-refuse" comment, which implied it was not observable.
Fixture (debug binaries, Build IDs asserted): all_1_1_0 at mutation 0, outdated all_2_2_0_5 at 5, all_3_3_0 at 0, all_4_4_0_6 at 6. It needs a prerequisite the report does not mention: two KILLed partially-failed mutations, so the registry is empty and the pre-existing different-mutation-version check at MergeTreeMergePredicate.cpp:50-56 does not reject the pair first.
- pristine master
3ca195b2:OPTIMIZE FINALsucceeds, producesall_1_4_1_6, reattach loads 3 rows. The result does containall_2_2_0_5, so the merge is safe. - this branch
8856884b: refused, "with mutation version 5 higher than these active parts have". - control, same fixture without the gap part, this branch:
OPTIMIZE FINALsucceeds.
The two claims about the code are also correct: canMergeAllParts returns on the first rejected adjacent pair, and FutureMergedMutatedPart::assign takes the max over the whole range plus applied patch versions.
I am not changing the predicate, for two measured reasons.
The conservatism is not introduced here. The same over-refusal exists on pristine master in the level dimension, with every part at mutation 0 so this term is irrelevant: all_1_5_2, all_6_6_0, outdated all_7_7_1, all_8_8_0. The whole-range result all_1_8_3 contains all_7_7_1, yet master refuses with "with merge level 1 higher than these active parts have". The pairwise-versus-range-max approximation belongs to the original gap guard (c51f4d7be1e0eaa, 2023-01-05); this change adds the second term MergeTreePartInfo::contains already requires.
At default settings nothing surfaces. optimize_throw_if_noop defaults to false, and StorageMergeTree.cpp:2381-2389 logs and returns false unless it is set, so OPTIMIZE TABLE t FINAL is a silent no-op; the server log confirms the term fired. Merging still progresses: a plain OPTIMIZE compacted the other sub-range to all_3_4_1_6, 3 active parts down to 2. And it clears itself once the outdated directory is removed after old_parts_lifetime, after which OPTIMIZE FINAL succeeds.
So the residual is a pre-existing conservatism in both terms whose effect at defaults is a temporary skipped merge, against a LOGICAL_ERROR on reattach in the non-contained case. Threading the exact future mutation version into whole-range validation is the more principled shape, but it is a redesign of the 2023 guard in a folder the code owner has asked me not to change, so it does not belong in this bugfix.
I am also not adding the suggested test: pinning the over-refusal would lock in behaviour a future range-level fix should be free to change.
There was a problem hiding this comment.
Pushed bb93a2eb: the mutation term now skips outdated parts whose creation was rolled back.
01168_mutations_isolation failed deterministically on cf5afe5b (16/16: 7/7 with randomized
settings, 9/9 without, per the randomization diagnosis, on amd_debug and arm_binary). The
term fired exactly once in the whole job, inside that test:
{...01168_mutations_isolation_..._tx7_...} test_....mt: Cannot OPTIMIZE table: There is an
outdated part in a gap between two active parts (all_1_1_0_13, all_7_7_0_13) with mutation
version 15 higher than these active parts have
mutation is the last component of the data_parts_by_info sort key
(MergeTreePartInfo::toTuple), so a higher mutation version of an endpoint sorts between the
endpoints and was scanned as if it lay in the block gap. all_1_1_0_15 got there because
tx 8 starts a mutation that is then killed, leaving it Outdated with creation_csn set to
Tx::RolledBackCSN while the active endpoints are still at 13.
Refusing over such a part is pointless: MergeTreeData::loadDataPart deactivates a part whose
creation was rolled back, so it never enters the set PartLoadingTree::add checks for
intersections, and add skips it again on its rolled-back branch. It cannot produce the
intersects previous part error this predicate exists to prevent.
Three arms, each Build ID asserted (readelf -n == buildId()), on the rolled-back shape:
pristine master accepts, cf5afe5b refuses via the mutation term, bb93a2eb accepts. The
guard is not weakened: 04812_merge_over_gap_with_mutated_part and 02521_merge_over_gap both
pass, and pristine master still aborts 04812 with
Part all_2_2_0_3 intersects previous part all_1_4_1.
On the earlier over-refusal point: unchanged and still pre-existing. It reproduces in the level
dimension on pristine master with every part at mutation 0, so it belongs to the 2023 guard
rather than to this change.
The mutation term added to the gap predicate walks `data_parts_by_info` between the two active endpoints. `mutation` is the last component of that index's sort key (`MergeTreePartInfo::toTuple`), so every higher mutation version of an endpoint sorts between the endpoints and is scanned as if it were a part in the block gap. `01168_mutations_isolation` hits exactly that: a transactional mutation is started and then killed, which leaves `all_1_1_0_15` Outdated with `creation_csn` set to `Tx::RolledBackCSN`, while the active endpoints are still at mutation version 13. The following `OPTIMIZE TABLE mt FINAL` was refused with `There is an outdated part in a gap between two active parts (all_1_1_0_13, all_7_7_0_13) with mutation version 15 higher than these active parts have`. Refusing there is pointless: `MergeTreeData::loadDataPart` deactivates a part whose creation was rolled back, so such a part is never in the loaded set the intersection check in `PartLoadingTree::add` runs over, and it cannot produce the `intersects previous part` logical error the gap predicate exists to prevent. `PartLoadingTree::add` skips it a second time on the rolled back branch. Verified on Build ID asserted debug binaries: the PR head refuses the rolled back shape while both pristine master and this change accept it, and both `04812_merge_over_gap_with_mutated_part` and `02521_merge_over_gap` still pass, so neither the level term nor the committed part case is weakened.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units20 translation units recompiled, 140 s compile time in total, 20 of them have a recent master baseline. |
CI finish ledger - bb93a2eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Report for the failing check: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113941&sha=bb93a2ebd5e4fb14fe38c39f0ec1f8244c991d67&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 157 checks succeeded, 17 skipped, 1 failed. Session id: cron:our-pr-ci-monitor:20260809-063000 |
Michicosun
left a comment
There was a problem hiding this comment.
- Remove comments
- GapPartProperties should not be in the part properties file, just return std::pair from getMaxLevelMutationInBetween
| /// A part left behind by a rolled back transaction is skipped when loading parts, so it can | ||
| /// never intersect the merge result and must not hold the merge back. | ||
| if ((*it)->version->getInfo().creation_csn == Tx::RolledBackCSN) | ||
| continue; |
There was a problem hiding this comment.
This check was not here and has no relation to the problem. Why have you introduced it? If it is a separate fix, remove it from this pr.
There was a problem hiding this comment.
You are right that it should not have been there in that form, and I have narrowed it.
The check was aimed at the mutation term this PR adds, but I applied it to the whole loop, so it also changed the pre-existing level term. That was wrong. It now guards only the mutation accumulation, and the level term is byte-identical to master, so the diff of this function is purely additive.
Why the remaining guard is not a separate fix: without it my own new term produces a false refusal. 01168_mutations_isolation failed deterministically on cf5afe5b (16/16), and the term fired exactly once in the whole job, inside that test, on all_1_1_0_15 in a gap between endpoints at version 13. mutation is the last component of the data_parts_by_info sort key, so a higher mutation version of an endpoint sorts between the endpoints and is scanned as if it lay in the block gap. That part exists because a mutation was killed, leaving creation_csn at Tx::RolledBackCSN.
Such a part can never be the one that fails to load: at MergeTreeData.cpp:2262 and :2273 an intersecting pair where either side has a rolled back creation is resolved in favour of the committed side, before the LOGICAL_ERROR at :2301. So refusing over it only postpones the merge, with no defect prevented.
If you would still rather see the two apart, I will drop the exclusion here and send it separately, but then this PR breaks 01168 on its own.
There was a problem hiding this comment.
Don't we need to introduce the same guard for the level?
There was a problem hiding this comment.
Also, why does the collector not handle this case using a proper filter of parts in active txs?
There was a problem hiding this comment.
On the level: yes, it has the same exposure, and it is already broken on master without this PR. I reproduced it rather than reasoning about it.
Four single-row inserts, then OPTIMIZE ... FINAL inside an explicit transaction, then ROLLBACK. The rollback leaves an outdated all_1_4_1 at level 1 with creation_csn = 18446744073709551615, which is Tx::RolledBackCSN (TransactionID.h:45). A plain OPTIMIZE ... FINAL after that, with no transaction in scope, is refused on pristine master:
Code: 388. Cannot OPTIMIZE table: There is an outdated part in a gap between two active
parts (all_1_1_0, all_2_2_0) with merge level 1 higher than these active parts have.
Refused 3 times out of 3, so it is not a transient. Control: the same table built without the transaction merges normally, so the check is not simply always refusing. DETACH + ATTACH + SYSTEM WAIT LOADING PARTS then loads all 4 rows, so nothing real is being prevented here either. It needs cleanup_delay_period raised to hold the window open, otherwise clearOldParts removes the gap part and the refusal clears itself.
So the level term wants the same exclusion, but it is a pre-existing defect rather than something this PR introduces, and per your own point at the top of this thread I would rather send it separately than widen this diff. I will open that PR unless you prefer it here.
On the collector: it cannot express this property, for two reasons.
collectInitial does all of its transaction work only when tx is non-null; with no transaction it just returns the active parts. StorageMergeTree::optimize takes txn from local_context->getCurrentTransaction() (StorageMergeTree.cpp:2401), so the refusal above happened with txn == nullptr and that filter never ran at all.
More fundamentally, the collector's output is the set of merge candidates, built by buildPartProperties over the already filtered ranges (PartsCollectors/Common.cpp:22-23). The parts this guard is about are by construction not in that set: they are outdated parts strictly between two active endpoints. That is why getMaxLevelMutationInBetween re-reads data_parts_by_info under readLockParts instead of using what it was handed. Filtering the collector harder removes more information; it cannot add the gap back.
For what it is worth, @ alexey-milovidov reached the same conclusion from the other direction on #115064 yesterday: parts_visible_for_merge, the collector superset, is not a sound source either, because once a replacing patch merge commits, the replaced part has a committed removal_csn and drops out of the superset while its replacement is filtered out as not visible. A complete fix there has to derive from snapshot visibility over both Active and Outdated parts, independent of the collector.
No change pushed for either question; I wanted your call on the level PR first.
There was a problem hiding this comment.
Do I understand correctly that if we do not include the txs logic in the current fix, the problem we already have with the level will be the same for mutations? That means we can, after that, open a follow-up PR to fix both level and mutation problems?
If so, do it this way - txs logic must be reviewed by other people, not me.
There was a problem hiding this comment.
Yes on the mechanism, and I measured it both ways rather than reasoning about it. Without those four lines the mutation term accumulates over rolled-back parts exactly like the level term already does, so the two become symmetric.
One consequence changes the order, though: the level version is latent, the mutation version is not. 01168_mutations_isolation fails deterministically without the guard, 5 of 5 runs, at tx 7 "optimize table mt final":
Cannot OPTIMIZE table: There is an outdated part in a gap between two active parts
(all_1_1_0_13, all_7_7_0_13) with mutation version 15 higher than these active parts have
Version 15 is tx 8's mutation_15, left outdated by tx_sync 8 "rollback". With the guard the same test is 5 of 5 green and the server logs no gap refusal at all. The test I added passes either way, 3 of 3 without the guard, so the fix itself does not depend on those lines. Neither run produced the level form; the level repro above needed part cleanup disabled to keep the gap part around.
So this PR cannot merge with the txs logic removed and the follow-up landing after it. Two orders do work:
- The follow-up goes first, covering level and mutation together, reviewed by whoever owns the transaction code. I then drop the four lines here, and this PR carries no txs logic at all.
- The four lines stay here, and the follow-up covers only the level term.
Option 1 is what you asked for and leaves nothing red at any point, so it is my preference. Say which you want and I will do that.
There was a problem hiding this comment.
add fix for the level in this pr
There was a problem hiding this comment.
Done in ca3e192f: the rolled back skip now covers the level maximum as well, so both terms of getMaxLevelMutationInBetween share one rule and neither needs a follow-up PR.
Measured both directions on Build ID asserted debug builds, with the fixture the level exposure needs (two parts, OPTIMIZE FINAL inside a transaction, ROLLBACK, two more parts, then OPTIMIZE FINAL inside a transaction):
- parent commit:
Code: 388 CANNOT_ASSIGN_OPTIMIZE,with merge level 1 higher than these active parts have - with the fix: the merge commits
all_1_4_1, and detach, attach,SYSTEM WAIT LOADING PARTSloads all four rows with the rolled back part dropped at load, and nointersects previous partin the log
The new 04813_merge_over_rolled_back_gap_part fails 5 of 5 on the parent commit and passes 20 of 20 here. 02521_merge_over_gap, 04812_merge_over_gap_with_mutated_part and the 01168_mutations_isolation family stay green. Parts created outside a transaction carry Tx::NonTransactionalCSN, so on a table that never ran one the walk is unchanged.
One consequence I would rather name than bury. When the rolled back part carries exactly the block range and level the merge result would get, the predicate no longer defers the merge, and it fails at rename instead with Code: 384 PART_IS_TEMPORARILY_LOCKED, already exists, but it will be deleted soon, where before it was a silent no-op. The predicate is pairwise while the result range is only known to the whole range selection, so it cannot tell that case from the safe one. I left the behaviour as measured rather than special casing it, and did not pin it in a test since a later fix should be free to change it. Say so if you would rather I keep the level term as it was for that reason.
Last thing: you said the transaction logic should be reviewed by someone other than you. It now applies to both terms rather than one, so that ask still stands. Name whoever should look at it and I will ping them.
Review feedback on the gap merge predicate: 1. Remove comments. Trimmed the fix-referential and self-evident ones from both the source and the test, keeping only the setup constraints a reader cannot infer at the call site. 2. GapPartProperties should not live in the part properties file. The struct is gone; getMaxLevelMutationInBetween returns std::pair<UInt32, Int64> and PartProperties.h is untouched by this PR again. 3. The rolled back part check had no relation to the problem. It was applied to the whole loop, so it also changed the pre-existing level term. It now guards only the new mutation term, leaving that term byte-identical to master: the diff of this function is purely additive. A part whose creation was rolled back is deactivated by MergeTreeData::loadDataPart before PartLoadingTree::add sees it, so it can never be the part that fails to load, and refusing a merge over it only postpones the merge.
The skip is not `MergeTreeData::loadDataPart` deactivating the part. It happens inside the intersection handling itself: `MergeTreeData.cpp:2262` and `:2273` resolve an intersecting pair in favour of the committed side when either side has a rolled back creation, before the `LOGICAL_ERROR` at `:2301`. Also state in the header that the level maximum covers all outdated parts while the mutation maximum covers only those whose creation was not rolled back, rather than implying both terms share one filter.
|
Both done in
Re-verified on a debug build (Build ID |
Master reflowed the level refusal in canMergeParts with clang-format and added a transaction-aware parts set to the merge predicate. The mutation term keeps its own refusal in the same reflowed style; the predicate now receives the transaction, and getMaxLevelMutationInBetween is unaffected by that change because it reads data_parts_by_info under the parts lock.
|
Merged master to clear the conflict. Head is now The conflict was in Validated on the merged tree, both arms with Build IDs asserted against
No submodule pins moved: the index gitlinks are identical to master for all of |
|
Hi @Michicosun, gentle ping - any update on the two review threads? I answered both on 2026-08-25 ( |
`getMaxLevelMutationInBetween` skipped a gap part whose creation was rolled back only while accumulating the mutation maximum. The level maximum still counted it, so the level term kept refusing merges over such a part. Nothing in the reason for that skip depends on which component made the pair non-containing. `MergeTreeData::PartLoadingTree::add` resolves an intersecting pair in favour of the committed side whenever either side has a rolled back creation (MergeTreeData.cpp:2323, :2334, :2387, :2396) instead of reaching the `intersects previous part` logical error at :2362, so a rolled back part is never the one that fails to load. The skip belongs to the whole walk, and both maxima now share it. Measured on Build ID asserted debug binaries with transactions enabled through the CI config tree. Fixture: two single row parts, `OPTIMIZE FINAL` inside a transaction, `ROLLBACK` (which leaves `all_1_2_1` Outdated with `creation_csn` = `Tx::RolledBackCSN`), two more single row parts, then `OPTIMIZE FINAL` inside a transaction. Before: `Code: 388 CANNOT_ASSIGN_OPTIMIZE`, `with merge level 1 higher than these active parts have`. After: the merge commits `all_1_4_1`, and a detach, attach, `SYSTEM WAIT LOADING PARTS` cycle loads all four rows with the rolled back part dropped at load, with no `intersects previous part` in the log. Parts created outside a transaction carry `Tx::NonTransactionalCSN`, so on a table that never ran one the walk is unchanged. One consequence is worth naming. When the rolled back part has exactly the block range and level that the merge output would get, the predicate no longer refuses, and the merge instead fails at rename with `PART_IS_TEMPORARILY_LOCKED`, `already exists, but it will be deleted soon`, where before it was a silent no-op. The predicate is pairwise while the output range is only known to the whole range selection, so those two shapes cannot be told apart there. The test pins `remove_rolled_back_parts_immediately = 0` and a large `merge_tree_clear_old_parts_interval_seconds`: a rolled back part is removable as soon as it appears, independently of `old_parts_lifetime` (MergeTreeData.cpp:4105-4106), and the parts cleanup runs once a second by default, so without those pins the fixture could be deleted before the merge. 04813_merge_over_rolled_back_gap_part covers the shape above. It fails on the parent commit with the level refusal and passes here. 02521_merge_over_gap, 04812_merge_over_gap_with_mutated_part and the 01168_mutations_isolation family all still pass.
|
|
||
| # Merges the two parts inside a transaction and rolls it back, which leaves all_1_2_1 Outdated | ||
| # with creation_csn = Tx::RolledBackCSN. Two more parts are added afterwards, so the merge below | ||
| # spans a wider range than the rolled back part and gets a different name. |
There was a problem hiding this comment.
This fixture deliberately sidesteps the remaining failing shape by making the second merge wider than the rolled-back all_1_2_1. If the same two active parts are merged again, getMaxLevelMutationInBetween now skips that rolled-back gap part, FutureMergedMutatedPart::assign still names the result all_1_2_1, and checkPartDuplicate then throws PART_IS_TEMPORARILY_LOCKED because the outdated rolled-back part is still in data_parts_by_info. So the PR still turns that case from a temporary deferral into a commit-time failure in OPTIMIZE FINAL or a background merge until cleanup runs. Please either cover and fix the exact-duplicate shape here, or keep the predicate refusing it.
There was a problem hiding this comment.
Mechanism confirmed, and it is the residual I described 21 minutes before this review, in the thread above: #113941 (comment). The throw site you name is the one I measured, MergeTreeData::checkPartDuplicate at MergeTreeData.cpp:6591-6593, and the naming holds: FutureMergedMutatedPart::assign takes the block range from the ends of the range and sets level = max_level + 1 (FutureMergedMutatedPart.cpp:74-76), so the same two parts do produce all_1_2_1 again.
Neither of the two options is mine to take.
Refusing the exact duplicate in the predicate also refuses the shape this PR fixes. canMergeAllParts validates adjacent pairs (MergeTreeDataMergerMutator.cpp:597-602), so in this fixture the first validated pair is (all_1_1_0, all_2_2_0), whose pairwise result name is all_1_2_1, the rolled back part, while the merge that actually runs is all_1_4_1. A rule keyed on the pairwise result name refuses both shapes, so it reverts the fix instead of narrowing it. Telling them apart needs the whole range result name, which only selectAllPartsToMergeWithinPartition has.
Keeping the old level accumulation is that same revert, and @ Michicosun asked for the level fix in this PR earlier today. I offered him that revert in the comment linked above, so it is his call.
Two bounds on what is left. checkPartDuplicate picks PART_IS_TEMPORARILY_LOCKED for an Outdated duplicate on purpose, and StorageMergeTree::renameAndCommitEmptyParts already treats that code by running clearOldPartsFromFilesystem and retrying. And rollback makes the part removable at once, so grabOldParts deletes it regardless of old_parts_lifetime when remove_rolled_back_parts_immediately is set (MergeTreeData.cpp:4104-4106), which is the default, on a cleanup task whose default interval is 1 second; the fixture has to turn both off to keep the part around. No table fails to load in either state, which is the failure this PR removes.
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) |
the shard's nested containers breach the /docker cgroup leaf, the kernel OOM-kills processes inside it and the job errors with no test attributed |
#117412 (external, merged 2026-09-01T11:31:33Z) |
Docs examples / Documentation examples |
the documented output of Function/toYYYYMM#0 was pinned to 202608, so the example self-broke at the month boundary |
#117459 (mine, merged 2026-09-01T13:55:50Z) |
Bugfix validation (functional tests, amd64 / aarch64), Finish Workflow / Post Hooks |
both per-arch jobs abort on assert build_urls, "Could not find master builds in S3", so nothing could validate and new_tests_check.py then reds the post hook |
#117433 (mine, open) |
Stress test (amd_debug) / Logical error: Not-ready Set is passed as the second argument for function 'globalIn' (STID 0250-4e52) |
pre-existing trunk defect in set readiness, not caused by this diff | #102308 (external, open) |
The /docker breach is a job-level condition, not a test result. I measured #117412 ABSENT from the tree that ran, from the job's own environment rather than from git ancestry: this job was launched with CI_DIND_INIT_RESERVE=17179869184 (the 16 GiB share #117412 replaces), and so were all ten failing legs I read this tick. The probe discriminates, with a positive control: two shards launched at 14:53Z and 14:59Z carry CI_DIND_INIT_RESERVE=8589934592 (the flat 8 GiB reserve #117412 introduces) and both passed. So this is rule 3c and not rule 3d, and #117411 is not a co-owner: it was closed unmerged at 11:11:48Z in favour of #117412, whose own diff comment states the causal link.
The docs example is a trunk-wide, date-dependent break, not something specific to this PR: 226 distinct pull requests and 10 true-master runs carry it. I measured #117459 ABSENT from the tree that ran, from the failure text itself: the reported query is still the old toYYYYMM(now(), ...) form, and the string the fix introduces appears in 0 of the 164 Docs examples failure rows recorded in the last day. The control is master's own line - Docs examples is FAIL at d8aa6cab7800, which is 4 commits behind the fix and has 0 occurrences of the new string, and OK at 8627fa22f015, which is the fix's own merge commit.
I have not merged master to pick those fixes up yet. It would not clear Mergeable Check on this head, because the Stress test (amd_debug) logical error and the Bugfix validation abort both remain, and neither fix is merged, so a merge now would cost a full CI cycle and leave the head red on the same count. One master merge picks everything up once the remaining fixes land.
Mergeable Check reports Failed: 4 at this head, which counts only the jobs it gates on. The table above is the complete non-OK, non-SKIPPED node set of the head's praktika report, so it also covers the rows Mergeable Check does not gate.
CH Inc sync was success at this head.
Session id: cron:our-pr-ci-monitor:20260901-163000
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
AST fuzzer (amd_debug, targeted) / Logical error: Not-ready Set is passed as the second argument for function 'globalIn' (STID 0250-4e52), Failures: 1/2 |
not PR-caused, pre-existing trunk defect in subquery-set readiness. The aborting query is recorded verbatim in fatal.log as SELECT ... FROM merge('.+.+.+.+') PREWHERE globalIn(database, (SELECT DISTINCT currentUser())) ..., and the abort frames are MergeTreeRangeReader::executePrewhereActionsAndFilterColumns into ExpressionActions::execute into FunctionIn::executeImpl (src/Functions/in.cpp:128): the globalIn subquery set was never built. Breadth over 30 days: 738 rows across 485 pull requests and 45 true-master trees. This diff touches only MergeTreeMergePredicate.cpp and StorageMergeTree.cpp, neither of which is on a set-building or read path |
#102308 (external, open) |
Bugfix validation (functional tests, amd64), Bugfix validation (functional tests, aarch64), Finish Workflow / new_tests_check.py |
harness abort before any test ran: assert build_urls, "Could not find master builds in S3" at ci/jobs/functional_tests.py:734. Master build artifacts moved under a normalized workflow-name prefix, so find_master_builds probes the old key and matches nothing, and new_tests_check.py then reds the post hook because no per-arch job reported OK or XFAIL. This diff touches no ci/ file |
#117580 (external, merged 2026-09-01T22:06:23Z). Both jobs started 21:10Z, about 56 minutes before that merge, so the fix is absent from the tree that ran (checked against the pre-fix and post-fix trees). I am not merging master to pick it up: the current head is the reviewer's own commit and the PR is approved, so the next update to this branch collects the fix without an extra cycle |
Style check and CH Inc sync are green on this head.
Session id: cron:our-pr-ci-monitor:20260901-233000
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR(Part ... intersects previous part ... It is a bug or a result of manual intervention) that makes aMergeTreetable impossible to load: attaching it, and every later attempt to load it, fails with that exception (a server abort in debug and sanitizer builds). A merge could span a block gap holding an outdated part whose mutation version is higher than the merge result's, producing a pair of parts on disk that neither contain nor are disjoint from each other. Closes #113864.Description
A merge is refused when the block gap it spans holds an outdated part the merge result would not cover. That check compared only the part level, while
MergeTreePartInfo::containsrequires bothlevel >=andmutation >=. An outdated part left by a mutation has level 0, so the check could not see it and the merge produced an intersecting, mutually non-containing pair. Every later part load (ATTACH TABLE, or a server restart) then throws, and in debug and sanitizer builds that exception aborts the server.Such a gap appears when parts owe different mutation stacks: in the reported case a mutation succeeded on one part (version 59) and threw on its neighbour (left at 45), and the surrounding parts then merged into a part that does not contain the intervening
all_57_57_0_59.getMaxLevelInBetweennow also accumulates the maximum mutation version over the gap and is renamedgetMaxLevelMutationInBetween;canMergePartsrefuses when that version exceedsmax(left.mutation, right.mutation). The bound is pairwise rather than the exact result version, which is only known later inFutureMergedMutatedPart::assign, and since that version is a maximum over a superset of any adjacent pair it can refuse early but never admits a merge it should refuse. Refusing is not fatal: the merge waits until the outdated part is removed.The same walk now also skips a gap part whose creation was rolled back, on both terms: part loading resolves an intersecting pair in favour of the committed side, so such a part never fails to load and refusing over it only postponed the merge. When it carries exactly the block range and level the merge result would get, that merge now fails at rename with
PART_IS_TEMPORARILY_LOCKEDrather than being deferred here, which a pairwise predicate cannot distinguish.The replicated predicate has no such hole; it probes the gap at
MAX_LEVEL/MAX_BLOCK_NUMBER.Validation: each new test fails on its parent commit and passes here;
02521_merge_over_gapand01168_mutations_isolationstay green, and 261 merge/optimize/mutation tests show no regressions.Workflow [PR]
Sync PR [sync-upstream/pr/113941]
Version info
26.9.1.664(included in26.9and later)