Repository navigation
Conversation
`InterpreterDropQuery::executeToDatabaseImpl` called `flushAndPrepareForShutdown` on every table of the database and only then ran, per table, the checks that can refuse the drop: transaction support, cross-database dependencies (`checkTableCanBeRemovedOrRenamed`) and `max_table_size_to_drop` (`checkTableCanBeDropped`). Preparation is irreversible, so when one table refused, the tables processed before it were already dropped and the remaining ones stayed prepared but alive: `ReplicatedMergeTree` tables became read-only "due to shutdown" (INSERT, OPTIMIZE and KILL MUTATION fail with TABLE_IS_READ_ONLY) and `MergeTree` tables had their merges cancelled forever (OPTIMIZE FINAL fails with ABORTED), until `SYSTEM RESTART REPLICA`, DETACH/ATTACH or a restart. In the Upgrade check of ClickHouse#119598 the stress phase ran `DROP DATABASE IF EXISTS test_7`, which was refused with HAVE_DEPENDENT_OBJECTS because a dictionary in `test_7_1` reads `test_7.table_for_dict`. That left `test_7.t_lightweight_mut_3` read-only and the pre-upgrade KILL MUTATION failed. Run the three deterministic checks for all collected tables before any table is prepared (and again after the refreshable-MV re-collect), the order DROP TABLE and DETACH PERMANENTLY already use. `Context::checkCanBeDropped` removes the `force_drop_table` flag when it authorizes an over-limit drop, so the storages checked here are remembered by identity and the per-table loop does not check their size again; a storage swapped in under a checked name is a different object and is still checked. With the flag and two or more over-limit tables the statement is now refused before touching any table. Not covered: KILL QUERY during the loop, a dependent created after the checks, a missing per-table DROP TABLE grant, and `stopReplication` of Replicated databases. Closes ClickHouse#62933 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… stops A refresh in progress of a refreshable materialized view owns a filled `.tmp.inner_id.<uuid>` table in the same database. `DROP DATABASE` stops such views before collecting the final list of tables, and stopping the view drops that table with the size limit disabled, so master never checks its size. The pre-flight added by the previous commit ran before the views were stopped and size-checked it, so a `DROP DATABASE` that master accepts was refused with TABLE_SIZE_EXCEEDS_MAX_DROP_SIZE_LIMIT, or spent `force_drop_table` on the transient table. The first pre-flight now runs after the list of views to stop is known and skips the size check of refresh temporary tables when there are such views; the transaction and dependency checks stay unconditional. A temporary table that survives the stop (a leftover of a crashed refresh) is in the re-collected list and is size-checked by the second pre-flight. The name test is shared with the dependency sort. New integration case `test_drop_database_during_refresh`: fails on the previous commit, passes on master and with this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…resh The previous commit skipped the size check of every `.tmp.inner*` table in the first pre-flight whenever `DROP DATABASE` stops a refreshable view. Only the temporary table of a refresh that is running is dropped by stopping its view. A leftover of a crashed or failed refresh next to an idle view survives the stop, so the second pre-flight refused the statement after the view's refresh task had been shut down for good: the view stayed registered but no longer refreshed until restart. The first pre-flight now skips only `.tmp` + the inner table name of each view to be stopped whose refresh task is `Running`; the second one skips nothing. The name helper and the dependency-sort change are reverted. New integration case `test_drop_database_refused_by_refresh_leftover`: fails on the previous commit and on master (the view is gone from `system.view_refreshes` after the refused drop), passes with this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit skipped the size check of `.tmp` + the inner table name in the first pre-flight whenever the view's refresh task was `Running`. That state is set as soon as an attempt is requested, before the attempt creates (CREATE OR REPLACE) its temporary table, so a leftover of an earlier failed refresh under that name was still exempt. Stopping the view does not drop a leftover, so the second pre-flight refused the statement after the view's refresh task had been shut down for good. `RefreshTask` now publishes whether the attempt in progress has created its temporary table (set right after `prepareRefresh`, cleared when the attempt returns), and `DROP DATABASE` exempts the name only while that holds. New integration case `test_drop_database_refused_by_leftover_of_pending_refresh` (holds the attempt with the `refresh_mv_skip_execution` failpoint): fails on the previous commit and on master (the view is gone from `system.view_refreshes` after the refused drop), passes with this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the ExecutionState::temp_table_created comment that repeated the accessor's, and fold the pre-flight comment into 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, 4 findings, the last round clean) plus my own review (5 nits).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261003-131200 |
|
Workflow [PR], commit [046f745] Summary: ❌
AI ReviewSummaryThe PR checks transaction support, dependencies and table size before preparing a database's tables for shutdown or stopping its replication. The deterministic refusal paths have regression coverage, but the revised force-drop accounting still permits an over-limit table to be deleted without its check consuming the force flag. Missing context / blind spots
Findings❌ Blockers
Final VerdictStatus: ❌ Block Make force-drop exemptions depend on the actual consuming check, and verify that another drop consuming the flag cannot bypass the final size guard. |
| /// Last, because it may consume the `force_drop_table` flag. | ||
| for (const auto & table : tables_to_check_size) | ||
| { | ||
| table->checkTableCanBeDropped(table_context); |
There was a problem hiding this comment.
Because this result is cached in tables_with_checked_size, the later executeToTableImpl path never re-runs checkTableCanBeDropped after prepare_tables() has frozen the tables. That weakens max_table_size_to_drop for ReplicatedMergeTree: a concurrent INSERT can still land between this preflight and flushAndPrepareForShutdown(), grow the table past the limit, and the database drop will still delete it. Can we revalidate the size after the tables are prepared (or otherwise freeze writes before trusting this preflight result)?
There was a problem hiding this comment.
🕵 Done in 802b9d8: only the tables whose check consumed force_drop_table are now remembered (detected by the flag file disappearing during their check). Those tables cannot be checked again, because the flag is gone. Every other table is no longer cached, so executeToTableImpl checks its size again after prepare_tables, as on master. A table that grows past the limit in that window is therefore still refused, at the cost of leaving the remaining tables prepared for shutdown (the pre-PR behaviour for that narrow race).
There was a problem hiding this comment.
[Blocker] The final size-check bypass is still reachable through the new flag detection at src/Interpreters/InterpreterDropQuery.cpp:673-679: disappearance of the server-wide force_drop_table file does not establish that this table consumed it.
For example, with a 1 MiB limit:
- The preflight reads that the flag exists for an under-limit
a.t. - A concurrent
DROP TABLE b.uconsumes the flag in another database. - The check of
a.treturns because it is below the limit (Context::checkCanBeDropped,src/Interpreters/Context.cpp:9021-9022), but the missing file makes this code inserta.tintotables_with_checked_sizeanyway. - An
INSERTgrowsa.tabove the limit beforeprepare_tables. The check atInterpreterDropQuery.cpp:403-404is then skipped, deleting an over-limit table whose drop never consumed the flag.
Please propagate whether the particular check actually used the flag from the consuming operation, instead of inferring ownership from two filesystem observations. Cover consumption by a concurrent table/partition drop as well as the existing serial flag cases.
There was a problem hiding this comment.
I am leaving this as is: misattributing the flag needs a second drop that consumes the single-use force_drop_table file during this one size check, plus an INSERT that pushes the table over the limit before prepare_tables. Master accepts the same check-then-drop race (executeToTableImpl checks the size before flushAndShutdown, and the IStorage::checkTableCanBeDropped comment calls a size change during the operation not very important), while propagating the result from the consuming check would change that virtual and its 9 overrides.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+23.01 KiB total), 0 added.
716 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 units43 translation units recompiled, 266 s compile time in total, 43 of them have a recent master baseline. |
CI finish ledger - afb7b5fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these touches Session id: cron:our-pr-ci-monitor:20261003-200032 |
|
Fixing PR for 05237_with_expression_alias_scope_descendant (DBReplicated): #123774 |
|
A Running |
…TABASE can proceed A refused DROP DATABASE of a Replicated or MaterializedPostgreSQL database left its replication stopped until a server restart: every later DDL query in a Replicated database failed with DATABASE_REPLICATION_FAILED. The refusal checks now run before stopReplication. The replication can create, drop and rename tables until it is stopped, so the tables are listed and checked again after it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
DROP DATABASE is refusedDROP DATABASE is refused
|
Confirmed, and fixed in 39fdac4: the checks now run before After a refused This also closes #74791. #127896 adds the same checks before |
The first list of tables is taken before `stopReplication()`, and the references to the storages were kept until after it. Stopping the replication of a `Replicated` database joins its DDL worker; if that worker is executing a `DROP TABLE ... SYNC` replicated from another replica, it waits until nobody holds the dropped table, so both waited for each other until the worker's query was killed. Measured with two servers (replica B runs `DROP DATABASE` while its DDL worker, paused by `database_replicated_stop_entry_execution`, executes `DROP TABLE t SYNC` from replica A): DROP DATABASE hung for more than 60 s on the previous head, with the worker in `waitTableFinallyDropped` and the drop in `DDLWorker::shutdown`; with this change it finishes in about 2 s (3 of 3), as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - e60d7bbEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The 3 Session id: cron:our-pr-ci-monitor:20261027-150018 |
…DATABASE` The size check before `prepare_tables` was cached for all tables, so `executeToTableImpl` did not check them again after `flushAndPrepareForShutdown`, and an `INSERT` in between could make a table exceed `max_table_size_to_drop` unnoticed. Now only the tables whose check consumed `force_drop_table` are skipped later (they cannot be checked again, because the flag is gone); the others are checked again after they are prepared for shutdown, as before this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123694&sha=e60d7bb84471e235f3b81bf0fc307ea416a7ea2e&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%20targeted%29 ( |
|
Same race as on #101783 and #115453, and the fix is already in progress: ClickHouse/librdkafka#23. The write is It has been open and mergeable since 2026-10-21, with no review yet. It is based on |
|
ClickHouse/librdkafka#23 is merged, and #129623 bumps |
…gh the query storage cache `DatabaseCatalog::tryGetTable` goes through `Context::getOrCacheStorage`, which pins each qualified name to the storage it first resolved to for the rest of the query, following that storage across a concurrent rename or exchange. The pre-flight checks ran this lookup before the per-table loop, so the loop's own lookup in `executeToTableImpl`, made under the table's DDL guard, got the pinned storage instead of the table that has the name now. With `EXCHANGE TABLES db1.t AND db2.t` between the pre-flight and the loop (the window is open while stopping a refreshable view waits for its refresh), `DROP DATABASE db1` dropped `db2.t` and then failed with `DATABASE_NOT_EMPTY` because `db1.t` was left. Master never looks the tables up before the loop, so it drops the current `db1.t` and leaves `db2.t` alone. `DETACH DATABASE` runs the same pre-flight lookup. Look the table up in the database being dropped, like the dependency sort below does; that is the lookup `getTableImpl` makes for a name without a UUID, so the storage the pre-flight remembers for `force_drop_table` is the one the loop finds. The new integration case parks a refresh where stopping the view cancels it, runs the exchange while `DROP DATABASE` waits there, and checks that the exchanged table survives: it fails on the previous head with `DATABASE_NOT_EMPTY` and passes on master and with this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s replaced With `lazy_load_tables = 1`, a table nobody has read since the database was attached is a `StorageTableProxy`. The size check of the `DROP DATABASE` pre-flight loads it and may consume `force_drop_table`, and the exemption was remembered under the proxy. Since ClickHouse#118699 the database replaces an unused proxy by its loaded storage on the next lookup, so `executeToTableImpl` got the loaded storage, missed the exemption and checked the size again without the flag: an authorized `DROP DATABASE` was refused with `TABLE_SIZE_EXCEEDS_MAX_DROP_SIZE_LIMIT` after the tables were prepared for shutdown (merges cancelled). Record and look up the exemption by `resolveStorageProxy`, the loaded storage of a lazy proxy, which is what the database replaces it with. An unrelated storage swapped in under the same name still does not match. Reported by clickhouse-gh[bot]: ClickHouse#123694 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
`StorageRabbitMQ::checkTableCanBeDropped` and `StorageNATS::checkTableCanBeDropped` set a plain `mutable bool drop_table`. Every caller on master holds the table's DDL guard, but the pre-flight of `DROP DATABASE` calls the hook while holding only the database guard, so a concurrent `DROP TABLE` of the same table writes the field and reads it in `StorageRabbitMQ::shutdown` with no ordering against that write: a data race. The value stored is always `true`, so an atomic flag is enough and keeps the behaviour unchanged. The side-effect-free `checkTableSizeBelowDropLimit` used by `CREATE OR REPLACE` is not a drop-in replacement here: its materialized view and `TimeSeries` overrides also check their inner tables, which `DROP DATABASE` checks as tables of their own, so `force_drop_table` would be consumed twice. Reported by clickhouse-gh in ClickHouse#123694 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
@groeneai, fix conflicts. |
…tabase-keeps-tables # Conflicts: # src/Storages/RabbitMQ/StorageRabbitMQ.h
…s a refresh Since `Refuse RENAME and EXCHANGE of the tables of a database being dropped` (ClickHouse#133016) `DROP DATABASE` holds the exclusive side of `restart_replica_mutex` from listing its tables until it has dropped them, and every `RENAME` and `EXCHANGE` try-locks the shared side, failing with `UNFINISHED`. The window in which `test_drop_database_concurrent_exchange` exchanged a table (stopping a refreshable view that waits for its refresh) is inside that lock, so the exchange is now refused and the other database's table keeps its own row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`DROP DATABASE` now refuses a concurrent `RENAME` or `EXCHANGE` of its tables (ClickHouse#133016), so the window this case exchanged a table in is closed, and its remaining assertion (the exchange fails with `UNFINISHED`) holds with either lookup in the pre-flight. `05839_drop_database_refuses_concurrent_rename` covers that refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master and resolved the conflict in |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
DROP DATABASEorTRUNCATE DATABASErefused because a table exceedsmax_table_size_to_drop, a dictionary in another database depends on one of its tables, or a table does not support the current transaction, now drops no table, leaves every table writable and keeps the replication of aReplicatedorMaterializedPostgreSQLdatabase running. Before, the tables processed first were dropped, the remainingReplicatedMergeTreetables rejectedINSERTwithTABLE_IS_READ_ONLY, the remainingMergeTreetables never merged again, and DDL queries in aReplicateddatabase failed withDATABASE_REPLICATION_FAILED, until a restart. Closes #62933. Closes #74791.Description
Closes: #62933
Closes: #74791
Related: #120643
Related: #127875
On 26.9, a
DROP DATABASErefused bymax_table_size_to_dropor by a dependent dictionary leavesReplicatedMergeTreetables rejectingINSERT(TABLE_IS_READ_ONLY),MergeTreetables failingOPTIMIZE(ABORTED) and aReplicateddatabase failing DDL (DATABASE_REPLICATION_FAILED).Failing job: Upgrade check (amd_release) on #119598. Its stress phase ran
DROP DATABASE IF EXISTS test_7, refused withHAVE_DEPENDENT_OBJECTS;test_7.t_lightweight_mut_3stayed read-only, soKILL MUTATIONfailed.executeToDatabaseImplstopped the replication and calledflushAndPrepareForShutdownon every table, and only then ran the checks that can refuse the drop. The transaction, dependency and size checks now run for all tables first. The replication can change the tables until it is stopped, so they are listed and checked again after the stop. The size check can consumeforce_drop_table: with the flag and two or more tables over the limit, the statement is refused, consuming the flag; usemax_table_size_to_drop = 0or drop the tables one by one.Not covered:
KILL QUERYduring the loop, a missing per-tableDROP TABLEgrant, a refusal that appears only after refreshable views or the replication were stopped (they stay stopped).Validation: each refusal route has a case that fails on master and passes here, including a
Replicateddatabase. Refreshable views: a running refresh's temporary table does not block the drop; a leftover one refuses it before the stop.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123694]