Repository navigation
Fix a table disappearing after a failed SYSTEM RESTART REPLICA - #131883
alexey-milovidov merged 5 commits into
Conversation
…e its definition `doRestartReplica` detached the table, waited for it to become unused, and only then ran `getColumnsDescription` / `getConstraintsDescription`. The latter evaluates a constraint's scalar subquery, so a constraint reading a missing table (or one being restarted at the same time, `TABLE_IS_BEING_RESTARTED`) threw before the `try` block that retries re-creation and adjusts the `DatabaseReplicated` digest. The table then disappeared from the database until server restart. Analyze the stored definition before the table is shut down, outside the exclusive lock (the subquery may need to lock a table that is being restarted); the table's DDL guard, held for the whole restart, keeps the definition from changing until the detach. Move `waitDetachedTableNotInUse` into the `try` block so a kill during the wait also goes through the digest adjustment. Related: ClickHouse#129515 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [bbbee29] Summary: ✅
AI ReviewSummaryThe PR analyzes the stored table definition before shutdown, preserving the attached table when analysis fails, and includes detached-table wait failures in the existing Missing context / blind spots
Final Verdict✅ Approve |
SYSTEM RESTART REPLICA fails to analyze its definitionSYSTEM RESTART REPLICA
`01646_system_restart_replicas_smoke` already pins the same invariant: a `SYSTEM RESTART REPLICA` whose re-parse of the stored definition fails must not leave the table lost. Keep both under one prefix so they sort together. Co-Authored-By: Claude Opus 5 <[email protected]>
`check_style.py` rejects any test whose path contains `fail`, so `..._failed_analysis_...` fails the style check. Name it after the condition it covers instead: an error while analyzing the stored definition. Co-Authored-By: Claude Opus 5 <[email protected]>
…art-replica-lost-table
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131883&sha=528af85a999afd1fadeca7909590126e087afd9a&name_0=PR&name_1=Build%20profile%20diff ( |
AI review of a later commit does not approve the PR, see the AI Review comment.
|
The fix is #129675 (mine, open). In this run (job log) all 8 readiness probes connected to the CI logs cluster and then got |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 33 s compile time in total, 7 of them have a recent master baseline. |
Related: #129515
Problem
When
SYSTEM RESTART REPLICAfails after the table has been detached but before the re-created table is attached, the table disappears from the database until the server is restarted (its metadata file stays on disk). ForDatabaseReplicatedthe in-memory digest is also not adjusted on this path.One way to hit it: a table whose constraint has a scalar subquery reading another table, while that table is missing or is being restarted at the same time:
The stress test exposes this (with
TABLE_IS_BEING_RESTARTED) since it started to run randomSYSTEM RESTART REPLICA(S)in #129515.Root cause
InterpreterSystemQuery::doRestartReplicadetaches the table, waits for it to become unused, and only then analyzes the stored definition withInterpreterCreateQuery::getColumnsDescriptionandInterpreterCreateQuery::getConstraintsDescription. The latter runsTreeRewriter::analyze, which evaluates the constraint's scalar subquery. Its exception, like one fromwaitDetachedTableNotInUse(the query being killed), is thrown before thetryblock that retriesStorageFactory::instance().getand adjusts theDatabaseReplicateddigest, so nothing re-attaches the table.Solution
lockExclusively, because the constraint's subquery may need to lock a table that is being restarted. Reading the definition before the exclusive lock is safe: the table's DDL guard, held for the whole restart, is also taken by everyALTER(including replicated metadata alters applied in the background), so the definition cannot change before the detach.waitDetachedTableNotInUseinto thetryblock (before the retry loop), so its exception, e.g. the query being killed during the wait, also goes through theDatabaseReplicateddigest adjustment.Test:
01646_restart_replica_definition_error_keeps_table, which fails on master (the table vanishes) and passes with the fix.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a table disappearing until server restart after
SYSTEM RESTART REPLICAfailed, for example because the table's constraint references a table that is missing or being restarted.Workflow [PR]
Sync PR [sync-upstream/pr/131883]
Version info
26.12.1.141-master(included in26.12and later)