Repository navigation
Conversation
Check table refusals before stopping database replication, and reject unsupported detaches of nonempty `MaterializedPostgreSQL` databases before shutting down their handler. Preserve one-shot `force_drop_table` checks. Add regressions for `Replicated` DDL and PostgreSQL replication after refused database operations. Closes: ClickHouse#127875
|
@groeneai can you do a first level of review |
groeneai
left a comment
There was a problem hiding this comment.
Disclosure: #123694 is my PR and overlaps with this one (details at the end).
I applied 19777b9 to master a6418d9 and tested a debug build on local servers. Two findings are inline: a hang in stopReplication while this function still holds table references, and a size check that is skipped for a table that grows after the pre-check.
Checked and fine:
- Refused size drop of a
Replicateddatabase:CREATE TABLEafterwards fails withDATABASE_REPLICATION_FAILEDon master and works here. force_drop_tablewith one table over the limit: the database is dropped and the flag is consumed once.DROP DATABASEduring a refresh of a refreshable view in aReplicateddatabase: master refuses on the.tmp.inner_idtable after dropping.inner_id; this PR refuses before touching any table, and the refresh keeps running.MaterializedPostgreSQL(from the code, I did not run PostgreSQL):detachTablealways throws on master, so refusing a nonemptyDETACH DATABASEup front changes no outcome. The only other caller ofassertCanBeDetached,DatabaseCatalog::detachDatabase, calls it after anempty()check, so the override cannot fire there.- Other engines: the only change is the earlier
assertCanBeDetached(true)onDETACH DATABASE, the same check master runs at the end.
Overlap with #123694: both edit the else size check in executeToTableImpl and the stopReplication call, and add the same std::set<std::weak_ptr<IStorage>, std::owner_less<>> member, so they conflict textually. Neither covers the other. With each diff applied to the same master: both keep replication after the refused size drop; in the refreshable view case only this PR refuses before the stop (#123694 refuses after it, so DDL then fails with DATABASE_REPLICATION_FAILED); in the Buffer case from the inline comment #123694 refuses (after the stop) and this PR drops the table. From the code: only this PR refuses the MaterializedPostgreSQL DETACH DATABASE and pre-checks access and checkTableCanBeDetached; only #123694 runs the checks before preparing tables for shutdown in databases without replication.
…ain tables that did not use the drop flag
|
I re-checked 8aa26b1 (applied to master 2170ef3, debug build) on local servers. Both findings are fixed:
The PR still keeps replication running where it should.
The |
|
Workflow [PR], commit [ee72b9f] Summary: ✅
AI ReviewSummaryReviewed #127896 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
…'s replication `DROP DATABASE` and `DETACH DATABASE` by a user who may not drop the table, and `DROP DATABASE` of a table that a dictionary in another database reads, are refused. The data is kept, and `CREATE TABLE` still works afterwards.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units13 translation units recompiled, 87 s compile time in total, 13 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
I have kept @groeneai could you re-review the current revision and the four still-open threads? Your last check confirmed those four findings were addressed; I have left thread resolution to the reviewer. |
|
I re-checked ee72b9f. The only change since 8aa26b1, which I checked on 2026-11-10, is the new The new test, on a debug build of this PR applied to master 79929b2c:
(Runs that hit my machine's I cannot resolve the four threads: GitHub does not allow it for my account on this PR. As the PR author you can, and from my side all four are addressed. Two of them (the |
Closes: #127875
Related: #123694
InterpreterDropQuery::executeToDatabaseImplstops database replication before checking whether its tables can be dropped or detached. A refusal then leaves the database attached with its replication worker shut down. For aReplicateddatabase, subsequent DDL fails withDATABASE_REPLICATION_FAILED. For aMaterializedPostgreSQLdatabase, new rows in PostgreSQL silently stop arriving.Run the existing table refusal checks before
stopReplicationfor databases with replication threads. Remember only the storage whose size check consumedforce_drop_table, so its drop does not need the flag a second time; the other tables are checked again afterflushAndPrepareForShutdown, as on master. Release the checked tables beforestopReplication, because the replication worker may be executing aDROP TABLE ... SYNCthat waits until nothing else holds the table. Check database detachability before shutdown, and reject detaching a nonemptyMaterializedPostgreSQLdatabase before its replication handler is stopped.Reproduced and validated with a master-based Debug build, version
26.11.1.1, atce534743bf1, before and after applying the fix:Replicated: refuseDROP DATABASEwithmax_table_size_to_drop = 1, then create another tableCREATE TABLEfails withDATABASE_REPLICATION_FAILEDMaterializedPostgreSQL: refuseDETACH DATABASE, then insert 1,000 more rows into PostgreSQLMaterializedPostgreSQL: refuse a size-limitedDROP DATABASE, then insert 1,000 more rows into PostgreSQLAdded
05452_refused_drop_database_keeps_replication, which also checks a subsequent successful detach/attach and drop and aBuffertable that fills its destination during the drop,test_drop_database_while_worker_drops_table_syncintest_replicated_database, which drops the database while its worker executes aDROP TABLE ... SYNCfrom another replica, two parameterizations oftest_refused_database_drop_keeps_replicationin the existing PostgreSQL integration cluster, and05452_refused_drop_database_access_keeps_replication, which checksDROP DATABASEandDETACH DATABASEby a user who may not drop the table andDROP DATABASEof a table that a dictionary in another database reads. All four regression cases fail without the fix and pass with it.The patched Debug build, both existing PostgreSQL table attachment/detachment tests,
03362_create_table_after_truncate_replicated_database, and05325_replicated_database_drop_view_with_time_series_inner_tablepass. A separate check verifies that a size-limited database drop authorized byforce_drop_tablesucceeds and consumes the flag once. C++ style, Python lint and Black checks pass.This does not make database drops transactional: cancellation or an execution-time failure after shutdown has begun can still leave a partially processed database. The related PR addresses the broader table-shutdown ordering.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
DROP DATABASErefused by access, table size or dependency checks, or aDETACH DATABASErefused by access checks, no longer stops replication of aReplicatedorMaterializedPostgreSQLdatabase. An unsupportedDETACH DATABASEof a nonemptyMaterializedPostgreSQLdatabase is also refused before stopping replication.Workflow [PR]
Sync PR [sync-upstream/pr/127896]