Repository navigation
Wait for DETACH DATABASE to release tables in three integration tests - #114628
PedroTadim merged 1 commit into
Conversation
Three integration tests intermittently fail with Code 219 "Database <db> cannot be detached, because some tables are still in use. Retry later." from DatabaseAtomic::assertCanBeDetached (src/Databases/DatabaseAtomic.cpp:521). Non-SYNC DETACH DATABASE is best-effort by contract: assertCanBeDetached throws if any table of the database still has a live refcount. The engine already implements the deterministic wait, waitDetachedTableNotInUse, but executeToDatabaseImpl calls it only under query.sync (src/Interpreters/InterpreterDropQuery.cpp:779-790). Stateless CI installs tests/config/users.d/database_atomic_drop_detach_sync.xml, which sets database_atomic_wait_for_drop_and_detach_synchronously=1, so stateless tests get the wait for free. The integration helpers install no such profile and run at the server default of 0, which is why the failures are confined to the integration suite and why 17 of 18 occurrences in 180 days are sanitizer builds, where the holder's window is wider. Code 219 is intended behaviour of the asynchronous form and is pinned in-tree by 01107_atomic_db_detach_attach.sh:19, which sets the setting to 0 to provoke it and asserts it. So the defect is on the test side: the tests use the asynchronous form while asserting synchronous semantics. Adding SYNC asks for the wait the engine already implements instead of changing engine behaviour. Fixed the five statements with observed CI failures: test_drop_replica (11 hits in 180 days), test_replicated_table_structure_alter (4 hits), and test_drop_database_replica:192 (2 hits, both stacks confirm that line throws, so :94 inside the existing detach_database_with_retry helper is left alone; its docstring documents a different holder). All 21 non-SYNC sites under tests/integration/ were enumerated; the remaining 16 either have zero failures in 180 days or already pass the setting explicitly. Validation: with a holder injected the way 01107 does it, the DETACH returns 219 without SYNC and succeeds with it, 10/10 on Atomic and on Replicated. The three tests pass 42 of 42 runs. Each DETACH in test_drop_replica measures about 0.115 s over 25 measurements, so the wait costs nothing when no table is held, and it is cancellable per iteration and shutdown-aware. Related: ClickHouse#93064
Internal second-model review (click to expand)An independent model reviewed this change cold against the code and the PR contract. Findings
Gate B was re-run after the description changed, so the reviewed contract is the published one. Session id: cron:clickhouse-review-slot-9:20260813-112300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260813-103200 |
|
Workflow [PR], commit [979703c] Summary: ✅ AI ReviewSummaryThis PR makes the touched integration tests use Final VerdictStatus: ✅ Approve |
|
cc @tavplubix, could you review this? Three integration tests issue a plain |
CI finish ledger - 979703cCI is fully finished on this head: 178 checks completed, none queued or in progress, the praktika aggregator reports
Coverage is real rather than skipped-through: the three integration shards this PR touches ran and passed ( Session id: cron:our-pr-ci-monitor:20260813-173000 |
b752b0f
|
backport to fix CI |
Backport #114628 to 26.6: Wait for DETACH DATABASE to release tables in three integration tests
…in three integration tests
Backport #114628 to 26.7: Wait for DETACH DATABASE to release tables in three integration tests
Backport #114628 to 26.3: Wait for DETACH DATABASE to release tables in three integration tests
…se tables in three integration tests
…se tables in three integration tests
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #93064
Three integration tests intermittently fail with
Code: 219 ... Database <db> cannot be detached, because some tables are still in use. Retry later.thrown fromDatabaseAtomic::assertCanBeDetached(src/Databases/DatabaseAtomic.cpp:521).Root cause: non-SYNC
DETACH DATABASEis best-effort by contract, and these tests assume it isatomic.
assertCanBeDetachedthrows if any table of the database still has a live refcount. Theengine already has the deterministic wait,
waitDetachedTableNotInUse, butexecuteToDatabaseImplcalls it only underquery.sync(
src/Interpreters/InterpreterDropQuery.cpp:779-790). Stateless CI installstests/config/users.d/database_atomic_drop_detach_sync.xml(
database_atomic_wait_for_drop_and_detach_synchronously=1); the integration helpers install nosuch profile and run at the server default of 0. Hence the failures are confined to the
integration suite, and 16 of the 17 integration occurrences in 180 days are sanitizer builds,
where the holder's window is wider.
Code 219 is intended behaviour of the asynchronous form and is pinned in-tree:
01107_atomic_db_detach_attach.sh:19sets the setting to 0 to provoke it and asserts it. Sothis is a test-side defect, and the change asks for the wait the engine already implements
rather than altering it.
I added
SYNCto the fiveDETACH DATABASEstatements with observed CI failures:test_drop_replica(11 hits/180d),test_replicated_table_structure_alter(4), andtest_drop_database_replica:192(2, both stacks confirm that line is the thrower). All 21non-SYNC sites under
tests/integration/were enumerated; the other 16 are excluded becausethey have zero CIDB hits in 180 days, already pass
database_atomic_wait_for_drop_and_detach_synchronously, or sit inside the existingdetach_database_with_retryhelper, whose docstring documents a different holder.Validation: with a holder injected the way
01107does it, the DETACH returns 219 withoutSYNCand succeeds with it, 10/10 onAtomicand onReplicated. The three tests pass 42/42runs. Each
DETACHintest_drop_replicameasures ~0.115 s over 25 measurements, so the waitcosts nothing when no table is held, and it is cancellable and shutdown-aware.
CI report for the master failure:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=91b700711adf0a07172e1046c8d8f013f1e0b82c&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29
Version info
26.8.1.1356(included in26.8and later)26.7.11.17,26.6.9.17,26.3.33.106