Repository navigation
Conversation
A mutation that drops a secondary index, projection or statistics on a Wide part in full storage hardlinks every file it does not touch and unlinks the dropped ones, so it needs space for a little metadata rather than for a copy of the part. The selection guards nevertheless compared the free-space budget against the whole size of the source part, so a part larger than the budget was postponed forever - including for the very command that would free the space. Reported in ClickHouse#112106: an index that exists to be dropped to reclaim space could not be dropped because there was no space. The guard is a pre-check of the reservation that follows it (both reduce to part_size <= free/1.1), so exempting the guard alone would turn a diagnosable postpone into a NOT_ENOUGH_SPACE thrown out of selection. The requirement is therefore corrected at both, on both engines: * classify the mutation: guaranteed to take the partial route, only DROP INDEX / DROP PROJECTION / DROP STATISTICS (not their CLEAR forms), no patch parts, not copying instead of hardlinking, and no packed skip-index archive or statistics to rewrite. The four shape conditions the route already depends on are extracted into one predicate that the two existing sites now share, so they cannot drift apart; * for such a mutation ask the storage for the smallest reservation it grants on the source part's own disk instead of predicting a size, and postpone if that fails. The budget is a maximum across the policy's volumes, so passing it says nothing about the disk the part lives on; * carry the classification to the executing task and re-validate it wherever its own inputs become final - after the plan is built, before the part storage is created, and on the untouched-part clone path - throwing before the first byte if it no longer holds. A misclassification therefore returns the part to the behaviour it had before, with the reason in system.mutations; * on the replicated side classify at assignment and at execution (that guard has no separate zero-budget check, so the exemption is gated on a nonzero budget and on the source part existing), acquire the reservation at queue selection and carry it in SelectedEntry, and never divert such an entry into fetching a whole part. Nothing changes for any other mutation: the non-exempt guard and reservation expressions are untouched.
The previous commit exempted a mutation that only hardlinks from the free-space guard, but it refused any part carrying statistics, on the grounds that the surviving statistics are re-serialized into a new statistics.packed. That refused almost every real part: auto_statistics_types defaults to "basic, uniq_v2" and materialize_statistics_on_merge is on, so every merged part carries the archive even when the table never mentions statistics. Measured on the shape reported in ClickHouse#112106 - a full-text index, otherwise default settings - the archive is 6466 bytes and the exemption never applied, so the fix was a no-op for the case it was written for. The rewrite is also the wrong thing to bound. processStatisticsChanges reacts to DROP STATISTICS, DROP COLUMN, RENAME COLUMN and READ COLUMN only, so for a DROP INDEX or DROP PROJECTION the map it is handed comes back out unchanged and re-serializing it produces byte-identical content. Rather than admitting the part and arguing about how many bytes that costs, do not write it: leave statistics.packed out of both files_to_skip and files_to_rename so the existing "hardlink everything unchanged" loop takes it, and skip serializeStatisticsPacked in finalizeMutatedPart. The part inherits its source's checksums, which already describe the file that was hardlinked - the same reason the packed skip-index archive works when it is not dirty, and the reason its inherited entry is dropped only when it is. Measured on a wide six-column tdigest fixture, the exempt mutation's write footprint falls from 39249 to 1792 bytes and the archive's inode gains a link rather than being copied. The decision is derived inside processStatisticsChanges from the effective commands and the recalculation set, before any lookup into the loaded map, and returned to the caller. Deriving it from a lookup would be wrong: loadStatisticsPacked skips archive entries whose column it cannot resolve and swallows per-column deserialization failures, so the map is not a faithful index of the archive and "the erase found nothing" does not mean "nothing changed". Keeping the enumeration in the one function that already owns those command branches also stops the two copies drifting apart when a command kind is added. Two conditions bound it. DROP STATISTICS leaves the exempt class: it is interpreter-free like DROP INDEX, but it changes the set of statistics, so the archive is written anew at a size the small reservation does not cover, and on the nearly-full disk this whole change targets that would replace a postpone with a failure on every retry. And a rename pending for the part but absent from its commands still arrives as a synthetic RENAME_COLUMN, because required renames follow the part's metadata version rather than its data version; such a mutation does rewrite the archive, so it is refused at admission instead. On StorageMergeTree nothing is needed for that: every applicable mutation is selected by version alone, so the rename is already among the classified commands and the whitelist refuses it. The replicated queue answers it from the walk it already performs over its own mutation snapshot, bounded to the mutation version being executed so that a rename queued later cannot postpone this one. The write behaviour is scoped to the mutations holding the small reservation, so every other mutation on the partial route writes its statistics exactly as before. The one visible consequence outside the exempt class is that an ordinary within-budget DROP INDEX also stops re-serializing an unchanged archive, which is less IO for identical content. A legacy part whose statistics live in per-column statistics_*.stats files is hardlinked the same way and migrated to the packed format only when something actually changes the map, which is later than before but strictly less work. No name-based test is involved, so a user column called statistics_x cannot disable any of this. 04649_drop_index_mutation_exceed_max_part_size covers it through the existing mt_select_parts_to_mutate_max_part_size failpoint, which pins the budget to one byte and needs no disk manipulation. Besides the reported case it carries eight negative controls that must still be postponed, a route oracle proving the partial route ran, and a write-footprint comparison built only from measured quantities so that it needs no threshold: the exempt mutation must write less than a DROP STATISTICS on the same shape, and a non-exempt mutation must still write its statistics.
…the admission flag The decision whether to hardlink an unchanged statistics.packed instead of re-serializing it was keyed on FutureMergedMutatedPart::hardlink_only, which on ReplicatedMergeTree is one replica's admission classification. Two of its inputs are not invariant across replicas executing the same log entry: the always_use_copy_instead_of_hardlinks MergeTreeSetting is loaded from the server config, and the patch-part and pending-rename conditions read live state. The two outcomes it selected between are not byte-equal either, because ColumnStatistics::serialize always writes the current format while deserialize accepts older ones, so a legacy archive is upgraded on the rewrite path and inherited verbatim on the hardlink path. Where the bytes differ, checkEqual raises CHECKSUM_DOESNT_MATCH and the entry is diverted into fetching the whole result part, which is the failure this change exists to prevent on a nearly full disk. The decision is now derived from whether the mutation's commands can change which statistics the part holds, plus whether the task rewrites every column, both of which follow from the source part and the commands alone. That widens the behaviour to every partial-route mutation whose commands cannot change the statistics set, which is disclosed in the description. Also in this commit: - correct the locking contract documented for isHardlinkOnlyMutation. It reads the storage's active patch parts and therefore acquires the data-parts read lock itself; that is safe under ReplicatedMergeTreeQueue's state_mutex because the surrounding critical section already takes the same lock through getPartIfExists. - record Exceed max source part size on the non-replicated fall-through where the coalescing loop collects no command, so a part that is not progressing does not report an empty parts_postpone_reasons. - add an EXIT trap to the stateless tests so an early exit cannot leave a server-wide failpoint enabled. - add a DROP PROJECTION positive case, and 04651_drop_index_mutation_exceed_max_part_size_rmt for the replicated arm with a DELETE control. - add test_mutation_hardlink_only_space, which reproduces the bug on a real size-limited disk rather than through a failpoint, so the reservation and not only the selection guard is exercised. It asserts both of the inequalities the fixture rests on. - replace the write-footprint oracle's second column, which the widening above makes false by design, with one that still separates the two decisions on replica-invariant grounds.
…scriminate Three test-side corrections; no production code changes. The replicated DELETE control asserted a tautology: its SELECT list carried NOT is_done, which its own WHERE clause already guaranteed, so the expression was 1 for any row that existed and the postpone REASON was never checked. It would have passed just as happily a moment before an incorrectly admitted DELETE completed. Replaced with the discriminating arrayExists on the named reason that the non-replicated twin already used; the replicated path records the same PostponeReasons::EXCEED_MAX_PART_SIZE constant, so the two controls are now identical apart from the table name. Pointed at the positive table the predicate returns nothing rather than 1, which is what shows it discriminates. Nothing could detect removal of the fetch suppression in MutateFromLogEntryTask. findReplicaHavingPart skips the replica itself, so on a single-replica vehicle the branch is unreachable and deleting the !hardlink_only conjunct left every assertion green. Added a two-replica case sharing one ZooKeeper path with both fetch thresholds set to zero, so the fetch preference applies whenever it can and the exemption is the only thing left standing. Replica 2's queue is stopped until replica 1 has completed the mutation, so the result part genuinely exists to be fetched rather than the two replicas racing. Deleting the conjunct now reddens the case on both of its oracles: the partial-route event disappears and a download of the result part appears in system.part_log. The oracle is scoped to the result part because replica 2 also downloads the pre-mutation part when it first syncs, and that fetch is expected. Finally, a fixture comment in 04649 still described the write-footprint baseline as isolating a write the non-exempt mutation must still perform, which the widening of the statistics scope made false and which the assertion three lines below it already contradicted.
…tation carries Three write-side correctness gaps found in review, none of which any existing fixture could distinguish from its absence. The reservation an exempt replicated mutation carries is taken at selection time, on the disk of the part selection saw. Execution resolves the active source part again, and a move that passed its own checks before the MUTATE_PART entry existed commits at an arbitrary later time - MergeTreePartsMover::swapClonedPart only re-checks that an active part of that name still exists. Since the result part's path comes from that reservation and a hardlink cannot cross disks, the reservation is now compared against the resolved source's disk and re-taken there when they differ. If it cannot be re-taken the entry is postponed rather than diverted into a fetch: a fetch reserves the sender's whole part, which on a full disk can never succeed. Statistics preservation was derived from the recalculation set plus four command types, which is blind to a command that rewrites a column's values without changing which statistics exist. MATERIALIZE COLUMN on a MATERIALIZED column is the case, and UPDATE, DELETE, MATERIALIZE TTL and APPLY_PATCHES reach the same route. Rather than extending the list that rotted, the decision gains a third input derived from the route - whether the mutation builds a pipeline at all - so any such command writes its statistics anew. Like the other two inputs it is produced by splitAndModifyMutationCommands from the source part, the metadata snapshot and the commands, so two replicas executing one log entry still agree and still write byte-equal parts. The copy-mode re-validation on the write side had no test that could see it: every fixture held the copy mode constant from CREATE through mutation, so deleting the check left everything green. It is now driven by flipping the mode while the entry is parked between admission and the write, and the refusal is shown to be recoverable rather than a poisoned queue entry. Each of the three is pinned by a case that fails when only that code is removed. The moved-part case asserts the error rather than the end state, because the failed hardlink is retried and the mutation then completes on the part's current disk, leaving every observable identical on both sides.
…sk is full A MUTATE_PART entry that only hardlinks takes its small reservation at selection time, and the execution side re-validates it against the source part resolved again there, in case the part moved disks in between. That re-validation reported a failed re-reservation by returning prepared_successfully = false with need_to_check_missing_part_in_fetch = false, on the belief that the flag is what keeps a not-prepared result from becoming a fetch. It is not. ReplicatedMergeMutateTaskBase::executeImpl calls execute_fetch unconditionally on any not-prepared result; the flag is consumed only inside executeFetch, in its replica.empty() branch, where false merely suppresses the NO_REPLICA_HAS_PART exception. When a replica does have the part, control reaches fetchPart and DataPartsExchange reserves the sender's whole part - on the disk that had just refused a metadata-sized reservation. That is the bug this change exists to prevent, reached through the code meant to be the safe postpone. Throw NOT_ENOUGH_SPACE instead. This is what the non-exempt path already does at the same point, and what the three other write-side guards here do: the task base records it as the mutation's latest_fail_reason and latest_fail_error_code_name, the queue retries the entry, and no fetch is attempted. No new PrepareResult member and no new no-fetch outcome are needed. Three comments asserted the refuted mechanism and are corrected. One of them was wrong about master too, independently of this change: master's prepare() reserves via reserveSpace, which throws, and a throw never reaches execute_fetch. Also record that the disk re-read narrows the divergence window rather than closing it - once the entry exists the part is a queue virtual part that both move paths refuse, so only an already-in-flight move whose swap lands after the read can still escape. Co-Authored-By: Claude Fable 5 <[email protected]>
…sk bound Two review nits, both in MutateFromLogEntryTask::prepare. Move out of selected_entry->hardlink_only_reservation instead of copying it. selected_entry lives as long as the whole task, so a copy left the superseded reservation holding reserved_bytes on a disk the mutation no longer uses: for the task's duration that disk's unreserved_space under-reported by the 1 MiB RESERVATION_MIN_ESTIMATION_SIZE floor, and concurrent reservers on it saw less space than existed. This line is the only reader of that member, and the reservation stays held through the local and then reserved_space, so nothing is released early - only the duplicate ownership goes away. Correct the comment on the disk re-read. An earlier round claimed the re-read only narrows the cross-disk window, leaving a swap that lands after it able to escape the check. That does not follow: the source part is resolved once and retained, and swapActivePart replaces the indexed part with a new object rather than moving the retained one, so the hardlink source and the result path both stay on the disk this reservation names. One read is enough. No behaviour changes on any tested path.
MutateFromLogEntryTask::prepare took ownership of the reservation carried on
the queue entry only after the two not-prepared returns (source part missing,
source part covered by a larger one), so on either of those the reservation
stayed attached to the entry. The entry outlives the whole task, and a
not-prepared result is executed as a fetch on the same thread - a fetch that
reserves the sender's whole part on exactly the disk the reservation is still
charged to. On the nearly-full disk this feature exists for, that fetch could
be refused for space held by a mutation that had already decided not to run.
Hoisting the transfer above both returns removes the class rather than the two
instances: after the move there is no reachable return that leaves the member
populated, so a future early return added there cannot reintroduce it.
Both fallback paths were reachable by design - admission matches the exact part
name in {PreActive, Active, Outdated} while prepare resolves the active
containing part, and the surrounding code documents that they can disagree.
check_query_single_value_result defaults to false, so CHECK TABLE returns one row per part shaped part_path, is_passed, message. Every part these two cases produce is named all_1_1_0_2 or all_0_0_0_1, so the substring test "1" in output matched the part name and held even when is_passed was 0: both assertions could never fail. Ask for the single-value result explicitly and compare for equality. That matters here because CHECK TABLE is the only assertion on the size-limited disk that can observe a checksums-vs-files mismatch, which is what this change risks when it hardlinks statistics.packed into the new part while inheriting the source part's checksums. Verified by simulating a failed check in place of the query: under the old substring form all five tests still passed, under the new form the two cases that call assert_dropped_and_partial fail with 'all_1_1_0_2\t0\t\n' == '1\n'. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review - 8 rounds, 66 findings adjudicatedBefore opening this PR I ran an independent cold review plus a second-model gate on every round, and ❌ Blockers and majors that were real, and were fixed
|
Pre-PR validation gate
|
|
Workflow [PR], commit [b4dea19] Summary: ❌
AI ReviewSummaryReviewed PR head Missing context / blind spots
Findings
Final VerdictStatus: Minimum action: link the promised follow-up issue for the dismissed mixed-command admission gap. Expanding this PR to implement that follow-up is not required. |
| /// Now that the commands are final, decide on the whole set: coalescing may have turned a | ||
| /// mutation that only drops secondary objects into one that rewrites the part. As above, no | ||
| /// rename can be outside this set. | ||
| const bool hardlink_only |
There was a problem hiding this comment.
commands is still the raw mutation entry here, but the actual per-part command list is only filtered later in MutateTask::prepare via canSkipMutationCommandForPart. That means an oversized part is still classified as non-hardlink_only if the same ALTER also contains a non-hardlink command that gets skipped for this part, for example DROP INDEX ... IN PARTITION p1, CLEAR COLUMN ... IN PARTITION p2. In that case the DROP INDEX on p1 is postponed forever again even though the real work for that part is exactly the cheap hardlink-only route. The same mismatch exists in the earlier oversized fast-path in StorageMergeTree::selectPartsToMutate, and on the replicated side in StorageReplicatedMergeTree::tryMutatePart / ReplicatedMergeTreeQueue::shouldExecuteLogEntry, so the size exemption needs the filtered per-part command list rather than the raw mutation entry.
There was a problem hiding this comment.
The mechanism is real and I have reproduced it, but not in the shape described, and it is pre-existing rather than something this PR introduces. Deferring it to a follow-up. Measurements below.
The literal example does not parse. ALTER TABLE t DROP INDEX idx IN PARTITION 1 gives Code: 62 SYNTAX_ERROR ... failed at position 30 (IN). ParserAlterQuery.cpp accepts IN PARTITION only on the CLEAR forms (:361-377 CLEAR INDEX, :492-505 CLEAR PROJECTION); the plain DROP INDEX branch at :349-359 never parses a partition, and DROP PROJECTION pr IN PARTITION 1 fails the same way. A CLEAR form is excluded from the class by construction, so the partition-scoped command in a reachable mixed entry is always the non-exempt one.
The reachable shape does reproduce. A table-wide exempt command plus a partition-scoped non-exempt one lands as a single entry. With the size budget pinned to one byte on a Wide table partitioned into 1_1_1_0 and 2_2_2_0:
| ALTER | result |
|---|---|
DROP INDEX idx |
is_done = 1, no postpone reason |
DROP INDEX idx, CLEAR COLUMN b IN PARTITION 2 |
is_done = 0, both parts Exceed max source part size |
CLEAR COLUMN b IN PARTITION 2 |
is_done = 0, both parts postponed |
Part 1_1_1_0 in row 2 is the point: with the failpoint off, that mutation takes it from 40721 to 40633 bytes while partition 2 goes to 20494, and a.bin in the partition-1 result has nlink = 2. So its real work is hardlinking, and it is still size-gated.
It is pre-existing, not a regression. I ran the identical two cases against a pre-fix master binary whose StorageMergeTree.cpp is md5-identical to this branch's merge-base: pure DROP INDEX postponed, mixed entry postponed. This PR takes the mixed case from postponed to postponed, so it is a residual it does not close. The description also scopes the class explicitly to "only DROP INDEX or DROP PROJECTION and not their CLEAR forms", so a mixed entry is outside the stated contract.
It cannot become a space hazard, which is why I am not folding it in. isHardlinkOnlyMutation is monotone decreasing in the command set: an empty set returns false, mutationRequiresFullPartRewrite only becomes more true with more commands, and the loop returns false on the first command that is not a non-clear DROP INDEX/DROP PROJECTION. Because the raw entry is a superset of the filtered list, exempt(raw) implies exempt(filtered). The asymmetry can only under-exempt, never grant the small reservation to a mutation that rewrites the part. The two write-side re-validations already read the filtered list (MutateTask.cpp:2663 and :3576 pass ctx->commands_for_part), so execution is stricter than selection in the safe direction.
Why the suggested fix is not a small change. MutationCommand::ast() re-parses on every call (MutationCommands.cpp:91-95, no caching), so filtering per command per candidate part in the selection loop conflicts with keeping a part within budget from paying for the lookup at all. getPartitionIDFromQuery can throw INVALID_PARTITION_VALUE, BAD_ARGUMENTS and a LOGICAL_ERROR on a partition-value mismatch, where the selection sites cannot throw today, and with no lock passed it takes readLockParts() (MergeTreeData.cpp:179-182) while ReplicatedMergeTreeQueue.cpp:1887 already holds state_lock. That wants its own change with its own tests, not a rider here.
I have filed a follow-up for it with these measurements and those four constraints, and I am leaving this PR's content unchanged.
Correction (2026-11-18): I did not open a public issue for this, and no follow-up is planned. A mixed ALTER still leaves such a part postponed, as on master; running the DROP INDEX as its own ALTER gets the exemption this PR adds.
The replicated merge-selecting task clears the per-part postpone reasons at the top of every iteration (StorageReplicatedMergeTree::selectPartsToMerge) and refills them later, in a separate acquisition of the queue's state_mutex. ReplicatedMergeTreeQueue::getMutationsStatus reads the map under its own shared lock, so a read landing between the clear and the refill legitimately sees an empty map. The non-replicated path is not exposed: there the clear, the refill and getMutationsStatus all run under the single currently_processing_in_background_mutex held by the caller, so the map is never observable empty. The test waited for any reason to be present and then read the specific one in a second query, leaving that window open between the two reads. Measured over 500 trials against a live oscillating mutation, that shape reported the absent reason in 25 of them (5 percent), which is what the flaky check saw on four sanitizer flavours: rmt_delete postponed 0 instead of 1. Re-read the reported row until the reason appears instead. A reason that never appears still fails the assertion, because only the last read is ever reported. Same 500 trials: 0 failures, quiet and under load. Only the replicated file needs this; 04649 has no ReplicatedMergeTree table. Co-Authored-By: Claude Fable 5 <[email protected]>
The two threshold-free comparisons in 04649 measure how many bytes a mutation writes, read from the part_log ProfileEvent WriteBufferFromFileDescriptorWriteBytes. That counter is incremented in WriteBufferFromFileDescriptor::nextImpl, so it only sees writes that go through a local file descriptor. On the object storage lanes the default merge tree storage policy is overridden (tests/config/config.d/s3_storage_policy_for_merge_tree_by_default.xml and its azure counterpart), so the part data is written by WriteBufferFromS3 or WriteBufferFromAzureBlobStorage instead. The whole payload moves verbatim to a different counter and the fd counter is left measuring only the local metadata files, whose size does not depend on which statistics the mutation wrote. Measured on the materialize_column fixture: on a local disk the two differences are 21314 and 38 bytes, and on an s3 disk they are 58 and 58, so the strict comparison between them turns into a tie and reports 0. That is why the test failed on the five object storage lanes and passed on every local disk lane, including the plain sequential ones. Pinning storage_policy = 'default' on the six fixture tables puts their parts back on a local disk on every lane. The two tables created with CREATE TABLE ... AS inherit the setting. With the pin the s3 arm's footprints are byte-identical to the local arm's and the remote counter reads zero. The counter's only other user in the suite, 02703_max_local_write_bandwidth, carries the no-object-storage tag for the same reason. A tag would skip the whole file on those lanes and lose the coverage of everything else it asserts, so the fixtures are pinned instead. The sibling write_footprint comparison did keep reporting 1 on object storage, but only because both of its sides had collapsed to local metadata noise, so it was passing without measuring anything. It is pinned too.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 285/325 (87.69%) · Uncovered code |
CI finish ledger - 35fb047Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20260730-163853 |
…-only-mutation-space One conflicting file, src/Storages/MergeTree/MutateTask.cpp, in two places, and both are the same overlap: master and this branch independently extracted the same predicate out of the task fork. This branch added MutationHelpers::mutationRequiresFullPartRewrite, holding the four part-shape conditions, because isHardlinkOnlyMutation and splitAndModifyMutationCommands need them without an interpreter (selection time has no interpreter), and the task fork adds the interpreter term at its call site. Master added MutationHelpers::rewritesAllPartColumns, holding the same four conditions plus the interpreter term, so that getColumnsForNewDataPart and the task selection cannot disagree about the column list. Resolution keeps both and makes rewritesAllPartColumns delegate to mutationRequiresFullPartRewrite, so the four shape conditions exist once. The resulting expression is identical to what each side computed: mutationRequiresFullPartRewrite || (interpreter && isAffectingAllColumns) The second conflict is the task fork itself, where master reads its local rewrites_all_columns and this branch reads ctx->requires_full_part_rewrite. Those are now the same value, so the fork keeps master's condition and rewrites_all_columns is initialised from ctx->requires_full_part_rewrite instead of calling the predicate a second time. The decision therefore stays at the point this branch moved it to - immediately after the interpreter is built and before any filesystem work - which is what the hardlink-only reservation is validated against: prepare() refuses a mutation admitted as hardlink-only whose plan turns out to rewrite the part, and it has to refuse before claiming the temporary directory and beginning the part storage transaction. Computing it once also means the column list of the new part and the task that fills it read one value, which is the invariant master's comment asks for. Inputs are unchanged between the two former call sites: ctx->source_part is assigned once, ctx->commands_for_part is not written after the interpreter block, and ctx->interpreter is assigned only inside it.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes14 object files changed (+75.59 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units62 translation units recompiled, 718 s compile time in total, 62 of them have a recent master baseline. |
…-only-mutation-space One conflict, in MutateFromLogEntryTask::prepare(): master's new always_fetch_mutated_part early return landed at the same point where this branch takes ownership of the reservation the queue made at selection time. Kept both, with the takeover first. The takeover has to precede every early return: selected_entry outlives this task, so leaving the reservation there while the entry is executed as a fetch charges the sender's whole part to the same disk the reservation is already holding. Moving it into a local variable first means the fetch path releases it on return, which is what that ordering was written for. Nothing else about master's block changes; a replica that fetches every mutated part never reaches the hardlink-only path.
CI finish ledger - 6474cf0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The
Session id: cron:our-pr-ci-monitor:20260810-193000 |
…06-hardlink-only-mutation-space # Conflicts: # src/Storages/MergeTree/MutateTask.cpp
CI finish ledger - b29f7f0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The The five Session id: cron:our-pr-ci-monitor:20260818-030000 |
|
Fixing PR for the It is in Root cause is an ordering violation rather than only a race. |
…-only-mutation-space Only conflict was the include block of ReplicatedMergeTreeQueue.cpp: master relocated SubscriptionEnrichment.h into Streaming/Subscription/, and this branch had added MutateTask.h next to it. Resolved as a union taking master's new path. MutateTask.h is required for MutationHelpers::isHardlinkOnlyMutation at the MUTATE_PART execution guard.
|
📊 Cloud Performance Report ✅ AI verdict: This PR is entirely about MergeTree mutation handling: admitting hardlink-only mutations, reserving small space at selection time, and re-validating the route in MutateTask. None of that touches the read/query-execution path a ClickBench SELECT runs. The lone flagged query (clickbench Q34, +5.5%, ~63 ms) was already within master's variance band and shows no CPU shift (base and source CPU are essentially identical), so it reads as normal run-to-run noise rather than a PR effect. No cross-query pattern; nothing here warrants action from the author. clickbenchFlagged queries (1 of 43)
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. tpch_adapted_1_official🟢 No significant changes Debug info
|
Waiting out the mutation with the fail point held lands just over the 180s cap the flaky check applies to untagged tests, which failed the sync.
…-only-mutation-space Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both tests arm a fail point, and the `failpoint_tests_are_isolated` style check now requires such tests to be tagged `no-parallel` and `no-fasttest`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 2088643Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 163 check runs completed and Session id: cron:our-pr-ci-monitor:20261011-033004 |
…-only-mutation-space
CI finish ledger - 61d942aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
This head is the master merge that picked up #125121: Session id: cron:our-pr-ci-monitor:20261011-093005 |
- Classify a mutation as hardlink-only only for a part that the size guard would otherwise refuse, on both engines. A part within budget keeps its usual reservation, so the write-side NOT_ENOUGH_SPACE refusals can only hit a mutation that was postponed before this change. On ReplicatedMergeTree the queue now checks the part shape and the copy-mode setting before copying the commands, never classifies under a zero (throttled) budget, and looks the commands up without the missing-mutation warnings, which would otherwise fire on every scan for a killed mutation. rmt_merge_selecting_task_max_part_size now pins the queue's mutation budget as well, so the replicated test still exercises execution-time behaviour. - The clone path refuses only when it would copy instead of hardlink: a hardlink clone is covered by the small reservation whatever the commands are, including an empty list after KILL MUTATION. - Factor the tagging tail shared by both CurrentlyMergingPartsTagger constructors into a private helper. - Drop the integration case for a source part moved between admission and execution, and the second disk it needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It reads the table settings, which takes the MultiVersion mutex, so it is not lock-free. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-only-mutation-space Conflicts in MutateTask.cpp, ReplicatedMergeTreeQueue.cpp and StorageMergeTree.cpp: - mutationRequiresFullPartRewrite, which replaced the shape predicate in rewritesAllPartColumns and splitAndModifyMutationCommands, now uses isPerFilePartStorage (ClickHouse#126865), and splitAndModifyMutationCommands keeps master's future_storage_type condition and getColumnNameInStorage. - processStatisticsChanges takes master's new parameters and rename handling and keeps the bool result and the early return for unchanged statistics. - The !recalculate_ttl_only condition (ClickHouse#125025) moves into requires_full_part_rewrite, which rewrites_all_columns reuses. - The queue keeps both master's source_parts and mutation_source_part. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes
ALTER TABLE ... DROP INDEXandDROP PROJECTIONbeing postponed forever withExceed max source part sizeon a part larger than the free space. Such a mutation hardlinks the files it does not touch and unlinks the dropped ones, so it needs space for a little metadata rather than for a copy of the part, and the free-space requirement is now computed accordingly. Previously an index could not be dropped to reclaim space precisely when the space was needed. Closes #112106.Description
Mutation selection compared the free-space budget against the whole size of the source part, whatever
the mutation was going to do to it. That size is what a full rewrite needs, but a
DROP INDEXon a Widepart in full storage takes the partial route: it hardlinks every file it does not touch and unlinks the
dropped ones. So a part bigger than the budget was postponed forever, and dropping an index to free
space became impossible exactly when the space was needed:
A mutation on a part the size guard would refuse is now classified as hardlink-only when it provably
takes the partial route and writes none of that route's data-copying outputs, and then gets the
smallest reservation the storage grants on the source part's own disk instead of one covering the whole part. Guard and reservation are both corrected,
on both engines: they reduce to the same inequality, so exempting only the guard would turn a
diagnosable postpone into
NOT_ENOUGH_SPACEthrown out of selection. The classification is re-validatedin the executing task wherever its inputs become final, always before any file is created, so a
misclassification returns the part to its previous behaviour with the reason in
system.mutationsandnever fills the disk. Outside the class only the statistics handling below changes.
Testing. Two stateless tests pin the budget to one byte with the existing failpoints, so no disk
manipulation is needed, and assert that the reported case and a
DROP PROJECTIONcomplete while eightnegative controls stay postponed and a ninth, whose copy mode is flipped mid-flight, is refused and then
completes on retry. An integration test on real size-limited tmpfs disks covers what the failpoints
cannot: that the reservation is actually small.
Classification, scoping, tests
The class. Wide part in full storage with no unrecorded dynamic substreams, only
DROP INDEXorDROP PROJECTIONand not theirCLEARforms, no pending rename outside the command list, no patchparts, not copying instead of hardlinking, no packed skip-index archive to rebuild. Any doubt means not
exempt. Replicated side: decided at assignment and again at execution, reservation taken at queue
selection, and never diverted into a fetch, which would reserve the sender's whole part.
Statistics are left alone whenever the mutation neither rewrites any column nor can change which ones
the part holds, as
DROP INDEXandDROP PROJECTIONcannot:statistics.packedis hardlinked withits inherited checksums instead of being re-serialized to identical content.
DROP STATISTICS,DROP COLUMN,RENAME COLUMN,MODIFY COLUMN,MATERIALIZE COLUMN,UPDATE,DELETEand anyrecalculation write them as before. This is scoped to any partial-route mutation rather than to the
exempt ones: keying it on the exemption would make it depend on this replica's config and live queue
state, so two replicas executing one log entry could write parts differing byte for byte, and the
differing one is then forced to fetch the whole result part - the outcome this change exists to avoid.
DROP STATISTICSis not exempt although it is interpreter-free likeDROP INDEX: it changes theset, so the archive is written anew at a size the small reservation does not cover.
Tests. Controls that must stay postponed:
DELETEon both engines, a Compact part, a Wide+Packedpart,
always_use_copy_instead_of_hardlinks,CLEAR INDEX,DROP STATISTICS, the pool throttle.Oracles: a route oracle from
system.part_log, two threshold-free write-footprint comparisons, atwo-replica case with both fetch-preference thresholds at zero, and a paused entry whose copy mode changes
underneath it.
Workflow [PR]
Sync PR [sync-upstream/pr/112454]