Repository navigation
Conversation
…cellable `StorageMergeTree::selectPartsToMerge` (lambda `select_in_partition`) waits on `currently_processing_in_background_condition` for up to `lock_acquire_timeout_for_background_operations` (120 s by default) whenever an `OPTIMIZE ... FINAL` cannot select its partition while merges are running, and re-arms the wait after every finished merge; the memory poll before it sleeps in 1 s steps for up to the same timeout. Neither looked at the query status, and nothing notifies the condition when a query is killed, so `KILL QUERY`, `max_execution_time` and the `killAllQueries` of server shutdown were ignored. At shutdown, queries are killed before the DDL worker is joined, but merges are cancelled only after it, so a DDL worker running such an OPTIMIZE blocked the shutdown. Seen in `La Casa Del Dolor (amd_debug)` / `Server shutdown` on ClickHouse#127482, where the harness force-killed the server after 30 s. Both waits now run in slices of at most 1 s and call `QueryStatus::checkTimeLimit(OverflowMode::THROW)` before each slice, as ClickHouse#129283 did for `StorageReplicatedMergeTree::waitForProcessingQueue`. The THROW mode makes `timeout_overflow_mode = 'break'` stop the wait too. The total wait, the re-selection after a notification and the timeout error are unchanged. The new test pauses a mutation with `mt_mutate_task_pause_in_prepare` and checks `KILL QUERY` and `max_execution_time` (throw and break, explicit partition and whole table with parallel helpers). The second partition's part is inserted after the mutation, so it gets no mutation task of its own: the failpoint pauses only once, and a clone task of that part would otherwise race for it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wait The sliced wait re-selected only when `wait_for` returned `no_timeout`. libc++ derives that result from the clock after re-acquiring the mutex, so a merge that finalized around a slice deadline was reported as a timeout and its notification was lost. If it was the last running merge, nothing notified again and the OPTIMIZE waited out the rest of `lock_acquire_timeout_for_background_operations`. `CurrentlyMergingPartsTagger::finalize` now increments a counter under the mutex before `notify_all`, and each slice waits with a predicate on that counter, so a finished merge is observed at the latest when its slice ends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The status was checked only before each slice of the wait, so a wait could end on a merge that finished after the query was killed. The re-selection then succeeded and `merge` ran the new merge under the background context, which never looks at the query; the kill was reported only after the merge was done. Both waits now check the status once more when they end. The test covers a `KILL` sent together with the release of the awaited mutation and the success path of a waiting `OPTIMIZE FINAL`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e waits end promptly Case 4's Code: 394 is also raised after a merge, by the killed-query check that executeQuery runs once the interpreter returns, so the case now checks that the part of partition 0 keeps level 0. Cases 4 and 5 release the mutation only after the OPTIMIZE logged that it waits for it, so they exercise the wait itself. The query_log duration bound on cases 2 and 3 catches a wait that is not sliced and ends only at lock_acquire_timeout_for_background_operations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261107-002700 |
|
cc @PedroTadim @azat, could you review this and add the |
|
Workflow [PR], commit [22fb30a] Summary: ✅
AI ReviewSummaryThe PR makes the memory-pressure and running-merge waits of Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings to post. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units21 translation units recompiled, 209 s compile time in total, 21 of them have a recent master baseline. |
CI finish ledger - 842ab28Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped. The only other CIDB Session id: cron:our-pr-ci-monitor:20261107-073005 |
Master's Style check (234b980) now requires every test that reads system.text_log to have an event_time condition. Use the idiom master's tests adopted: event_date >= yesterday() AND event_time >= now() - 600. The polled message is logged by the OPTIMIZE a few seconds before the poll, so the window cannot exclude it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #127482
Related: #129283
Fixes: #6093
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
KILL QUERY,max_execution_timeand server shutdown now stop anOPTIMIZE ... FINALof aMergeTreetable that waits for currently running merges, instead of letting it wait up tolock_acquire_timeout_for_background_operationsper finished merge.Description
Failing job:
La Casa Del Dolor (amd_debug)/Server shutdownon #127482 (report). The server was force-killed 30 s after SIGTERM: the main thread was joiningDDLWorker, and the DDL worker ran anOPTIMIZE TABLE ... FINALparked inStorageMergeTree::selectPartsToMerge, waiting for running merges.That wait (
currently_processing_in_background_condition, up tolock_acquire_timeout_for_background_operations, 120 s by default, re-armed after every finished merge) and the memory poll before it never look at the query status, and nothing notifies the condition when a query is killed. Shutdown kills all queries before it joins the DDL worker but cancels merges only after it, so the join blocks.Both waits now run in slices of at most 1 s and call
QueryStatus::checkTimeLimit(OverflowMode::THROW)before each slice and when the wait ends, so a query cancelled just before the awaited merge finishes does not go on to run its own merge. #129283 sliced theReplicatedMergeTreewait the same way. The total wait and the error on timeout are unchanged. AnOPTIMIZE FINALthat waits for merges now fails when itsmax_execution_timepasses, also withtimeout_overflow_mode = 'break'.Validation: the new test pauses a mutation with
mt_mutate_task_pause_in_prepare. Before the fix,KILL QUERYandmax_execution_time = 2were ignored and every case ended after 30 s withCANNOT_ASSIGN_OPTIMIZE; after it they end in 1-2 s with codes 394 and 159. The test also checks that aKILLsent together with the release of the mutation stops theOPTIMIZEbefore it merges the partition, and that without a cancellation the waitingOPTIMIZEmerges as soon as the mutation finishes. Locally,ON CLUSTER+ SIGTERM shut down in 1.2 s instead of hanging. The test passed 50/50 randomized runs and 20/20 without randomization.Workflow [PR]
Sync PR [sync-upstream/pr/129875]