Repository navigation
Do not drop rows of a part without rows TTL info in a TTL merge - #123068
Conversation
A part attached from a table with a different TTL, or written before
`MODIFY COLUMN ... REMOVE TTL` + `MODIFY TTL ... SETTINGS
materialize_ttl_after_modify = 0`, keeps an expired `ttl.txt` entry of a TTL
family the table no longer has (column, DELETE WHERE, GROUP BY) and has no
rows TTL info at all (`table_ttl = {0, 0}`). `TTLPartDropMergeSelector` tags
merges from `part_max_ttl`, the max over every family, so such parts get a
`TTLDrop` merge, and the short-circuit added in ClickHouse#105859 read `TTLDrop &&
hasOnlyRowsTTL()` as proof that every row expired and wrote an empty part
without reading anything.
The short-circuit now also requires every source part to have a calculated
rows TTL (`table_ttl.min != 0`, the rule of `checkAllTTLCalculated`) that has
expired at the time of the merge, which is exactly when the pipeline itself
would drop all rows. The `ReplicatedMergeTreeQueue` exemption from the source
parts size check (ClickHouse#119983) uses the same helper at `entry.create_time`, the
time the merge runs with, so a TTLDrop entry that rewrites rows keeps the
size check.
A part without rows TTL info also added nothing to the aggregated rows TTL
bound that `TTLTransform` and `TTLDeleteFilterTransform` use to decide "all
rows expired", so merging it with a fully expired part (the same routes, or
any OPTIMIZE FINAL) dropped its rows as well. The merge already forces the
TTL calculation for such a part; the aggregated bound is now reset so that the
per-row evaluation decides.
Closes ClickHouse#121124
Co-Authored-By: Claude Opus 5.5 <[email protected]>
State the TTLDrop disk-space exemption rule in ReplicatedMergeTreeQueue exactly: exempt only the merge that drops every source part unread. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings, then 1 on a stateful re-review) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260930-122900 |
|
Workflow [PR], commit [1f877e2] Summary: ❌
AI ReviewSummaryThis PR fixes the PR Metadata
Findings
Final VerdictStatus: Minimum required actions:
LLVM Coverage Report |
… drop The TTL drop selector takes every adjacent part whose TTL info has expired, so fully expired parts and a part without rows TTL info (for example one attached from a table with a column TTL) land in the same merge. The size check exemption was all or nothing, so on a full disk such a range was refused as a whole, and the refused entry kept the only max_replicated_merges_with_ttl_in_queue slot (the stall of ClickHouse#119775), although the fully expired parts write nothing back. Count only the parts whose rows TTL has not expired, whose rows are the only ones the merge can write back. A range of fully expired parts still counts 0 bytes, and a range of parts without rows TTL info still needs room for all of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units60 translation units recompiled, 727 s compile time in total, 60 of them have a recent master baseline. |
| if (metadata_snapshot->hasOnlyRowsTTL()) | ||
| ignore_max_size = true; | ||
| { | ||
| sum_parts_size_in_bytes = 0; |
There was a problem hiding this comment.
The queue gate is now using the right notion of "bytes that may remain", but the replicated execution path still sizes the same mixed TTLDrop range as if it wrote nothing.
MergeFromLogEntryTask::prepare reserves space through CompactionStatistics::estimateNeededDiskSpace(parts, true, entry.create_time), and that helper still drops any part whose part_max_ttl <= current_time (CompactionStatistics.cpp:42-62). In the new orphan/mixed cases from this PR, the attached part still has an expired orphaned column/group-by/DELETE WHERE TTL entry, so part_max_ttl is expired even though the merge keeps and rewrites its rows. That means shouldExecuteLogEntry can now admit the merge based on the surviving rows here, but the executor still reserves 0 bytes for those same rows.
Under concurrent disk pressure this is still not "admission and execution agree": the merge can pass the queue check and then fail later for lack of reserved space. I think the reservation path needs to share the same per-part isRowsTTLExpired test (or a common "bytes that may remain after TTLDrop" estimator), plus a regression that exercises the mixed replicated case through execution rather than only the queue postponement check.
CI finish ledger - 1f877e2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
149 of 149 check runs completed (110 passed, 36 not selected, 3 red: the job above and the two rollups), Session id: cron:our-pr-ci-monitor:20260930-230153 |
|
Follow-up on the
|
|
@groeneai is it valid review point? Open fix if yes |
687f384
|
Yes, the code fact is right, but it is older than this PR and not specific to it. The fix is already open: #122391. There |
…ead-regular-116172 Master's ClickHouse#123068 added a per-part rows TTL expiry check to the TTLDrop short-circuit; it is kept next to this branch's patch and cleanup checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ClickHouse#123068 clears the merged part's `table_ttl` when any non-empty source part has `table_ttl.min == 0`, treating it as a part without a calculated rows TTL. An epoch-only part also has zero bounds, but its rows TTL is calculated and recorded with `has_epoch_timestamps`, which propagates to the merged part and already disables the whole-part shortcuts. Exclude such parts, so the merged part keeps the propagated bounds. Fixes `04904_materialize_ttl_merged_epoch_timestamps` and `05048_materialize_ttl_epoch_reload` in the Fast test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=63383&sha=c4a681b8754c3152fd4661c537356f6ca542bf77&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t in a merge A merge folds the column TTL info of its source parts with `MergeTreeDataPartTTLInfos::update`, which only iterates the entries a source part has. A part that stores a column but has no `columns_ttl` entry for it (attached with `ATTACH PARTITION ... FROM` from a table without the column TTL, or written before `MODIFY COLUMN ... TTL` with `materialize_ttl_after_modify = 0`) adds nothing, so the merged bound is exactly the other part's. When that part's column TTL has fully expired, `TTLColumnAlgorithm` takes its whole-block branch (`isMaxTTLExpired() && !is_compact_part`) and replaces the column of every merged row with the default, including rows whose TTL has not expired. `force_ttl` is set for such merges, but it only affects `isMinTTLExpired()`. Without a TTL step (TTL merges stopped) the wrong bound is persisted on the merged part and the next TTL merge of that part resets it. Collect the columns that a non-empty source part stores without TTL info and aggregate each source part's TTL infos from a copy without those entries. The merged part is then in the same "not calculated" state as the source part: a TTL step evaluates the column TTL per row, and without one the next merge sees the gap and forces it. Removing the entries before `update` (rather than erasing the aggregated entry afterwards) keeps `part_min_ttl`/`part_max_ttl`, which `update` derives from the folded entries, free of the expired bound. Merges whose parts all carry a calculated bound keep the whole-block fast path. Column-TTL counterpart of the rows-TTL fix in ClickHouse#123068 (issue ClickHouse#121124). Reproduces on 26.8.2.7 and 24.8.14.39. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #121124
Related: #105859
Related: #119983
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed merges deleting all rows of a part whose rows TTL was never calculated, although none of its rows had expired: a part attached with
ATTACH PARTITION ... FROMfrom a table without that rows TTL, or written beforeMODIFY TTLwithmaterialize_ttl_after_modify = 0added it (for example afterMODIFY COLUMN ... REMOVE TTL). The rows were lost in background TTL merges and in merges with fully expired parts. Closes #121124.Description
On 26.8.2.7-lts,
ALTER TABLE dst ATTACH PARTITION tuple() FROM src, wheresrcdeclares a column TTL thatdstdoes not have, followed by an ordinary background merge, deletes every row of the attached parts.Such a part keeps an expired
ttl.txtentry of a TTL the table lacks (column,DELETE WHEREorGROUP BY) and no rows TTL info. The selector tags the mergeTTLDropfrom the maximum over all entries, and the #105859 short-circuit took that tag plushasOnlyRowsTTLas proof that every row expired, writing an empty part unread.Changes (merge path only):
ReplicatedMergeTreeQueuesize check of a TTL drop (Do not postpone a fully expired TTL drop because of source parts size #119983) counts only the source parts that may keep rows.TTLTransformandTTLDeleteFilterTransformuse to drop all rows, so a merge with a fully expired part (alsoOPTIMIZE FINAL) lost its rows too, already on 26.3. The merge now resets that bound so every row is evaluated.The new stateless test covers column,
DELETE WHEREandGROUP BYleftovers,ReplicatedMergeTreeand both mixed-merge algorithms, each losing all rows on master and 26.8. Two newtest_ttl_drop_not_postponed_by_sizecases cover the size check;04267_ttl_drop_merge_no_data_readstill reads nothing.Not changed here: stale but calculated bounds (#117990, #116678, for example a part attached from a table with a shorter rows TTL), rows whose TTL value is 0 next to expired rows (the bound ignores them), and the older column TTL twin (a column reset to its default).
Workflow [PR]
Sync PR [sync-upstream/pr/123068]
Version info
26.10.1.2132-master(included in26.10and later)