Repository navigation
Conversation
…per error DatabaseReplicatedDDLWorker::shutdown() eagerly removes the replica's "active" ephemeral node. That removal only exists so SYSTEM DROP DATABASE REPLICA does not spuriously report the replica as active; the node is released by session expiry regardless. But ZooKeeper::tryRemove throws on a hardware Keeper error and nothing on the DROP path caught it, so a transient Connection loss failed the user's whole DROP DATABASE ... SYNC with KEEPER_EXCEPTION and left the database attached with its tables half torn down. DatabaseReplicated::shutdown() already wraps stopReplication() in a first-error-and-continue path for exactly this hazard. The DROP path called stopReplication() bare, so it never got that handling. Two changes: - DatabaseReplicatedDDLWorker::shutdown() releases its node holders on the throwing path as well, so a repeated shutdown() does not retry the same failing removal. The exception still propagates, so the DatabaseReplicated::shutdown() contract and its database_replicated_throw_on_stop_replication failpoint keep working. setAlreadyRemoved() stays on the success path only, so that after a failed eager removal ~EphemeralNodeHolder still retries it. - InterpreterDropQuery treats the pre-drop stopReplication() as best effort for a DROP, rethrowing anything that is not a hardware Keeper error. DETACH keeps the database on disk to be reattached, so there the error still surfaces. Both changes are required: with only the interpreter catch, DatabaseCatalog:: detachDatabase calls db->shutdown() a second time during the same DROP, the removal is retried, throws again and is rethrown, so the DROP still fails. Found by Integration tests (amd_tsan, 4/6), which failed the same way on four unrelated pull requests on the same day. Co-Authored-By: Claude Fable 5 <[email protected]>
The healthy-session test added in the previous commit could not fail. It asserted that the replica path is gone after a DROP, but DatabaseReplicated::drop removes that subtree recursively anyway, so deleting the eager removal in DatabaseReplicatedDDLWorker::shutdown left every assertion passing. DETACH is the state that makes the removal observable: DatabaseCatalog::detachDatabase calls db->drop() only when dropping, so a DETACH stops replication and detaches the database while leaving the Keeper subtree intact. The new test asserts the active node is gone AND that the replica path still exists; the second half is what attributes the absence to the shutdown path rather than to a recursive cleanup. Deleting the eager tryRemove while keeping setAlreadyRemoved() now fails the new test on the active node assertion, while the pre-existing DROP test still passes. That pair is the evidence. The DROP test is kept: it is the only one asserting that a healthy DROP takes neither the injected error nor the best-effort branch. Also correcting the previous commit message: it said the failure left the tables half torn down. It does not. stopReplication() is called before table enumeration begins, so the database was left attached with its replication worker already stopped and no table touched. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112045&sha=6c7ac2f6fa2f42fad0b432647d063876394a67c5&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Related: ClickHouse#112045 Co-Authored-By: Claude Fable 5 <[email protected]>
The DROP path treats a failure to stop replication as best effort only for a
hardware Keeper error:
if (!drop || !Coordination::isHardwareError(e.code))
throw;
The test module pinned only the !drop term. Its single failpoint hardcodes
ZCONNECTIONLOSS, so no test injected a user-class error and neutralizing the
isHardwareError term left every test green while a DROP silently swallowed
ZNONODE, ZBADVERSION, ZNODEEXISTS, ZNOTEMPTY and ZNOCHILDRENFOREPHEMERALS.
Add a second REGULAR failpoint at the same site that throws ZBADVERSION, a code
that is in isUserError and that tryRemove itself can surface, and a test that
asserts the DROP still reports it and leaves the database attached.
Two mutations bracket the new test. Neutralizing only the isHardwareError term
fails exactly this test and leaves the other six passing. Reverting
InterpreterDropQuery.cpp to master entirely leaves this test passing, because the
error surfacing is also master's behaviour, while the best-effort DROP test
fails, so the two tests are complementary rather than redundant.
Module: 7 passed, and 70 passed with --count 10 --repeat-scope=function.
CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112045&sha=6c7ac2f6fa2f42fad0b432647d063876394a67c5&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29
Reported on ClickHouse#112045
The restore test disarmed the failpoint before its second SYSTEM RESTORE DATABASE REPLICA, so that restore only showed the database was usable again. Keep the failpoint armed across both restores instead: reinitializeDDLWorker throws out of ddl_worker->shutdown() before it can reset ddl_worker, so the second restore shuts the same stale worker down again, and it can only succeed if the failed shutdown released its holders. The INJECTED log count must then stay unchanged, asserted with exact equality, because count_in_log counts log lines and an unhandled throw on this path emits two of them, so any offset would be scale dependent. Deleting the SCOPE_EXIT block now fails this test on the second restore itself, alongside the best-effort DROP test that pins the same release through the other carrier. This also corrects the previous commit message, which described the injected ZBADVERSION as a code that tryRemove can itself surface. That is wrong: ZooKeeper::tryRemove returns ZOK, ZNONODE, ZBADVERSION and ZNOTEMPTY rather than throwing them, so the injection is synthetic. ZBADVERSION is still the right choice, because the test only needs a code that isUserError accepts and isHardwareError therefore rejects. The user-class codes tryRemove does throw, and that the guard rethrows, are ZNOCHILDRENFOREPHEMERALS and ZNODEEXISTS, so the branch is reachable in production even though the injected code is not. Module: 7 passed, and 70 passed with --count 10 --repeat-scope=function. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112045&sha=6c7ac2f6fa2f42fad0b432647d063876394a67c5&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Reported on ClickHouse#112045
The restore test sampled the INJECTED count as soon as query_and_get_error returned. The client returns once the server has sent the exception, while the remaining record for that same throw is written afterwards by TCPHandler::run, so a record could land between the two reads and fail the equality for a reason that has nothing to do with the removal being re-entered. Both reads now poll until the count stops growing, which keeps the assertion independent of how many records one throw emits, and raise if it never settles. The exact equality is unchanged: an unchanged count is what shows the removal was skipped rather than attempted and happening to succeed. This also corrects a false claim in my previous commit message, which named ZNOCHILDRENFOREPHEMERALS and ZNODEEXISTS as user-class codes this tryRemove can throw, and concluded from that the branch is reachable in production. That is wrong in both parts. Neither code can arrive from a remove request: in KeeperStorageImpl.cpp they occur only inside the ZooKeeperCreateRequest and ZooKeeperCheckRequest preprocess overloads, while the remove overload can return only ZBADARGUMENTS, ZNOAUTH, ZOK, ZNONODE, ZBADVERSION and ZNOTEMPTY. Of those, isUserError accepts ZNONODE, ZBADVERSION and ZNOTEMPTY, and tryRemove returns exactly those three rather than throwing them, so there is no user-class code this call site can throw. ZBADVERSION remains the right thing to inject, because the test only needs a code that isUserError accepts and isHardwareError therefore rejects, and the injection is synthetic either way. The guard's non-hardware branch is a conservative default rather than a branch some known production code reaches. The catch is keyed on the exception type, so it covers everything stopReplication can throw and not just this one tryRemove: DDLWorker::shutdown runs first and clears its own active node holders, and DatabaseReplicatedDDLWorker makes further Keeper calls on other paths. Narrowing to hardware errors keeps a genuine user-class or programming error visible instead of letting a DROP swallow it. Module: 7 passed, and 70 passed with --count 10 --repeat-scope=function. Deleting the SCOPE_EXIT block still fails the restore test on its second restore. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112045&sha=6c7ac2f6fa2f42fad0b432647d063876394a67c5&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Reported on ClickHouse#112045
Internal second-model review (5 rounds): all findings resolved, no open itemsIndependent review of this branch by a second model, plus my own cold review of the Round 5
Round 4
Round 3
Round 2 (closed)
Round 1 (all closed and verified closed)
Verified independently this round (no change requested)The fix logic itself is correct. I re-derived it from source rather than accepting
Disclosure: overlap with #110886The new catch keys on the exception type rather than the engine. It is unreachable |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-9:20260731-211900 |
|
cc @tavplubix @vdimir, could you review this? |
|
Workflow [PR], commit [5d0efed] Summary: ❌
AI ReviewSummaryReviewed #112829 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or thread changes are needed. Runtime verification remains subject to the pending CI results. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 33/38 (86.84%) · Uncovered code |
CI finish ledger - 4ea2fe0Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only 174 check runs, 0 queued or in progress,
On the hung check: I grepped the ingested 32 KiB of hung-check context for every path this diff touches and found zero occurrences of I am deliberately not linking the merged fix for one sub-cause of this hung-check family: it is already an ancestor of this head, so this run failed with that fix present and it does not resolve this signature. Session id: cron:our-pr-ci-monitor:20260801-153000 |
Only conflict was the failpoint registry in src/Common/FailPoint.cpp, where master added REGULAR(database_catalog_shutdown_sleep_per_table) at the same anchor as the two entries this branch adds. Kept all three. The merged list holds every failpoint master registers plus those two, with no kind change and no duplicate. The two other files this branch touches merged without conflict: master's edits to DatabaseReplicatedWorker.cpp (saturatedDuration, a settings type) and to InterpreterDropQuery.cpp (drop dependency ordering, QueryFlags, has_like) are all outside the shutdown() and stopReplication() call sites this branch changes.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 24 s compile time in total, 9 of them have a recent master baseline. |
CI finish ledger - 159aae5CI is fully finished and green on this head: 147 OK, 23 skipped, 0 failures, nothing to own. The only check without a result is the private CH Inc sync, which is not actionable here. For the record, Session id: cron:our-pr-ci-monitor:20260828-180000 |
Resolve the conflict with ClickHouse#128824 in DatabaseReplicatedDDLWorker::shutdown: its wake-up of the log_ptr waiters moves into the SCOPE_EXIT together with the holder release, so it also runs when the active node removal throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scenario needs one server, Keeper and failpoints, all of which the stateless tests have, so it does not need a dedicated integration cluster (see the integration test guidelines in .claude/CLAUDE.md). The test keeps the four cases: DROP survives a hardware Keeper error, DETACH still reports it and the active node is still removed, a non-hardware error still fails the DROP, and a second SYSTEM RESTORE DATABASE REPLICA does not repeat the removal. It is no-parallel because the failpoints fire on the shutdown of every Replicated database's DDL worker. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 5d0efedEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261108-180009 |
Related: #112045
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes
DROP DATABASEof aReplicateddatabase failing withKEEPER_EXCEPTIONwhen a transient Keeper error hits the best-effort removal of the replica'sactiveephemeral node. The database was left attached with its replication already stopped.Description
DatabaseReplicatedDDLWorker::shutdowneagerly removes the replica'sactiveephemeral node. That removal only exists soSYSTEM DROP DATABASE REPLICAdoes not spuriously report the replica as active; the node is released by session expiry regardless. ButZooKeeper::tryRemovethrows on a hardware Keeper error, and nothing on the DROP path caught it, so a transientConnection lossfailed the user's wholeDROP DATABASE ... SYNC. The throw happens before any table is touched, so the database stayed attached with its replication worker already stopped.DatabaseReplicated::shutdownalready wrapsstopReplicationin a first-error-and-continue path for this exact hazard, butInterpreterDropQuerycalled it bare. Two changes:First,
DatabaseReplicatedDDLWorker::shutdownreleases its node holders on the throwing path as well, so a repeatedshutdowndoes not retry the same failing removal. The exception still propagates, so theDatabaseReplicated::shutdowncontract and itsdatabase_replicated_throw_on_stop_replicationfailpoint keep working.setAlreadyRemovedstays on the success path only, so that after a failed eager removal~EphemeralNodeHolderstill retries it.Second,
InterpreterDropQuerytreats the pre-dropstopReplicationas best effort for a DROP, rethrowing anything that is not a hardware Keeper error. DETACH keeps the database on disk to be reattached, so there the error still surfaces.Both are required: with only the interpreter catch,
DatabaseCatalog::detachDatabasecallsshutdowna second time during the same DROP, the removal throws again and is rethrown, so the DROP still fails.Validation: a new failpoint makes the failure deterministic. A new stateless test fails on the unfixed build (the DROP fails with the injected
Coordination::Exceptionon theactivepath) and passes with the fix; mutations show each change is separately required.test_drop_database_replicastill passes.Found by
Integration tests (amd_tsan, 4/6), which failed the same way on four unrelated pull requests on the same day: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112045&sha=6c7ac2f6fa2f42fad0b432647d063876394a67c5&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29Workflow [PR]
Sync PR [sync-upstream/pr/112829]