Repository navigation
Do not cancel the parts of ON CLUSTER backups and restores during a graceful shutdown that waits for them - #124334
Conversation
With `shutdown_wait_backups_and_restores = true` (the default) a graceful shutdown waits only for backups and restores already registered in `BackupsWorker`, then `ProcessList::killAllQueries` cancels every query. The DDL worker keeps running until `Context::shutdown`, so an internal ON CLUSTER leg it starts right before the kill is cancelled "in pending state", the backup inherits that cancelled query status, and the whole ON CLUSTER backup ends `BACKUP_CANCELLED` (flaky `test_shutdown_waits_for_backup`). In wait mode both shutdown kills now spare BACKUP and RESTORE queries; `BackupsWorker::shutdown`, which already runs after `DDLWorker::shutdown`, waits for them. `ContextSharedPart::shutdown` drains the DDL and backups workers before joining the dictionaries loader threads, because a restore can create a dictionary, and then kills what is left unconditionally. The new failpoint `backups_delay_before_registering_operation` holds an operation before registration so the race is deterministic in a test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… hosts An initial BACKUP/RESTORE ... ON CLUSTER sends its own host's part through this host's DDL queue and then waits for all hosts without a timeout. If it missed the shutdown wait and were spared by the kill, the DDL worker is stopped before the local part runs and BackupsWorker::shutdown blocks until the 3600 s host-disconnect timeout. Keep cancelling initial queries; spare only the non-initial parts the DDL worker runs for other hosts. Add a test for the RESTORE part. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A part killed with node2 is re-run by the DDL worker after a restart, so the new tests now read node1's final status after node2 stops and before it starts again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…flag The client can send SECONDARY_QUERY, so the shutdown kills now spare only BACKUP and RESTORE queries whose context the DDL worker made (Context::isDDLOrOnClusterInternal), captured once in the QueryStatus. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the member comment that restates Context::isDDLOrOnClusterInternal and the duplicate dictionary-ordering clause on the backups worker shutdown; shorten the killAllQueries comment to one line. 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; 4 rounds, 8 findings) plus my own review.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261006-213800 |
|
Workflow [PR], commit [0a738e2] Summary: ✅
AI ReviewSummaryThe change preserves DDL-worker parts of Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or changes to existing review threads are needed. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes113 object files changed (+19.66 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1354 translation units recompiled, 8950 s compile time in total, 1353 of them have a recent master baseline. Translation units without a recent master baseline:
|
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
| "SELECT count() FROM system.processes WHERE query_kind = 'Backup' AND NOT is_initial_query", | ||
| "1", | ||
| ) | ||
|
|
There was a problem hiding this comment.
If a loaded runner overruns 5s, addInfo completes, and the test then exercises the already-working registered path – while still asserting BACKUP_CREATED/RESTORED, which is exactly what a missed race produces.
There was a problem hiding this comment.
Agreed, the fixed 5 s delay could expire before the restart. Fixed in c77b0f1 and 86c7d9e:
- The failpoint (now
backups_hold_registration_until_ddl_worker_stops) no longer sleeps for a fixed time. It holds node2's part beforeBackupsWorker::addInfountil node2's DDL worker is stopping, andContextSharedPart::shutdownstops the DDL worker only afterkillAllQueries. So the part always registers after the kills, however slow the runner is. - Before stopping node2, the tests also assert that its part is running but has no
system.backup_logentry yet, so a hold that did not take effect fails the test instead of passing through the registered path. - If a test fails before the stop, it disables the failpoint, which releases the held part, so it does not block node2's DDL queue for the following tests.
Without the fix both tests fail on every run (BACKUP_CANCELLED 6/6, RESTORE_CANCELLED 6/6); with the fix they pass 15/15 each.
| "SELECT count() FROM system.processes WHERE query_kind = 'Restore' AND NOT is_initial_query", | ||
| "1", | ||
| ) | ||
|
|
The failpoint used by the two new shutdown tests slept for 5 seconds before `BackupsWorker::addInfo` registered the operation. If the graceful shutdown of node2 began more than 5 seconds after node2's part entered that window (a slow runner), the part was already registered, the shutdown wait covered it, and the tests passed without exercising the late-registration path at all. Replace the fixed delay with a hold that lasts until this host's DDL worker is stopping (or the failpoint is disabled). `ContextSharedPart::shutdown` stops the DDL worker only after `ProcessList::killAllQueries`, so the part now always registers after the shutdown cancelled queries, regardless of timing: without the fix the operation always ends cancelled, with the fix it always completes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before the graceful stop, both tests now assert that node2's part is running but has no `system.backup_log` entry yet, so a hold that did not take effect fails the test instead of letting it pass through the already-working path of a registered operation. If the test fails before stopping node2, the failpoint is disabled, which releases the held part; otherwise it would block node2's DDL queue for the following tests in the module. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The parts of ON CLUSTER backups and restores that the DDL worker registers after the shutdown wait were spared by both shutdown kills and left to `BackupsWorker::shutdown`. That runs in `Context::shutdown`, after the scope guard in `Server.cpp` has already shut down the AsyncLoader. A late `RESTORE DATABASE ... ON CLUSTER` of a dropped database then fails on the host being restarted: `InterpreterCreateQuery::createDatabase` schedules the database's startup job, and `AsyncLoader::schedule` throws `ASYNC_LOAD_CANCELED: AsyncLoader was shut down: While creating database mydb`. Drain those parts in `Server.cpp`, before the AsyncLoader stops: kill the other queries as before, stop the DDL worker (which makes every part it delivered registered), and wait for all backups and restores again. By default this happens right after the existing kill. With `shutdown_wait_unfinished_queries` there is no kill there, so the same kill and drain run after the queries were waited for. Late initiators are still cancelled before the DDL worker stops, because an initiator's own part needs it. A DDL worker whose startup job has not run yet must not be started after it is stopped, so the drain first removes that job from the AsyncLoader (cancelling it if pending, waiting for it if running). Since no such part outlives the drain, the `ContextSharedPart::shutdown` reorder and its sparing kill are reverted to master. The only path that skips the drain is a startup failure, where the DDL worker is not running. The restore shutdown test now restores a dropped database, so it covers the database and table creation, and it runs twice: restarting node2 (default settings) and restarting node3, which has `shutdown_wait_unfinished_queries`. - master shutdown code: RESTORE_CANCELLED (both cases) - previous head (541c81bf): RESTORE_FAILED, ASYNC_LOAD_CANCELED (both cases) - this commit without the drain after the query wait: RESTORE_CANCELLED in the `shutdown_wait_unfinished_queries` case - this commit (9120585a): RESTORED (both cases, 3/3 each) Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 163c3c5Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261016-110007 |
Stopping the DDL worker joins the task it runs, including ones that are not backups or restores. Before the connection wait, a `TRUNCATE ... ON CLUSTER` waiting in `lockExclusively` for a lock held by a native `INSERT` that waits for client data kept the shutdown waiting until `lock_acquire_timeout`, instead of exiting forcefully after `shutdown_wait_unfinished` as master does (66.0 s vs 5.5 s with `shutdown_wait_unfinished = 5` and `lock_acquire_timeout = 60`). The first kill stays where master has it and still spares the DDL worker's parts, which keep running during the connection wait. After the forced exit check, the remaining queries are cancelled again, as `ContextSharedPart::shutdown` does before it stops the DDL worker, then the DDL worker is stopped and all backups and restores are waited for, still before the AsyncLoader stops. Both `shutdown_wait_unfinished_queries` modes now use the same place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 29dad40Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The two targeted jobs stopped early and the integration Bugfix validation was dropped, so the tests selected for this diff have not fully run on this head. Session id: cron:our-pr-ci-monitor:20261017-030004 |
02fa087
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a graceful server shutdown cancelling a
BACKUP ... ON CLUSTERorRESTORE ... ON CLUSTERwhose part reached this host while it was shutting down, althoughshutdown_wait_backups_and_restores(enabled by default) makes the shutdown wait for running backups and restores.Description
On 26.8, a
BACKUP ... ON CLUSTERendsBACKUP_CANCELLEDwhen one host gets its part just as it starts a graceful shutdown, althoughshutdown_wait_backups_and_restores = truemakes a graceful shutdown wait for running backups.Related: #84798. CI failure of
test_shutdown_waits_for_backup: #101039.Root cause. On SIGTERM the server waits only for already registered backups, then
killAllQueries()cancels every query. The DDL worker runs untilContext::shutdown; in the CI failures it had started the internalBACKUPquery ~10 ms before SIGTERM, before registering it, so the kill cancelled it.Change.
Server.cppkill leaves running theBACKUP/RESTOREparts the DDL worker executes (recognized by a server-side flag, not the client's query kind). After the connection wait and the forced exit check, the server cancels the other queries, stops the DDL worker, which registers every part it delivered, and waits for all backups and restores before the AsyncLoader stops, because a restore can create a database. Any other backup or restore that misses the wait is still cancelled, because anON CLUSTERinitiator needs this host's DDL worker for its own part.shutdown_wait_backups_and_restores = falseis unchanged.backups_hold_registration_until_ddl_worker_stopsholds a part before it is registered until this host's DDL worker stops, which the shutdown does only after the kill, so the tests always exercise the late registration; they assert that the part is not registered when node2 begins shutting down.Validation. New tests: the
BACKUPone fails 6/6 without the fix (BACKUP_CANCELLED), theRESTOREone, which recreates a dropped database and also runs withshutdown_wait_unfinished_queries, 4/4 (RESTORE_CANCELLED); with the fix both pass, as does the original test. The backup modules oftest_backup_restore_on_clusterandtest_backup_restore_newpass. A shutdown during an unrelatedTRUNCATE ... ON CLUSTERstuck on a table lock still exits at theshutdown_wait_unfinisheddeadline.Workflow [PR]
Sync PR [sync-upstream/pr/124334]
Version info
26.11.1.166-master(included in26.11and later)