Repository navigation
Do not leak the TTL merge slot of a merge that never runs - #121236
Conversation
A merge with TTL takes one of the `max_number_of_merges_with_ttl_in_pool` slots the moment it is selected, because `system.merges` - which the limit is counted from - only gets an entry once the merge task starts running. The slot was given back by that entry's destructor, so a merge that was selected and then dropped before it ever ran never gave its slot back. The slots are server-wide and there are two of them by default, so two such merges stop every table on the server from running another merge with TTL until it is restarted, and expired rows are never deleted. Dropping a selected merge is not exotic: the background pool discards a task that is still queued when its table goes away, which is what a `DROP TABLE` shortly after an insert of expired rows does. That is how `04790_ttl_drop_merge_text_index` and `05106_ttl_only_drop_parts_column_ttl` failed together on master: at 05:19:42 two `TTLDrop` merges were selected on the inner table of a `TimeSeries` table and its database was dropped 274 ms later; from there on not one of the ~4000 merges the job still ran was a merge with TTL, and the two tests timed out 9 and 21 minutes later waiting for a background TTL merge the server could no longer assign. Both tests are correct. The slot is now held by `MergeList::TTLMergeSlot`, an RAII token that lives in the selected merge itself - `MergeMutateSelectedEntry` for `MergeTree`, the task for `ReplicatedMergeTree` - so it is given back however the merge ends: it ran, it was cancelled, it threw, or it was dropped before it started. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=5e3546b1e1b3be5c651cd5deb0039361bbc57671&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29 Co-Authored-By: Claude Opus 5 <[email protected]>
|
Workflow [PR], commit [c90939c] Summary: ✅
AI ReviewSummaryThis PR moves TTL-merge slot ownership from Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit c90939c.
Changed lines: Changed C/C++ lines covered: 53/55 (96.36%) · Uncovered code |
…ot_not_leaked_when_merge_dropped` `mt_drop_selected_ttl_merge_once` is server-wide, so an `EXIT` trap now disables it and drops the test tables however the script ends. Co-Authored-By: Claude Opus 5.5 (1M context) <[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 units245 translation units recompiled, 2591 s compile time in total, 245 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only how the server counts slots for TTL merges. The count is now held by a token that gives the slot back on its own, plus a new test hook and a stateless test. None of this runs during benchmark SELECT queries. The only flagged query is clickbench Q28 at -6.6% (1106.5 ms to 1034.0 ms). The two tests disagree on it and the measurements were noisy, so it stays not_sure and does not need action. No performance effect is expected from this change, and none was measured. 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
|
The amd_tsan flaky check failed the last scenario 8 times in 238 runs: the TTL drop never ran. `max_number_of_merges_with_ttl_in_pool` is compared with the number of TTL merges of the whole server. The job log shows two TTLDrop merges selected on `t_drop_column_zero` while `SYSTEM STOP MERGES` was in effect and then dropped without running. The slots they booked were never given back (the leak ClickHouse#121236 fixes), so from then on no table on that server got a TTL merge. The four scenarios that wait for a background TTL merge now set the limit to 100, as 02293 and 04321 do. The two that must prepare the part first keep it at 0 until then and raise it with `MODIFY SETTING` instead of `STOP/START MERGES`; the other two need neither. So the test no longer selects a TTL merge that is then dropped. With two TTL merges of another database paused on the server (`merge_task_projection_stage_pause`), the previous version fails scenarios 11-14 as in CI and this one passes (1/1, and 20/20 randomized). 100/100 randomized at --jobs 32. The master build still fails 11 and 13, and the mutants M9, M10, M12 still fail 12, 13 and 14. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…leak # Conflicts: # src/Common/FailPoint.cpp # src/Storages/StorageMergeTree.cpp
alexey-milovidov
left a comment
There was a problem hiding this comment.
Looks reasonable.
# Conflicts: # src/Common/FailPoint.cpp # src/Storages/StorageMergeTree.cpp
…_merge_once` The fail point used to fire before `MergePlainMergeTreeTask` was constructed, so the only owner of the TTL merge slot it dropped was the local `merge_entry` in `scheduleDataProcessingJob`. The leak it guards against happens later: the task has been queued and is discarded when its table goes away, and then the slot's owner is the task's `merge_mutate_entry`. Fire the fail point after the task is constructed and release the local reference first, so the task is the last owner of the selected entry when it dies, as for a queued task. Addresses review: #121236 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…x-ttl-merge-slot-leak # Conflicts: # src/Storages/StorageMergeTree.cpp
…ttest` The style check `failpoint_tests_are_isolated` requires a test that enables a fail point to be kept out of the fast test, because a fail point is server-global state and such a test must run alone. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121236&sha=ba55e87113b679c53c142df83bcc64c97111d5b7&name_0=PR&name_1=Style%20check PR: #121236 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's ClickHouse#121236 removed the try block around the merge entry construction in StorageMergeTree, which conflicted with the branch's patch-aware estimateNeededDiskSpace call. The call is kept at the new indentation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A merge with TTL takes one of the
max_number_of_merges_with_ttl_in_poolslots the moment it is selected, becausesystem.merges— which the limit is counted from — only gets an entry once the merge task starts running. The slot used to be given back by that entry's destructor, so a merge that was selected and then dropped before it ever ran never gave its slot back. The slots are server-wide and there are two of them by default, so two such merges are enough to stop every table on the server from running another merge with TTL until it is restarted, and expired rows are then never deleted.Dropping a selected merge is not exotic: the background pool discards a task that is still queued when its table goes away, which is what a
DROP TABLEshortly after an insert of expired rows does.That is how
04790_ttl_drop_merge_text_indexand05106_ttl_only_drop_parts_column_ttlfailed together on master. At 05:19:42 twoTTLDropmerges were selected on the inner table of aTimeSeriestable and its database was dropped 274 ms later; from that point on not one of the ~4000 merges the job still ran was a merge with TTL, and the two tests timed out 9 and 21 minutes later waiting for a background TTL merge the server could no longer assign. Both tests are correct — the server was wedged.The slot is now held by
MergeList::TTLMergeSlot, an RAII token that lives in the selected merge itself (MergeMutateSelectedEntryforMergeTree, the task forReplicatedMergeTree), so it is given back however the merge ends: it ran, it was cancelled, it threw, or it was dropped before it started.bookMergeWithTTL,cancelMergeWithTTLand theMergeList::onEntryDestroyoverride are gone, so there is no longer a way to take a slot without owning it.The new test drives the exact path with a one-shot fail point that drops a selected merge with TTL, then checks that a table which insists on every slot being free can still run its own.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=5e3546b1e1b3be5c651cd5deb0039361bbc57671&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29
Related: #119717
(the same "selection is not execution" gap, but on the per-partition
merge_with_ttl_timeouttimer; this pull request does not address it)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix background merges with TTL silently stopping for the whole server. A merge with TTL that was selected and then dropped before it ran — for example because its table was dropped right after the expired rows were inserted — leaked one of the
max_number_of_merges_with_ttl_in_poolslots, which are shared by all tables. After two such merges no table would delete expired rows any more until the server was restarted.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121236]
Version info
26.10.1.1435-master(included in26.10and later)