Repository navigation
Conversation
A table whose persisted `ENGINE = <X>(<named collection>)` names a collection that no longer exists cannot be constructed when its metadata is replayed at startup: Code: 722 Waited job failed: Code: 695 Load job 'load table default.t_url' failed: Code: 669 There is no named collection `nc_url`: Cannot attach table `default`.`t_url` from metadata file store/d4c/.../t_url.sql (NAMED_COLLECTION_DOESNT_EXIST) Every engine resolves its collection inside its registration lambda, before the storage is constructed, through `tryGetNamedCollectionWithOverrides`, whose `throw_unknown_collection` defaults to true. So the exception escapes `createTableFromAST` and fails the table's load job, and a failed load job is fatal twice over: in sync mode `loadMetadata`'s `waitLoad` rethrows it out of `Server.cpp` and the boot dies, and in async mode `getTablesIterator` waits on every table's startup task, which is how `StorageSystemTables` reaches it, so one broken table fails every `system.tables` scan of its database. Measured on a pristine build of the parent commit, three server generations over one data directory: with `async_load_databases = 0`, `Ready for connections` = 0, `Caught exception while loading metadata` = 1 and every process exits; with the packaged default `async_load_databases = 1` the server starts, but `SELECT name FROM system.tables WHERE database = 'default'` fails with `ASYNC_LOAD_WAIT_FAILED`, so the user cannot list their tables to find the broken one. The second arm contradicts what `async_load_databases` documents, namely that a failed load job is rethrown to queries that access that table. Reachable in four ordinary statements, and by two routes that need no other bug: `check_named_collection_dependencies = 0` before `DROP NAMED COLLECTION`, or removing the collection's `config.d` entry, where there is no SQL `DROP` to intercept. Reported on the MySQL engine as ClickHouse#77366. Make the load job succeed instead of fail: in the existing `catch`, when the error is exactly `NAMED_COLLECTION_DOESNT_EXIST`, attach the lazy stand-in that a `lazy_load_tables` database already uses. The table is listed with `engine = 'TableProxy'`, reading it raises the real error, and recreating the collection makes it work with no restart. `registerStorageMergeTree.cpp` already takes this shape one level deeper, skipping a projection that names a dropped dictionary or missing object rather than refusing to start. The catch runs in the frame that called the throwing constructor, so `e.code()` is still live and nothing has to be recovered from a flattened message; and because the job no longer fails, neither the sync-mode nor the async-mode contract is altered. The gate is `mode == FORCE_ATTACH`, not `isLoadingFromExistingMetadata`. Ordinary metadata replay runs at exactly `FORCE_ATTACH`, while a user `CREATE` or `ATTACH TABLE` runs at `mode <= ATTACH` and still fails immediately. `FORCE_RESTORE` is excluded deliberately: `force_restore_data` is one-shot and deleted during the boot, whereas `loadTableLazy` captures `mode` and materializes at an arbitrary later time, so a stand-in born in a force-restore boot would keep skipping sanity thresholds long after the flag was gone. Under force-restore the boot therefore still aborts. `shouldLazyLoad`'s body becomes `canUseLazyStandIn` so both paths share one predicate and cannot drift; `shouldLazyLoad` is now that predicate plus its `lazy_load_tables` check, so the lazy-load path is unchanged by construction. This inherits its exclusions, and one of them costs coverage on purpose: a push source that feeds a materialized view still aborts the boot, because a stand-in never calls `startup` and nothing reads a source table, so ingestion would stall silently even after the collection came back. With no dependent view such a table is covered. Not a blanket swallow: a `MergeTree` table naming a storage policy that no longer exists still aborts the boot identically, `Code: 478 UNKNOWN_POLICY`. Related: ClickHouse#77366 Co-Authored-By: Claude Opus 5 <[email protected]>
The stateless test covers the arm that needs no server: `clickhouse local` replays the metadata of its `--path` through the same loader, so re-entering it on one directory is a restart. On the parent commit the second invocation fails with `Code: 722 ... ASYNC_LOAD_WAIT_FAILED` instead of listing the table. Its third assertion is anchored on the first line of the error rather than grepping for the error name anywhere in the output. The unanchored form passes on the parent commit too, because the wrapped `722 -> 695 -> 669` chain contains that name as well; what the fix changes is that the collection error is reported directly instead of inside a failed load job, and only a line-anchored match can see the difference. The integration test covers the default `async_load_databases` and the route that has no SQL `DROP` to intercept: a collection defined in `config.d`, a table created against it, the entry removed, and a real server restart. It reuses the file's existing `with_replace_config` fixture rather than adding one. Restoring the collection before dropping the table is not just cleanup. Dropping a table whose collection is still missing materializes the stand-in, through `StorageTableProxy::checkTableCanBeDropped`, and so raises the same error; putting the collection back first both removes the table and asserts that the table recovers without another restart. On the parent commit that `DROP` fails as well, and keeps failing even after the collection is recreated, because the failed load job is cached for the life of the process. Co-Authored-By: Claude Opus 5 <[email protected]>
…t be built Handing a table whose storage cannot be constructed a `StorageTableProxy` stand-in is the first thing in the tree that creates a proxy whose materialization is guaranteed to throw. Every consumer that ships today only ever meets a proxy that materializes successfully, so "handles a proxy" and "tolerates a proxy that cannot be built" turned out to be different properties, and three consumers had only the first one. `system.tables` reached the storage twice without a guard: `data_paths` via `tryGetDataPaths()` and `metadata_version` via `supportsReplication()`, both routed through `StorageProxy::getNested()`. `metadata_snapshot` is non-null for a stand-in, since `StorageTableProxy` returns its cached metadata, so the `&&` did not short-circuit. A whole-server `SELECT * FROM system.tables` therefore aborted on the first such table, not merely the row for it. `system.columns` reached it once, through `tryGetColumnSizes()`. Leaving the sizes empty is already a supported state: the per-column fill takes its `insertDefault()` branch when a name is absent, which is what a `URL` table produces anyway. `DatabaseAtomic::tryCreateSymlink` read the table's data path outside its own catch-all, and `renameTable` calls it from the `attach` lambda after the metadata move has been committed, past the point the code documents as "the following methods should not throw (if they do, it's a logical error)". So `RENAME TABLE t TO t2` returned an error for a rename that had already happened, and the user's retry then reported `UNKNOWN_TABLE` for a table that did move. `EXCHANGE TABLES a AND b` was worse: the throw landed between the two `attach` calls, leaving `b` attached to neither database in memory until the next restart. Each hunk copies an idiom already present in the function it edits, so nothing that works today changes behaviour. The guards deliberately sit in the consumers rather than in the proxy: making the proxy answer these questions without materializing would change `data_paths`, `metadata_version` and column sizes for every existing `lazy_load_tables` user, and forwarding the capability predicates would construct storages in new places. Under `FORCE_RESTORE` the startup job in `DatabaseAtomic` walks every table through this same `tryCreateSymlink`, which is the second reason the tolerance added earlier excludes `FORCE_RESTORE`, and the reason the ordinary `FORCE_ATTACH` boot was already safe. Coverage: neither shipped test would have caught the `system.tables` break, because one selected `name, engine` and the other only `name`, and `StorageTableProxy::getName()` deliberately avoids materializing. The stateless test's listing is widened to name the two previously-throwing columns and gains a `system.columns` arm; the integration test gains the rename.
The recovery arm of test_missing_collection_in_config_does_not_block_startup only asserted that reading the table no longer fails with NAMED_COLLECTION_DOESNT_EXIST. That is nearly vacuous: query_and_get_error requires the query to fail, and the restored collection deliberately points at an unreachable endpoint, so the read always fails on connection. The assertion therefore said only "the failure is not spelled NAMED_COLLECTION_DOESNT_EXIST", which passes just as well for a LOGICAL_ERROR or a stale get_nested factory. It could not distinguish a stand-in that materialized into a real URL storage from one that broke differently. The engine column of system.tables is a sufficient and cheaper oracle than standing up a reachable endpoint. It is filled from IStorage::getName(), and StorageTableProxy::getName() reports TableProxy while nested is null, then forwards to the nested storage once it is set. Because nested is only ever assigned by a getNested() call that has constructed and started the storage, engine = 'URL' is reachable only through a successful materialization, and reading the column does not itself force one. Asserting TableProxy while the collection is missing and URL after it comes back makes the pair a before/after transition, so the test now polices the contract the change claims: recreating the collection makes the table work again without a restart.
The tolerance added earlier hands a table whose named collection is missing a `StorageTableProxy` stand-in, so one dangling reference fails one table instead of the whole database load. For an engine that ingests from a background job, that stand-in is not a faithful placeholder, and unlike the `lazy_load_tables` path it now appears in databases that never opted into a stand-in at all, so two engine contracts become reachable in a default configuration. `DatabaseAtomic::renameTable` validates `checkTableCanBeRenamed` on the object the catalog holds, which is the proxy. `StorageProxy` forwards only `isRemote` and `isView`, so the inherited no-op accepts a cross-database move that `StorageObjectStorageQueue::checkTableCanBeRenamed` refuses while `keeper_path` is implicit. `chooseZooKeeperPath` derives that path from the database and table UUIDs, so once the collection came back the table would process against a different Keeper path and lose the record of what it had already consumed. `isStreamingStorage` is `final` in `IStreamingStorage` but only defaulted in `IStorage`, and neither proxy overrides that default, so both of `InterpreterSystemQuery`'s streaming paths classify a stand-in as not streaming: the ALL form skips it while collecting tables, and the per-table form authorizes and routes it as an ordinary table. `StorageProxy` does forward `getActionLock`, but that materializes the storage only after the caller has already taken the wrong branch. A materialized view created once the collection is back materializes the stand-in and starts the nested engine, and `SYSTEM STOP`/`SYSTEM CANCEL` then no longer reach an ingesting engine. Forwarding either property through the proxy would call `getNested()`, so it would materialize on every rename, change behaviour for every table that is already loaded this way, and make `RENAME TABLE` fail on a table whose collection is gone. Excluding these engines instead leaves both contracts exactly where they are today: such a table fails its own load, which under asynchronous loading is reported when the table is accessed, and on a synchronous start still refuses the start. The engine set is the one `canUseLazyStandIn` already keys on, so the two paths cannot disagree about what a push source is. The eager path there excludes such a table only once it has a dependent view, because a stand-in that is never read would stall an otherwise working pipeline; here the table's load has already failed, and the point is to keep failing it. Coverage: the integration test gains a database holding both a `Kafka` table and a `URL` table whose collections are both missing, and asserts that only the `URL` table is attached, that its own load completed, and that the `Kafka` table reports the missing collection out of a failed load job. Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the canUseLazyStandIn declaration comment (it restates the name) and the push-source line at the condition (isPushSourceEngine documents that set itself); condense the named-collection comment to the property that justifies the dangling-reference classification.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model, plus a cold pass I made before reading either the
Severity: ❌ blocker / |
|
Workflow [PR], commit [a626b23] Summary: ❌
AI ReviewSummaryThis PR teaches Findings
Tests
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit a626b23.
Changed lines: Changed C/C++ lines covered: 62/65 (95.38%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260917-234600 |
|
@groeneai this still doesn't sound like the real solution. I think the real one is that if a table has a named collection dependency, it shouldn't be dropped. This is a backward-incompatible change, but the more defensive solution |
The first run on this head produced no result: praktika's Config Workflow failed its "Check CI DB" leg because the CI database refused every request with "Code: 202. DB::Exception: Too many simultaneous queries. Maximum: 1000", so all 171 dependee jobs were set to DROPPED and no test job ran. The same leg failed the same way on unrelated pull requests over the same period, so this was a shared infrastructure event and not a property of this branch. The run is already at attempt 2, and the hourly infra-retry workflow only selects runs at attempt 1, so nothing upstream will re-dispatch it. A fresh head is the only remaining path. No code change. Co-Authored-By: Claude Opus 5 <[email protected]>
|
The refusal you describe is already open as @ alexey-milovidov's #112805: it counts detached tables as dependents, so I do not think a refusal can be the whole answer, because the collection can go missing with no
The abort is also only one of the two symptoms. With the packaged default #77366 is the same chain reported on MySQL: the drop-side guard was the fix chosen there, and the reporter had asked for this shape instead, "I think the check is so strict. Just throw exception when table used". Making the refusal unbypassable is a call for you and @ alexey-milovidov, and I will take it if you want it. If you would rather the refusal be the whole answer, say so and I will close this PR. |
| fmt::format( | ||
| "Attaching {} without its storage, so reading the table reports this instead of the server refusing to start", | ||
| name.getFullName())); | ||
| loadTableLazy(local_context, name, ast, mode); |
There was a problem hiding this comment.
Attaching the table through loadTableLazy also hands non-lazy URL/object-storage/external tables a StorageTableProxy whose insert-time capability bits are still the IStorage defaults until something else materializes it. InterpreterInsertQuery::execute reads those bits before any materializing call: the supportsPartitionBy guard runs before the first write, and the disable_insertion_and_mutation exemption branches on isObjectStorage / isExternalDatabase.
That means the PR's recovery contract is still broken on the first write after the collection is recreated. A recovered URL or S3 table will reject INSERT ... PARTITION BY with NOT_IMPLEMENTED, and on a server with disable_insertion_and_mutation even a plain insert into S3 / MySQL is rejected as if the table were local. This needs either cached capability answers on the stand-in for the insert path, or an exclusion for the affected engines until those bits can be answered without eager materialization.
There was a problem hiding this comment.
Checked both arms against the code and measured them; I am not changing the diff.
INSERT ... PARTITION BY is not reachable for a table. PARTITION BY is parsed only inside the INSERT INTO FUNCTION branch (ParserInsertQuery.cpp:110-121), the only place SQL sets ASTInsertQuery::partition_by, and when it is set getTable builds the storage from the table function (InterpreterInsertQuery.cpp:189), never from the catalog. So supportsPartitionBy() is never asked of a StorageTableProxy. Measured on this build: INSERT INTO t PARTITION BY a VALUES (1) gives Code: 62. Syntax error: failed at position 15 (PARTITION), while INSERT INTO FUNCTION file(...) PARTITION BY a SELECT 1 parses.
The disable_insertion_and_mutation arm is real, but it belongs to StorageProxy and predates this PR. Measured with no named collection anywhere and disable_insertion_and_mutation=1: an INSERT into an S3 table in a lazy_load_tables = 1 database is refused with Code: 392. Insert queries are prohibited, while the same insert into the same engine in an ordinary database passes that check and proceeds to I/O. StorageProxy does not forward isObjectStorage or isExternalDatabase, and this PR changes none of StorageProxy.h, StorageTableProxy.h, IStorage.h or InterpreterInsertQuery.cpp. #113389 and #117972 add the non-materializing accessors that answer those bits at the source; forwarding them from here would materialize storages on new paths, including on every rename.
Neither suggested remedy fits this path: at attach time there is no storage to read the capability bits from, because its collection is missing, and the "affected engines" are S3, URL, MySQL and the rest, which is every engine that takes a named collection.
On the requested test: writing through the stand-in is StorageProxy::write -> getNested(), master's code that the lazy_load_tables tests already cover, and test_missing_collection_in_config_does_not_block_startup asserts the stand-in materializes with no restart (the engine column flips from TableProxy to URL).
A design question on the whole approach is open above from @ PedroTadim, so I am leaving the diff as it is until that is settled.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units40 translation units recompiled, 348 s compile time in total, 40 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. |
CI finish ledger - a626b23Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Root cause: merged #120477 deleted six entries from Why rule 3c and not 3d, measured rather than argued: praktika tested merge commit I am deliberately not merging master to pick #120763 up on this head yet: a design ruling on Session id: cron:our-pr-ci-monitor:20260918-140155 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A table that fails to load with
NAMED_COLLECTION_DOESNT_EXIST, because itsENGINEnames a named collection that is gone, no longer stops the server from starting, and no longer makes asystem.tablesorsystem.columnsscan fail. In anAtomicdatabaseRENAME TABLEno longer reports an error for a rename that has already happened. The table is listed, reading it reports the missing collection, and recreating the collection makes the table work again without a restart. A streaming source, aforce_restore_datastart, and a table stored asAS <table function>(...)still stop as before.Description
A table whose persisted
ENGINEnames a named collection that no longer exists cannot be constructed when its metadata is replayed at startup. Withasync_load_databases = 0the server refuses to start. With the packaged defaultasync_load_databases = 1it starts, but everySELECTfromsystem.tablesfor that database fails withASYNC_LOAD_WAIT_FAILED, so the user cannot list their tables. That contradicts whatasync_load_databasesdocuments: a failed load job is rethrown only to queries accessing that table.Reachable with no other bug:
SET check_named_collection_dependencies = 0before theDROP, or removing the collection'sconfig.dentry, where there is no SQLDROPto intercept. Reported on MySQL as #77366.Root cause: an engine resolves its named collection while parsing its arguments, before the storage exists, so
NAMED_COLLECTION_DOESNT_EXISTescapescreateTableFromASTand fails the load job.Fix: in
DatabaseOrdinary::loadTableFromMetadata's existingcatch, when the error is exactlyNAMED_COLLECTION_DOESNT_EXISTand the mode isFORCE_ATTACH, log it and attach the lazy stand-in alazy_load_tablesdatabase uses.registerStorageMergeTree.cppalready does this for a projection naming a dropped object.FORCE_ATTACHis the level metadata replay uses; a userCREATEorATTACH TABLEruns below it and still fails immediately.Such a stand-in is the first storage whose materialization always throws, so three consumers needed the guard their neighbours already carry:
data_pathsandmetadata_versioninsystem.tables, column sizes insystem.columns, andDatabaseAtomic::tryCreateSymlink, whichRENAME TABLEcalls after committing the move.Related: #77366
Happy to close #110529 (
URLengine only) if you prefer this shape.Scope, residuals, validation
Reuses
shouldLazyLoad's exclusions (canUseLazyStandIn). Consequences chosen, not worked around:Kafka,S3Queue, other streaming engines) always aborts: a stand-in never callsstartup, so ingestion would stall silently, and it answers neither the engine's own rename veto nor its streaming classification.AS <table function>(<collection>), whose argumentscreateTableFromASTparses beforeStorageTableFunctionProxysees them, and bareENGINE = Remote(<collection>), which reportsCLUSTER_DOESNT_EXISTsince a lone identifier there is also a cluster name.force_restore_datathe boot still aborts: that flag is one-shot, a stand-in loads later.DROP TABLE,DROP DATABASEand a table-lessSYSTEM STOP MERGESstill fail with669: each reaches the storage. Recreating the collection orDETACH TABLE ... PERMANENTLYremoves the table; on master they fail even after it returns.RENAME TABLEin anOrdinarydatabase also still fails, by design: there the rename moves the data directory, soDatabaseOnDisk::renameTablerolls the name back itself. OnlyAtomicthrows after committing the move.addDependencyon the stand-in path, so the two compose; Fix BACKUP and access checks for lazily loaded tables that are still a proxy #117972 and Replace the proxy of a lazily loaded table with the table itself #118699 only reach an already-materialized stand-in, which this one never is, so these guards stay; Fix data loss and silent behaviour changes in databases with lazy_load_tables #113389 reworkslazy_load_tablesand the proxy accessors, fixes no named collection, and conflicts inshouldLazyLoad. Happy to rebase.A/B validated on
URL,S3and via config removal: sync boot (Ready for connections0 -> 1), asyncsystem.tables(ASYNC_LOAD_WAIT_FAILED-> listed), and a whole-catalogSELECT *from both system tables (669-> clean); two new tests that fail on master; a missing storage policy still aborts; removing the newifreturns every arm to master.Workflow [PR]
Sync PR [sync-upstream/pr/120734]