Repository navigation
Conversation
…tion A non-replicated TTL merge books a slot in the global counter for `max_number_of_merges_with_ttl_in_pool` at selection time (to close the assign-vs-execute race), and hands the booking over to the `MergeList` entry only when the merge starts executing. If the selected merge is abandoned before that handover, the slot was leaked. Only two abandonment paths were compensated; others were not, most notably the pending-queue removal that `DROP`/`DETACH TABLE` performs on a merge still waiting in the background pool, and a `STOP MERGES` landing between selection and scheduling. Each leak permanently reduces the number of TTL merges the server can run; once the counter reaches the per-table limit (default 2), `merge_with_ttl_allowed` is false for every default-limit table and background TTL merges stop server-wide until restart, while regular merges keep running. Make the booking a `scope_guard` owned by the selected-merge entry, released on any path that abandons the merge before its `MergeList` entry exists and disarmed once that entry takes over the accounting. The guard is armed before the slot is booked, so the booking is the last statement of the block and cannot be stranded. This replaces the two ad-hoc per-path compensations with a single mechanism covering every abandonment path. Guard the same book-to-insert gap in the replicated path (`MergeFromLogEntryTask`) symmetrically, and add a debug/sanitizer assertion against counter underflow. This surfaced as the flaky test `04321_table_readonly_background_merges`, whose writable control table relies on a background TTL merge that never ran once the global counter had leaked to the limit earlier in the run. Add a regression test that reproduces the leak deterministically via the `mt_skip_scheduling_merge_once` failpoint with the limit set to 1. A second TTL merge cycle on a fresh table, run after `DROP`ping the first so its whole background task and the slot accounting it carries are destroyed, also catches the opposite accounting error (an over-released slot), so the test discriminates both directions in all build types. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=0aa6569f3e6563c982227857effd5d2d19c97527&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 PR where it was observed: ClickHouse#96130 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 5 review rounds, 11 findings; the final round returned 0 findings, and the independent cold reviews found 0 blockers in every round).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260725-231900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-9:20260725-231900 |
|
cc @tavplubix @alesapin - could you review this? A TTL merge books a slot against |
|
Workflow [PR], commit [1bdcf06] Summary: ❌
AI ReviewSummaryThis PR fixes the TTL-merge slot accounting gap between merge selection and Missing context / blind spots
Final Verdict
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 35/37 (94.59%) · Uncovered code |
CI finish ledger — 1bdcf06Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Not PR-caused: this PR changes TTL merge-slot bookkeeping ( Session id: cron:our-pr-ci-monitor:20260726-063000 |
Two more eligibility restrictions for `reattach_tables_before_query_execution`: 1. Skip `MergeTree` tables whose metadata carries any TTL. The internal `DETACH TABLE ... SYNC` cancels selected-but-not-started background TTL merges, and `MergePlainMergeTreeTask::cancel` does not return the `max_number_of_merges_with_ttl_in_pool` slot booked at selection time, so every such cancellation leaks a slot until server restart; two leaks disable TTL merges server-wide. This is the AI review blocker, and the cause of the recurring `04321_table_readonly_background_merges` and `04267_ttl_drop_merge_no_data_read` failures in this PR's CI. The skip stays until the underlying leak is fixed (see #111925). 2. Skip tables that have an Outdated part not covered by any Active part. The `DETACH`/`ATTACH` cycle reloads the parts from disk and resurrects such a part as Active — e.g. the empty covering part left by `ALTER TABLE ... DETACH PART` until the asynchronous cleanup deletes it. The same resurrection happens on a server restart in that window, so it is pre-existing behavior, but the hook must not turn it into a deterministic side effect of an unrelated query. This caused the `04653_mutation_rewrite_stale_part_column_type` failure (confirmed by the CI diagnosis as caused by the randomization): the resurrected empty part received the pending mutation, and the following `OPTIMIZE TABLE ... FINAL` became a silent no-op because the empty part lacks the projections of its neighbors ("Parts have different projection sets"). CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=021fa9deea22167db809efe3dadc5af26126a327&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%202%2F3%29 PR: #96130 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@alexey-milovidov, your #121236 fixes the same leak as this PR and covers every path it guards (a queued merge discarded on |
|
#121236 is merged, and it fixes this leak on master (the TTL slot is now owned by the selected merge, and |
Related: #96130
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes background TTL merges stopping server-wide when a selected TTL merge is dropped before it starts executing (for example, when its table is dropped or detached while the merge is still queued in the background pool). Each such merge leaked a slot booked against
max_number_of_merges_with_ttl_in_pool; once the counter reached the limit, no further TTL merges were scheduled until the server was restarted.Description
A non-replicated TTL merge books a slot in the global counter for
max_number_of_merges_with_ttl_in_poolat merge selection time (to close the assign-vs-execute race), and the booking is handed over to theMergeListentry only when the merge starts executing. If the selected merge is abandoned before that handover, the slot was leaked. Two abandonment paths were compensated; several were not, most notably the pending-queue removal thatDROP/DETACH TABLEperforms on a merge still waiting in the background pool. Each leak permanently decrements the number of TTL merges the server can run; once it reaches the per-table limit (default 2),merge_with_ttl_allowedis false for every default-limit table and background TTL merges stop server-wide until restart, while regular merges keep running.The fix makes the booking a scope guard owned by the selected-merge entry, released automatically on any path that abandons the merge before its
MergeListentry exists, and disarmed once that entry takes over the accounting. This replaces the two ad-hoc per-path compensations with a single mechanism covering every abandonment path. The same book-to-insert gap in the replicated path (MergeFromLogEntryTask) is guarded symmetrically. A debug/sanitizer assertion guards the counter against underflow.The flaky test
04321_table_readonly_background_mergessurfaced this: its writable control table relies on a background TTL merge, which never ran once the global counter had leaked to the limit earlier in the run (test02293_part_log_has_merge_reason, the only test setting the limit to 100, was unaffected, which pinpointed the counter). Report where it was observed: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=0aa6569f3e6563c982227857effd5d2d19c97527&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29Regression test
04641_ttl_merge_slot_leak_unscheduledreproduces the leak deterministically via themt_skip_scheduling_merge_oncefailpoint (which drops a selected merge exactly once, the same accounting gap the table-drop hits) with the limit set to 1, and verifies that a later background TTL merge still runs after the dropped selection, and that a second TTL merge cycle runs afterwards (either a leaked or an over-released slot makes the second cycle time out, so the test discriminates both accounting errors in all build types).