Repository navigation
Conversation
…is dropped In the `Kind::Drop` branch of `InterpreterDropQuery::executeToTableImpl` the call to `NamedCollectionFactory::removeDependencies` preceded `database->dropTable`. Anything that throws inside `dropTable` therefore left the table with its on-disk metadata intact while its dependency was already gone, so the next `DROP NAMED COLLECTION` was wrongly permitted, the collection was deleted from disk, and every later server start failed to attach the surviving table. The throw does not need fault injection. `DatabaseAtomic::dropTableImpl` has no try/catch and its `txn->commit` can throw on a Keeper session expiry before the local rename; `DatabaseOnDisk::dropTable`'s rollback re-attaches the table and rethrows without restoring the dependency, and its window spans the whole `table->drop`. Moving the call after `dropTable` returns is safe from anywhere in the sequence: `removeDependencies` is a total, idempotent, non-throwing, in-memory-only erase, so the success path keeps the same observable end state. The map is rebuilt as tables attach, so a dependency lost to a crash self-heals on restart; the collection deletion the old order permitted does not, which is why the ordering is what has to change. A `ONCE` failpoint at the position the call vacated pins the invariant. Its `isPredefinedDatabase` guard wraps `fiu_do_on` rather than sitting in its body: for a one-shot point `fiu_fail` marks the point consumed before returning, so a guard inside the body would let a drop in `system` burn the one shot and skip the throw, making the regression test flaky instead of failing. Found while investigating a `Stress test (arm_tsan)` `Cannot start clickhouse-server` failure. That particular run is the detached-table variant, which is a different defect; this change closes the sibling ordering hole in the `Drop` path. `04318_remote_storage_engine_access` dropped its named collection without checking that the preceding `DROP TABLE` had removed the table. Under the stress profile that drop can be a no-op or be rewritten into a `DETACH`, and the test then passed while leaving a table that no later server start could load. It now pins both stress settings on that statement and only drops the collection once no attached or detached table references it. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold
Severity: blocker / major / nit. DISAGREE verdicts carry recorded evidence and are terminal Session id: cron:clickhouse-review-slot-8:20260827-172800 |
Pre-PR validation gate (click to expand)
Validation: new test and |
|
Workflow [PR], commit [c95632d] Summary: ✅
AI ReviewSummaryThe PR preserves dependencies when Findings
Tests
Final VerdictStatus: |
|
cc @evillique @tuanpach, could you review this? In the |
The Style check's `functional_tests_check` rejects any test under `tests/queries` whose path contains "fail" (`ci/jobs/check_style.py:238-239`), so `05045_drop_table_keeps_named_collection_dependency_on_failure.sh` turned it red. This is a pure rename of the `.sh` and its `.reference`. The test body, the failpoint name and the source change are untouched, because the rule matches the path and not the file content. Co-Authored-By: Claude Opus 5 <[email protected]>
| @@ -363,8 +365,15 @@ BlockIO InterpreterDropQuery::executeToTableImpl(const ContextPtr & context_, AS | |||
| table_lock = table->lockExclusively(context_->getCurrentQueryId(), context_->getSettingsRef()[Setting::lock_acquire_timeout]); | |||
|
|
|||
| DatabaseCatalog::instance().removeDependencies(table_id, check_ref_deps, check_loading_deps, is_drop_or_detach_database); | |||
There was a problem hiding this comment.
What do you think about either putting it into a try catch, both DatabaseCatalog::instance().removeDependencies and NamedCollectionFactory::instance().removeDependencies(table_id); or putting them after database->dropTable(context_, table_id.table_name, query.sync); altogether (although for sync it may wait a while, investigate)
There was a problem hiding this comment.
The try/catch, for four measured reasons. I built the fixture on this branch using the failpoint it adds.
First, a correction to the reproducer: a materialized view is not enough. With mv ... TO dst, an inner-table MV, a plain view, a Merge table and a Distributed table all reading src, loading_dependencies_table is empty for every one of them and DROP TABLE src succeeds immediately. The default check reads loading_dependencies (check_referential_table_dependencies is off by default) and none of those register there. A dictionary does: with dict1 sourced from src, DROP TABLE src gives Code: 630 HAVE_DEPENDENT_OBJECTS; after DROP DICTIONARY dict1 throws in the window, the dictionary is still present, its edge is gone, and DROP TABLE src then succeeds and destroys the source of a live dictionary. So the bug is real.
Second, on sync: the wait is not inside dropTable. executeToTable calls executeToTableImpl and only then waitForTableToBeActuallyDroppedOrDetached if query.sync, so a call moved after dropTable still finishes before the wait starts. DROP TABLE ... SYNC of a 280 MiB table returned from dropTable in 0.10s. The one exception is a materialized view with an inner table: DatabaseAtomic::dropTable calls dropInnerTableIfAny(sync, ...), which issues a nested sync DROP and does wait inside dropTable.
Third, the reason I would not move them even so: checkTableCanBeRemovedOrRenamedUnlocked does not filter dependents by existence. Measured with no code change, a plain DETACH TABLE usesdict leaves its edge behind, and DROP DICTIONARY dict1 is then refused with Code: 630 ... because some tables depend on it: e1.usesdict, naming a table that is no longer in the catalog. Moving the removal after dropTable creates that same state between the two statements, so it trades a rare wrong-allow for a wrong-refuse, and if the moved call throws the edge leaks until the next restart.
Fourth, the restore fits the existing API exactly: removeDependencies already returns the three vectors, DatabaseCatalog::addDependencies(const StorageID &, const std::vector<StorageID> &, ...) takes exactly those, and DatabaseCatalog.cpp already uses a restore-on-failure idiom around line 1975. It needs an explicit catch (...) { restore; throw; } rather than a SCOPE_EXIT, since a restore that throws while unwinding would terminate.
One note on severity, because it is not symmetric with the named-collection edge: loading_dependencies is rebuilt from metadata at startup, so after a restart the edge is back, DROP TABLE src is refused again and the server starts normally. The named-collection case is worse only because the lost edge lets DROP NAMED COLLECTION delete the collection file from disk. The generic ordering is also pre-existing: master has that line in the same place, and a build carrying master's ordering behaves identically on the arm above.
I will add the try/catch here since it is the same function.
There was a problem hiding this comment.
Pushed as 3785209. The saved edges are restored in a catch (...) wrapping the failpoint and dropTable, and the regression test gained a dictionary arm that fails without it: on the previous head DROP TABLE t_dep_src returns success instead of HAVE_DEPENDENT_OBJECTS, then UNKNOWN_TABLE because the source is gone. Both halves live in one test file so that two tests cannot consume each other's ONCE failpoint, hence the rename.
Two limits are in the description rather than fixed here, both pre-existing and measured identical with and without this change: a materialized view is unsubscribed by flushAndShutdown before the edges are captured, so a failed drop leaves it disconnected until a restart; and a concurrent drop of the dependency inside the window can still remove it, leaving the restore to re-add a stale edge.
The `Kind::Drop` branch removed the table's `DatabaseCatalog` dependency edges before `database->dropTable`. If anything inside `dropTable` throws, the table keeps its on-disk metadata while its edges are gone, so a table it depends on can then be dropped even though `check_table_dependencies` is on by default. Reproduced with a dictionary, which is what registers a loading dependency: with `dict1` sourced from `src`, `DROP TABLE src` is refused with `HAVE_DEPENDENT_OBJECTS`, and after `DROP DICTIONARY dict1` throws in that window the dictionary is still present, its edge is gone, and `DROP TABLE src` succeeds and destroys the source of a live dictionary. A materialized view is not enough: materialized views, plain views, `Merge` and `Distributed` register nothing in `loading_dependencies`, which is the graph the default check reads. The edges are restored on the exception path rather than removed after `dropTable`, because `checkTableCanBeRemovedOrRenamedUnlocked` does not filter dependents by existence: holding them across `dropTable` would refuse a concurrent drop of the dependency while naming a table no longer in the catalog, and would leak them until the next restart if the moved call threw. An explicit `catch` is used rather than a scope guard because a restore that threw while unwinding would terminate. If `dropTable` throws after the metadata rename the restore leaves stale edges until the next start, which is the safe direction: a wrong refusal is recoverable, a wrong permission destroys data. Unlike the named-collection dependency this one is rebuilt from metadata at startup, so losing it never prevents the server from starting. The regression test covers both halves in one file so that two tests cannot consume each other's `ONCE` failpoint; it is renamed accordingly.
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, 22 s compile time in total, 9 of them have a recent master baseline. |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Stress test (amd_msan) / Logical error: The metadata stream of AlignStreams ended before all data stream rows were matched (STID 0250-329b) |
trunk logical error in the streaming read plan, aborting the server at src/Storages/MergeTree/Streaming/ReadingPlan/AlignStreams.cpp:333 from AlignStreamsProcessor::work. The signature first appears 2026-08-26 and measures 14 CIDB rows over 14 distinct PRs, so it is not specific to this branch, which touches nothing under src/Storages/MergeTree/Streaming |
fixing PR #116531 (external, open) |
The two Bugfix validation (functional tests, amd64/aarch64) FAIL rows for
04318_remote_storage_engine_access are not failures. They carry check_status = success, the
documented inversion where this PR's regression test is expected to fail against the master binary,
which is the proof the bug reproduces.
Session id: cron:our-pr-ci-monitor:20260828-033000
…cy-until-metadata-gone The only conflict is in `04318_remote_storage_engine_access.sh`, and it is resolved by taking master's side whole. This branch pinned that test's `DROP TABLE` with `SETTINGS ignore_drop_queries_probability = 0, ast_fuzzer_runs = 0` and then asserted the table was gone before the collection was dropped. Since then `e71a2e2ff65d7` landed the same protection on master as `SET ast_fuzzer_any_query = 0`, which covers the fuzzed `DETACH` that was the only channel able to strand the collection reference: a `DROP` skipped or rewritten by `ignore_drop_queries_probability` returns before `removeDependencies`, so the table keeps its edge and the following `DROP NAMED COLLECTION` is refused rather than stranding anything. Keeping this branch's version would therefore re-add an `ignore_drop_queries_probability` pin that master no longer uses (ClickHouse#113117 removed the carriers) for a channel master already covers, so the whole hunk goes, and the two `.reference` lines that only existed for its assertion go with it. `04318` is now byte-identical to master and drops out of this pull request. The source fix and `05045_drop_table_keeps_dependencies_on_error` are unchanged; the failpoint entry re-applied on top of master's current `FailPoint.cpp` list without displacing any of the entries added upstream since this branch was cut. Co-Authored-By: Claude Opus 5 <[email protected]>
DROP TABLE now prunes the collection edge only after database->dropTable has removed the table metadata, so a throw inside NamedCollectionFactory::removeDependencies can no longer be undone: the drop has already committed, and an exception there would report a failure for a table that is gone. The name-based branch (non-Atomic databases: Ordinary, persistent MySQL, persistent PostgreSQL) had two allocation sites on that path, either of which can throw under memory pressure: a std::vector of the iterators to erase after the scan, and a lookup key that copied both name strings. Erasing in place while walking the range, keyed by a tuple of references, removes both. boost::multi_index invalidates only the erased element's iterator, so the range's end survives the loop; the library's own erase(first, last) is written the same way. 03822_named_collection_drop_dependency_check asserted the erase with a DROP NAMED COLLECTION issued after the DROP TABLE, which passes even when the edge is left behind, because InterpreterDropNamedCollectionQuery prunes edges whose dependent table no longer exists. Recreating the table name before that assertion makes it bite: with the erase disabled the test fails with NAMED_COLLECTION_IS_USED, and it passes both with the previous implementation and with this one. Co-Authored-By: Claude Opus 5 <[email protected]>
| } | ||
| /// Only once the metadata is gone: a `dropTable` that throws leaves the table on disk, and it | ||
| /// is attached again at the next start, so it must keep blocking `DROP NAMED COLLECTION`. | ||
| NamedCollectionFactory::instance().removeDependencies(table_id); |
There was a problem hiding this comment.
database->dropTable is not a pure "metadata still survives" step on non-Atomic engines. DatabaseOnDisk::dropTable can still throw after replaceFile has already moved the metadata out of the live name and detached the table (src/Databases/DatabaseOnDisk.cpp:400-429), for example from the removeRecursive / removeFileIfExists cleanup at the end.
When that happens this line is skipped even though the old table name is already gone, so the name-based named-collection edge survives. Recreating the same Ordinary table name then makes DROP NAMED COLLECTION fail for a table that no longer uses the collection, which is the same stale-edge shape 03822_named_collection_drop_dependency_check.sh now checks on the success path.
Can we either make DatabaseOnDisk::dropTable non-throwing once the metadata rename has committed, or let the caller distinguish post-commit exceptions so NamedCollectionFactory::removeDependencies still runs after the old name is irreversibly gone?
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Stress test (arm_asan_ubsan, s3) / Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected 2, found 1 (STID 2270-38be) |
trunk logical error that aborts the server on a chunk whose port header is k UInt64, s AggregateFunction(countResample(10, 5, 1), UInt64, UInt64): an empty -Resample range serializes to a zero-byte state, the reader returns 0 rows for it and StorageLog then drops the column, so a 1-column chunk reaches a 2-column port. First seen 2026-09-13 20:20Z and since measured on unrelated branches and once on true master, so it is not specific to this branch. Tracker: issue #119727 |
fixing PR #119728 (mine, open) |
| Sync | - | CH Inc sync (private, not actionable by me) |
The two Bugfix validation (functional tests, amd64/aarch64) FAIL rows for
03822_named_collection_drop_dependency_check are not failures. They carry
check_status = success, the documented inversion where this PR's regression test is expected to
fail against the master binary, which is the proof the bug reproduces.
Session id: cron:our-pr-ci-monitor:20260914-203131
|
Dear @evillique, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
The test arms the drop_table_fail_before_metadata_drop fail point, and the failpoint_tests_are_isolated style rule (67965ab) now requires every stateless test that enables a fail point to be tagged both no-parallel and no-fasttest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| { | ||
| /// The table keeps its metadata and is attached again at the next start, so it must keep its | ||
| /// dependencies: without them a table it depends on can be dropped while it still needs it. | ||
| DatabaseCatalog::instance().addDependencies(table_id, removed_ref_deps, removed_loading_deps, removed_view_deps); |
There was a problem hiding this comment.
This catch assumes every database->dropTable exception means the table is still alive, but DatabaseOnDisk::dropTable can also throw after the old name is already gone: its removeRecursive / removeFileIfExists cleanup at src/Databases/DatabaseOnDisk.cpp:426-429 runs after the metadata has been renamed out of the live path and after the table is detached from the database.
On that post-commit path, re-adding removed_*_deps resurrects a table that no longer exists in the DatabaseCatalog dependency graphs, so the next DROP TABLE of one of its dependencies is wrongly rejected with HAVE_DEPENDENT_OBJECTS until restart. Can we split dropTable exceptions into rolled-back vs committed, or make the post-rename cleanup non-throwing, before restoring dependencies here?
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…med-collection-dependency-until-metadata-gone Co-Authored-By: Claude Opus 5.5 <[email protected]>
…med-collection-dependency-until-metadata-gone
Related: #115378 (comment)
Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115378&sha=ddf8970d88156a2099f64ac83a7eab96b19f6674&name_0=PR&name_1=Stress%20test%20(arm_tsan)
Related: #112805
Related: #110529
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
DROP TABLEthat fails partway leaving what it depended on unprotected: a followingDROP NAMED COLLECTIONwas wrongly allowed and the server then failed to start, and a table the dropped one depended on could be removed even withcheck_table_dependenciesenabled.Description
Found in a
Stress test (arm_tsan)Cannot start clickhouse-serverfailure. TheKind::Dropbranch released the table's dependencies beforedatabase->dropTable, so adropTablethat throws left the table on disk with its dependencies gone. No fault injection is needed:DatabaseAtomic::dropTableImpl'stxn->commitcan throw on a Keeper session expiry before the local rename. Two dependencies are affected, both fixed here.The named collection: the next
DROP NAMED COLLECTIONwas wrongly allowed, the collection was deleted from disk, and every later start failed to attach the surviving table. That erase now runs afterdropTable, and its name-based branch is allocation-free so it cannot throw there.The
DatabaseCatalogedges, raised in review: a table the dropped one depended on could be removed even withcheck_table_dependenciesenabled, reproduced with a dictionary. These are restored on the exception path rather than moved, becausecheckTableCanBeRemovedOrRenamedUnlockeddoes not filter dependents by existence: holding them acrossdropTablewould refuse a concurrent drop while naming a table no longer in the catalog.A
ONCEfailpoint at the vacated position pins both orderings.04318_remote_storage_engine_accessis untouched now: master hardened it itself.This does not fix the failure I was asked to look at: that is the detached-table variant, which #112805 already fixes along with the permanent-
Detachreorder. It inserts a line between the two statements this PR reorders, so a trivial conflict is expected.Not addressed, all pre-existing and none affecting the next start: a materialized view is unsubscribed by
flushAndShutdownbefore the dependencies are captured, so a failed drop leaves it disconnected until a restart (measured identical without this change); a concurrent drop inside the window can still remove a dependency, leaving a stale edge;dropTableFinallyre-registering from the background drop;lazy_load_tables = 1; andStorageMongoDB.Workflow [PR]
Sync PR [sync-upstream/pr/116768]
Workflow [PR]
Sync PR [sync-upstream/pr/116768]