Repository navigation
Conversation
A part whose GROUP BY, WHERE or column TTL has expired is selected as a whole-part TTL drop. The drop selector gave such merges unlimited size constraints, and estimateNeededDiskSpace skipped fully expired parts, both assuming that the merge writes nothing. That holds only with an unconditional rows TTL, through which TTLTransform drops all data; otherwise the rows are aggregated or filtered and written back. On a disk with less free space than the part, the merge started with a 1 MiB reservation, failed with ENOSPC and was selected again about once per second, so the TTL was never applied and concurrent writes to the disk could fail. Use hasRowsTTL() at both safeguards: without an unconditional rows TTL the drop gets the regular merge constraints, and the plain and replicated merge reservations count the expired parts. hasOnlyRowsTTL() would be too narrow: a DELETE TTL next to a move, recompression, column, GROUP BY or WHERE TTL also empties the part, and such drops keep ignoring free space. Extend test_ttl_drop_not_postponed_by_size. Case B now queues the drop while it fits, fills the disk, checks that the queue still postpones it and that the executed merge reserves room for its rows. New case C covers a non-replicated table on a full disk, new case D a DELETE TTL next to a recompression TTL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit let a TTL drop of a completely expired part skip the size limits and the space reservation whenever the table has an unconditional rows TTL. The table having one does not make the part empty: `TTLTransform` drops all rows only when the part's own rows TTL maximum has expired, and a row whose `DELETE` TTL is 0 records no value. A part whose every row has such a value, or that was written before the `DELETE` TTL was added with `materialize_ttl_after_modify = 0`, is still a drop candidate through its `GROUP BY`, `WHERE` or column TTL; it got unlimited constraints and 1 MiB, and its rows were written back into a full disk, the same ENOSPC loop. Check the part instead. `PartProperties::GeneralTTLInfo` gets `rows_ttl_expired`: the table has a rows TTL and the part's rows TTL maximum is set and expired, the condition under which `TTLTransform` empties it. The drop selector first looks, with unlimited constraints, only at such parts, then at every other completely expired part with the regular merge constraints. `estimateNeededDiskSpace` skips a completely expired part only if it has a rows TTL value, so the merge reservations, `OPTIMIZE ... DRY RUN` included, count the rows such a merge writes; the mutation reservations count such parts too. This replaces the caller parameter of the previous commit. Run case C of `test_ttl_drop_not_postponed_by_size` also with a `DELETE` TTL that has no value for any row, and check that a dry run of the part is refused with `NOT_ENOUGH_SPACE` while the disk is full. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`estimateNeededDiskSpace` skipped a completely expired part whose rows TTL values had expired, trusting only what the part records. The merge empties such a part only if the metadata it runs with has a rows TTL. `ALTER ... REMOVE TTL` is metadata-only, and so is a `MODIFY TTL` that drops the `DELETE` with `materialize_ttl_after_modify = 0`, so the part keeps its expired values while the merge writes every row back. `OPTIMIZE ... DRY RUN` has no other size check: it reserved nothing and failed with a write error on a full disk instead of `NOT_ENOUGH_SPACE`. Background merges and mutations are size-limited at selection, so they only lost the reservation margin. Pass the metadata snapshot of the merge or mutation to the estimate and skip a part only if that snapshot has a rows TTL. With a rows TTL the estimate is unchanged; without one it counts every part. Add case E to `test_ttl_drop_not_postponed_by_size`: after `REMOVE TTL`, a dry run of an expired part on a full disk must be refused with `NOT_ENOUGH_SPACE`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review: my own cold pass over the resulting code in each of three rounds, plus an
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260926-051000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260926-035500 |
|
Workflow [PR], commit [40cffe1] Summary: ❌
AI ReviewSummaryThe PR makes row-retaining Missing context / blind spots
Findings
Final Verdict✅ Approve the scoped merge fix. The mutation issue above is retained for visibility as a pre-existing, separately tracked limitation. No new inline findings were posted; the existing mutation thread remains open, and the unsupported stale-expression thread was resolved. Current-head integration validation is still pending. |
| /// Exclude expired parts | ||
| time_t part_max_ttl = part->ttl_infos.part_max_ttl; | ||
| if (part_max_ttl && part_max_ttl <= current_time) | ||
| if (metadata_snapshot.hasRowsTTL() && part->ttl_infos.table_ttl.max && part_max_ttl && part_max_ttl <= current_time) |
There was a problem hiding this comment.
estimateNeededDiskSpace is now shared by the mutation reservations too, but this continue is only safe for operations that are known to delete the rows. Both mutation callers (MutateFromLogEntryTask::prepare and StorageMergeTree::selectPartsToMutate) now route through this helper, while MutateTask only reapplies TTL when shouldExecuteTTL sees TTL dependencies, and the "drop the whole expired part" shortcut is limited to hasOnlyRowsTTL(). That leaves a real gap for tables like TTL ts + INTERVAL 1 DAY DELETE, ts + INTERVAL 10 YEAR RECOMPRESS ...: a regular ALTER ... UPDATE / MATERIALIZE COLUMN on a fully expired part still rewrites the rows, but this branch reserves 0 bytes because table_ttl.max and part_max_ttl are expired. On a full disk that mutation can still fail with NOT_ENOUGH_SPACE and retry forever.
Please keep the "skip expired source parts" rule scoped to operations that are guaranteed to remove those rows (TTLDrop / MATERIALIZE TTL / the hasOnlyRowsTTL() mutation optimization), and make generic mutation reservations count the part size.
There was a problem hiding this comment.
This still looks unresolved in the current tree. estimateNeededDiskSpace still skips any fully expired rows-TTL part for both mutation callers (src/Storages/StorageMergeTree.cpp:2434 and src/Storages/MergeTree/MutateFromLogEntryTask.cpp:139), but the actual mutation path only drops the result automatically on the much narrower hasOnlyRowsTTL() && ttl_only_drop_parts && !materialize_ttl_recalculate_only optimization (src/Storages/MergeTree/MutateTask.cpp:4129, src/Storages/MergeTree/MutateTask.cpp:4267, src/Storages/MergeTree/MutateTask.cpp:4346).
So a generic mutation on a fully expired part in a table like TTL ts + INTERVAL 1 DAY DELETE, ts + INTERVAL 10 YEAR RECOMPRESS still rewrites the rows while reserving 0 bytes. The local size gate does not prove safety either: it is based on the maximum free space across all disks (src/Storages/MergeTree/Compaction/CompactionStatistics.cpp:149), while the mutation later reserves on the source part's own disk (src/Storages/StorageMergeTree.cpp:1014), and the replicated path has no such gate before reserveSpace(estimated_space_for_result, source_part->getDataPartStorage()) (src/Storages/MergeTree/MutateFromLogEntryTask.cpp:191).
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only background merge code: how fully expired parts are chosen for TTL drop merges and how disk space is estimated for merges and mutations, plus integration tests. None of the ClickBench or TPC-H SELECT queries run that code. Q20's -42.0% improvement comes with a matching CPU drop, but the diff cannot explain it, so it is downgraded to not_sure and does not count as a PR effect. The automatic suppression of Q16 (+12.4%), Q33 (+6.7%) and Q34 (+5.3%) is consistent with the diff: each stays inside master's normal range, and all three queries have a noisy history. clickbenchFlagged queries (4 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
|
CI finish ledger - 59423c4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 146 check runs completed (102 passed, 43 not selected, 1 red) and Session id: cron:our-pr-ci-monitor:20260928-063113 |
…rop-needs-space # Conflicts: # src/Storages/MergeTree/Compaction/CompactionStatistics.cpp # src/Storages/MergeTree/Compaction/CompactionStatistics.h # src/Storages/MergeTree/MergeFromLogEntryTask.cpp # src/Storages/StorageMergeTree.cpp # tests/integration/test_ttl_drop_not_postponed_by_size/configs/storage_configuration.xml # tests/integration/test_ttl_drop_not_postponed_by_size/test.py
The mixed case of test_ttl_drop_not_postponed_by_size now asserts that the merge writing back the rows of the attached part reserves at least what that part holds. The attached part is made larger than the 1 MiB minimum reservation so that the check can fail: on master the mixed range reserves 1 MiB for about 2 MB of rows it writes back. The orphan case now queues its drop while the part still fits and fills the disk afterwards, as the GROUP BY case does: with the selector change of this branch, a drop that keeps rows is no longer assigned when the disk cannot hold them, so the drop would otherwise never reach the queue check.
Closes: #122280
Related: #119983
Related: #122481
Related: #123068
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed TTL merges of fully expired parts that keep rows (a
GROUP BY,WHEREor column TTL) ignoring free disk space. Such a merge was started with a 1 MiB reservation even when the rows it writes back did not fit, failed withNo space left on deviceand was retried about once per second, so the TTL was never applied and other writes to that disk could fail. These merges now obey the same size limits and space reservation as other merges. Closes #122280.Description
On 26.8.10.6 and 26.9.1.1629, a
MergeTreetable withTTL ... GROUP BYwhose fully expired parts exceed their disk's free space starts aTTLDropMergewith a 1 MiB reservation, fails witherrno: 28and restarts it about once per second, also with default settings, so the TTL is never applied. Other inserts to that disk can fail (5 of 150 on master).Such a part is merged as a whole-part drop, and two safeguards assume it writes nothing: the drop selector ignores the merge size limits (half the unreserved space, pool pressure,
max_bytes_to_merge_at_max_space_in_pool) andestimateNeededDiskSpaceskips fully expired parts. But only aDELETETTL expired for every row empties a part; aGROUP BY,WHEREor column TTL writes the rows back.Now only parts whose
DELETETTL has expired for every row skip the size limits and the reservation. Every other fully expired part (GROUP BY,WHEREor column TTL, aDELETETTL without a value, or one thatALTERremoved) obeys these size limits and is counted by the reservation, also forOPTIMIZE ... DRY RUN. The replicated queue check (#119983, #123068) applies the same rule only to tables with no other TTL, so a full replica still postpones a largeDELETE+ move drop. Mutations of parts whoseDELETETTL expired for every row reserve only 1 MiB; #122481 fixes that.Tests (
test_ttl_drop_not_postponed_by_size): new cases C (plain table, full disk, also with a value-lessDELETETTL: no merge starts, a dry run is refused, with room it reserves the part size), D (aDELETETTL next to another TTL still drops on a full disk) and E (a dry run afterREMOVE TTLis refused); B and the mixed case of #123068 check the replicated reservation. B, C, E and the mixed case fail on master.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122391]