Repository navigation
Conversation
|
cc @kssenii @Algunenano could you review this? On ATTACH/startup the URL engine resolves its named collection eagerly, so a named collection dropped with check_named_collection_dependencies=false makes a dependent URL table abort synchronous server startup (NAMED_COLLECTION_DOESNT_EXIST -> Cannot start clickhouse-server, the 03822 stress failure from #105045). This defers URL named-collection resolution to the first query on ATTACH, so the table attaches and the error surfaces at query time instead of at startup. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260715-092300 |
|
Workflow [PR], commit [aea6de7] Summary: ❌
AI ReviewSummaryThis PR fixes the startup/ Final Verdict
LLVM Coverage ReportMeasured on commit aea6de7.
Changed lines: Changed C/C++ lines covered: 156/210 (74.29%) · Uncovered code |
|
Reworked (52fd292). The in-place deferred New approach defers the whole construction instead of just the Addresses all three:
Regression test extended to cover all three cases plus DROP-while-deferred ( |
|
Reverted the tryGetNested()-returns-nullptr shortcut in StorageTableProxy checkTableCanBeDropped / checkTableSizeBelowDropLimit back to master (9c0225f). You are right that this silently turned "cannot materialize" into "safe to drop": it bypassed max_table_size_to_drop for lazy MergeTree and, for a deferred URL(nc) that dispatches to StorageObjectStorage, let DatabaseOnDisk remove only local metadata while StorageObjectStorage::drop never ran, leaking remote objects. Since the URL lives inside the missing collection, the backend is unknown while the collection is missing, so no subset of drops (e.g. plain-HTTP-only) can be safely allowed. DROP now propagates NAMED_COLLECTION_DOESNT_EXIST until the collection is recreated, then drops normally through the real backend. Added a regression covering both (DROP while missing surfaces the error; DROP after recreate succeeds). The startup-abort fix and its other regressions are unchanged. |
|
Fixed in 0990454. The deferred
DROP while the collection is missing is now allowed (metadata-only), matching the plain Test 04540 extended with RENAME (succeeds, metadata-only) and TRUNCATE (NOT_IMPLEMENTED) while the collection is missing; the DROP-while-missing case now asserts success. |
|
Added the remaining URL-specific overrides on
Change is confined to 04540 extended: |
|
Addressed the create_query staleness and dependency-graph gaps (169004c).
Test 04540 extended: comment survives materialization; |
|
Fixed in 7546f80. `StorageDeferredURL` now overrides `drop()` to not materialize while unmaterialized (forwards to the nested storage once materialized). A URL table drop is metadata-only (plain URL/File/object-storage backends have a no-op `drop()`, external objects are never deleted), so nothing needs the nested storage. This stops the resurrected `getConfiguration(..., ¤t_id)` re-registration for a table being dropped, which in an Ordinary DB left a stale name-based dependency that made a later unrelated same-named table trip `NAMED_COLLECTION_IS_USED`. Regression added to 04540 (drop deferred table, recreate an unrelated same-named table, DROP NAMED COLLECTION must succeed). |
|
Both addressed in 6c4ee72.
04540 extended with both cases. |
|
Flaky-check FAIL on amd_asan_ubsan (test runs too long, >180s) fixed in 49738e8: tagged 04540 |
|
Fixed in 034c324. Regression added to 04540: attach a deferred |
|
I could not reproduce this and I do not think the gate is reachable here, so I have not made a change.
Because a deferred If you have a concrete query that reaches the gate through an attached deferred |
CI finish ledger — 034c324All checks green on this head. No failures.
Session id: cron:our-pr-ci-monitor:20260716-090000 |
…ssing A URL table whose named collection was dropped with check_named_collection_dependencies=false used to abort synchronous server startup with NAMED_COLLECTION_DOESNT_EXIST because the URL engine resolves its named collection eagerly on ATTACH. Defer the resolution behind a lazy StorageDeferredURL proxy (based on StorageTableProxy) so a missing named collection no longer prevents startup; the real StorageURL is materialized on first use once the collection exists. The proxy preserves the eager URL storage contract: DDL semantics (CREATE/ALTER metadata-only path, planner contract), DROP safety for unresolvable tables, named-collection dependency tracking at attach time, up-front URL virtual columns, and table-level constraints and comment seeded into the cached metadata. Adds regression test 04540_url_named_collection_missing_on_attach (tagged long to stay under the flaky-check time limit). Co-Authored-By: Claude Opus 4.8 <[email protected]>
034c324 to
d35585d
Compare
Resolution of the
|
|
@alexey-milovidov you are the only one who can review this |
One conflict, in the `URL` storage creator registered by `registerStorageURL`. Master added `checkStorageSettingNames(args)` as the creator's first statement (SETTINGS-name rejection for File/URL/S3/Log), directly above the scheme dispatch. This branch had moved that dispatch, with the rest of the creator body, into `createStorageURLImpl` so the lambda can wrap the whole construction in the deferral for a missing named collection. Resolved by keeping master's check as the first statement of the lambda, ahead of the deferral decision, so the resulting order is the same as master's: validate the SETTINGS names, then dispatch by scheme (now reached through `createStorageURLImpl`, which both the eager and the deferred-retry branch call). Putting it inside `createStorageURLImpl` instead would have re-run it on every materialization attempt of a deferred table. Verified after resolution that `createStorageURLImpl`'s body is line-for-line master's creator body, so none of master's edits to that code were lost to the move, and that the net diff against master is still exactly this PR's 8 files with no submodule gitlink drift.
Two things this branch relied on changed under it while it was stale. `IStorage::alter` gained a `DDLGuardPtr & ddl_guard` parameter, so the deferred proxy's three-parameter override no longer overrode anything and did not compile. Forward the new parameter to both bases; a proxy has nothing of its own to do with the guard. `system.tables` now asks every row whether it is a data lake (StorageSystemTables.cpp:945), unconditionally rather than inside the total_rows and total_bytes column branches it used to be gated behind. isDataLake answered by materializing, so a catalog sweep over a table whose named collection is missing reported that absence instead of a row: SELECT comment FROM system.tables and SELECT metadata_version FROM system.tables both failed with NAMED_COLLECTION_DOESNT_EXIST, and 04540 caught it. Answer isDataLake from the proxy while the delegate is absent. It is the only one of the four classifications a catalog sweep reads -- system.tables is the sole caller outside InterpreterInsertQuery -- and false is also the delegate's answer, because no engine a URL can dispatch to (URL, File, S3, AzureBlobStorage, HDFS) carries a data lake configuration; isDataLakeConfiguration is false outside DataLakeConfiguration. The other three keep materializing. They are reached only by the disable_insertion_and_mutation guard, which runs before the write that would materialize anyway, and which engine serves a URL depends on the resolved URL, so the delegate has to answer: an s3:// collection must be exempted as object storage. Suppressing the missing-collection error here instead would have cost the promise the deferred creator makes, that first use surfaces the real resolution error -- measured, that insert reported QUERY_IS_PROHIBITED rather than the missing collection. Measured with the Build IDs asserted against SELECT buildId(). Without this commit 04540 fails on three hunks with Code: 669; with it 04540 passes byte-exact, the sweep over the unresolved table returns its row with zero materializations in the server log, and the same insert reports Code: 669 while the collection is missing and consults the delegate once it is recreated. Separately, a real restart with the collection's metadata file deleted brings the server up with no "Cannot attach table", keeps the table catalogued as URL, and still reports Code: 669 when the table is read.
The deferral predicate was written to mirror StorageDistributed, which answers the same question: is this definition being introduced now, or replayed from metadata this server already stored? Master has since added a third term to that predicate at every site carrying it, because one replay route is invisible to the other two. DatabaseReplicated::recoverLostReplica and SYSTEM RESTORE DATABASE REPLICA re-execute the CREATE statement stored in Keeper. parseQueryFromMetadata sets create.attach = false, so the replay arrives below LoadingStrictnessLevel::ATTACH with no short syntax: both existing terms are false and it is indistinguishable from a user CREATE by mode alone. Context::isRecoveryFromStoredMetadata carries the provenance instead. Without the third term a URL table whose named collection is absent fails its own stored definition during recovery, which is the failure this PR exists to prevent, one level up: the replica rejects its own metadata and retries forever rather than deferring and recovering. StorageDistributed.cpp:2702, StorageFactory.cpp:66 and registerStorageMergeTree.cpp:590 all consult it for the same reason.
The stress profile sets ast_fuzzer_runs=5 (ci/jobs/scripts/fuzzer/query-fuzzer-tweaks-users.xml), so the server re-runs a mutated copy of every statement. This test repeatedly creates tables and then drops the named collections they reference, which is exactly the shape where a fuzzed CREATE or DROP leaves a table behind that references a collection the test then drops: the assertions stop being deterministic and the run can strand metadata that no later test can load. The sibling 03822_named_collection_drop_dependency_check pins ast_fuzzer_runs = 0 in three blocks for this reason. Every query here goes through $CLICKHOUSE_CLIENT, so pin it once on the variable rather than in 29 separate settings blocks.
The deferral predicate's comment and the isDataLake comment both restated their commit messages. Keep the properties a reader cannot derive from the code -- that only a replayed definition may defer, that a Replicated replay is invisible to `mode` alone, that `system.tables` reads the classification per row, and that no engine a `URL` dispatches to carries a data lake configuration -- and drop the retelling. Comments only: the comment-stripped file is byte-identical.
AlterCommands::validate reads supportsTTL and supportsStatistics on the storage the ALTER is addressed to, and it runs before checkAlterIsPossible (InterpreterAlterQuery.cpp:366 vs :373). StorageDeferredURL inherited both from StorageProxy, which forwards through getNested(), so ALTER ... MODIFY TTL and ALTER ... ADD COLUMN c UInt64 STATISTICS(...) on an attached-but-unresolved URL(named_collection) table reported NAMED_COLLECTION_DOESNT_EXIST instead of the plain URL engine's own refusal. Same class as the AlterPartition and CHECK TABLE overrides already on this branch: unsupported DDL must not depend on whether the named collection happens to exist. Answering both from the proxy while unmaterialized restores the eager path's errors byte for byte (BAD_ARGUMENTS "Engine URL doesn't support TTL clause", NOT_IMPLEMENTED "Engine URL doesn't support statistics"), and the table stays unmaterialized: SELECT still reports the missing collection. These two are the complete set for that function; every other storage predicate validate() consults is either already non-materializing here or a cast on the proxy itself. No engine a URL dispatches to supports TTL or statistics, so false is also the delegate's answer once materialized. statistics needs allow_statistics = 1 to reach the gate, since validate() rejects statistics with INCORRECT_QUERY first when the setting is off; the new test row sets it. Also trims the comment above overrideURLInEngineArgs from 15 lines to 4, dropping the url_base illustration and the cross-file policy citation while keeping why the AST copy skips userinfo (credential exposure through SHOW CREATE TABLE) and why the object storage uses a scratch copy. Comment-only, no code change in that hunk.
Build profile diff (arm_release)Comparing commit See the job log for details. |
CI finish ledger - 99aaca7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Evidence for the 5/6 owner, since a bare count of "10 errors" hides which test failed: the shard's Session id: cron:our-pr-ci-monitor:20260920-030238 |
CI finish ledger - 4367182Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates: (a) 0 of 176 checks queued or running (155 pass, 15 skipped, 6 red); (b) Session id: cron:our-pr-ci-monitor:20260920-140257 |
|
@groeneai is this PR still needed? |
|
Yes, the defect is live, but I would not keep this PR as the carrier. Remeasured on a debug build of master at
What has expired is the CI reason this PR was opened for: the stranded-metadata windows were closed test-side (#115326, #118504, plus the 03822 restart-safety commits), and CIDB has no master failure in the last 30 days for That half is better served by #120734: 265 lines, all engines, in the What only this PR adds, for So: close this one and keep #120734, if you agree. I have not closed it myself because alexey-milovidov merged master into this branch yesterday. The database-level variant is a separate layer, open as #115049. |
Related: #105045
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the server failing to start (
Cannot start clickhouse-server) when aURLtable references a named collection that no longer exists. A collection can be legitimately dropped while a dependentURLtable exists (withcheck_named_collection_dependencies = false), and theATTACHreplayed at startup then threwNAMED_COLLECTION_DOESNT_EXIST. The table now attaches and the error is reported at query time.Description
Reported on #105045 but unrelated to it:
Stress teston03822_named_collection_drop_dependency_checkfails to restart the server, withATTACH TABLE ... ENGINE = URL(...)hittingNAMED_COLLECTION_DOESNT_EXIST. Reproduces on master.Root cause: the
URLengine resolves its named collection eagerly at attach time(
StorageURL::getConfiguration), butcheck_named_collection_dependencies = falselets acollection be dropped while dependent
URLtables exist. The persistedATTACHreplayed at startupthen aborts the server under synchronous loading.
Fix: when replaying a definition stored on this server, a missing collection attaches a lazy proxy
instead of aborting; it is re-resolved on first read/write, and if still missing the query fails
NAMED_COLLECTION_DOESNT_EXIST. A definition the user supplies now (CREATE, full-definitionATTACH,RESTORE, Replicated DDL) still fails its own DDL instead of persisting an unusabletable, gated on the predicate
StorageDistributeduses.Also fixed while under review, every case where
StorageProxyanswers throughgetNested()(whichmaterializes), so the proxy reported the missing collection where eager
URLanswers directly:the engine classification (
isObjectStorage/isDataLake/isMessageQueue/isExternalDatabase),read by
InterpreterInsertQuerybefore the materializingwrite(), so an object-storage-backedURL(nc)was rejectedQUERY_IS_PROHIBITEDunderdisable_insertion_and_mutationwhere the eagerform inserted; and
checkAlterPartitionIsPossible,alterPartition,getCheckTaskList,getActionLock,supportsReplication,getColumnSizes, where partition DDL andCHECK TABLEreported
NAMED_COLLECTION_DOESNT_EXISTinstead ofNOT_IMPLEMENTEDand the last three are sweptover every table, so one unresolvable table made
system.tables,system.columnsand bulkSYSTEM STOP MERGESthrow.Validated in both directions with
04540_url_named_collection_missing_on_attachandtests/integration/test_disable_insertion_and_mutation, including a real restart with thecollection still missing.
S3/Azure/HDFSresolve collections in their ownfromASTpath andmay share this.
Workflow [PR]
Sync PR [sync-upstream/pr/110529]