Repository navigation
Do not leave metadata referencing a dropped named collection - #115326
PedroTadim merged 2 commits into
Conversation
… stress restart Three stateless tests briefly leave table metadata on disk that references a named collection which no longer exists. SQL normally forbids that state: check_named_collection_dependencies defaults to true and the DROP is refused with NAMED_COLLECTION_IS_USED, so each of these tests reaches it only by opting out of the guard or by leaving its setup and teardown drops unordered. Under the stress test the server is killed and restarted at arbitrary points, and the runner randomizes async_load_databases=false. In that mode loadMetadata waits every table load job and AsyncLoader::wait rethrows, which Server.cpp rethrows in turn, so a restart landing inside the window means the server cannot boot: Caught exception while loading metadata: Code: 722 ... Code: 695 ... Code: 669 ... There is no named collection `nc_missing_sk_test_3`: Cannot attach table ... ENGINE = Remote(nc_missing_sk_test_3, ...) The check then goes red on a PR whose diff cannot touch named collections. Measured over 30 days: 16 occurrences across 14 pull requests and 2 master runs, all of them Stress test jobs. 04512 now detaches PERMANENTLY. detachTablePermanently writes a marker file that loadTablesMetadata skips before constructing any storage, while the .sql definition survives and a short ATTACH still replays it, and the marker is removed only after a successful attach. So every statement and every assertion of the two affected arms is unchanged and the reference file is untouched, yet a restart at any point inside an arm boots cleanly. 04320 and 04327 adopt both halves of the pattern already used by 04626_s3_base_setting.sh: create the collection before dropping a possible leftover table, so a leftover collection is reused rather than dropped while a leftover table still references it, and chain the two teardown drops so the collection outlives the table. Server startup behaviour is not changed here, so the underlying gap remains. It was reported in ClickHouse#77366 and closed in favour of a drop-side dependency guard, ClickHouse#96181, which ClickHouse#112805 is extending to detached tables. Related: ClickHouse#77366 Related: ClickHouse#112805
Each states the same invariant in one sentence instead of three lines. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model reviewAn independent model reviewed this change cold, and I adjudicated its findings against the code and
On 3. Every one of the 16 occurrences in the last 30 days names the collection that caused it, and
The remaining scope is disclosed rather than claimed complete - a broader setup-ordering class exists and On 4. The repro is deterministic, not a stress coin flip: the restart is injected exactly where the The boundary-injection run requested already exists. Arm (a) is replayed from an empty data directory to On the specific worry that The finding is right that a stateless test cannot restart a server, so no reference file can carry a Binary identity was asserted for every measurement, and the three tests plus Session id: cron:clickhouse-review-slot-48:20260818-160900 |
|
Workflow [PR], commit [fa341ec] Summary: ✅ AI ReviewSummaryThis PR hardens three stateless tests so they no longer drop a named collection before the referring table is safely gone, which is the right direction for the files it touches. I did not find a bug in the modified lines themselves, but the CI-fix contract is still incomplete: an unmodified sibling Findings
Final VerdictChanges requested. |
Pre-PR validation gate
Mutation check: each change reverted one at a time. Reverting Negative control: pointing an arm at a collection that still exists makes it fail, so the arms are not Randomized runs: 200/200 passed over the three changed tests plus |
|
cc @pamarcos, could you review this? It is a test-only change: three stateless tests briefly left table metadata on disk referencing a named collection they had already dropped, which aborts startup under the stress test when async_load_databases is randomized to false, so 04512 now detaches PERMANENTLY (startup skips such a table without constructing its storage) and the other two create the collection before dropping a leftover table and chain their teardown drops. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
7a6c38d
…the CI randomizers The test deliberately holds a URL table whose named collection has been dropped, since that is the property it asserts with check_named_collection_dependencies = false. Under the stress profile the CI randomizers turn that deliberate window into persisted metadata that the next server start cannot load, so the job dies at boot with NAMED_COLLECTION_DOESNT_EXIST wrapped in 695/722. It shows up as "Cannot start clickhouse-server", never as a failure of the test itself. Three randomizers reach that state. QueryFuzzer::fuzzCreateQuery renames a cloned CREATE TABLE without inspecting the engine arguments, so a bare identifier first argument (the named-collection form) is copied verbatim into a __fuzz_N sibling; the test cleans up only its own table name, and the server-side fuzzer has no clone cleanup at all (getDropQueriesForFuzzedTables is only reachable from the client fuzzer). ignore_drop_queries_probability = 0.2 can rewrite a cleanup DROP into a TRUNCATE that URL does not support. The random query killer can SIGTERM the client between two statements of the same block, so no cleanup ordering inside a block is safe. The first incarnation, the only one inside the guard-disabled window, moves into a Memory database, whose table metadata is never written, so no restart can replay it. It is removed with DROP DATABASE, which the drop injector excludes, so it needs no pin. The second incarnation stays in the Atomic database and keeps the RENAME and EXCHANGE arms unchanged, since DatabaseMemory does not implement renameTable. ast_fuzzer_runs = 0 is pinned on the four blocks that create a URL table, ignore_drop_queries_probability = 0 on the drops the test depends on, and the setup cleanup now removes leftover tables and databases before the collection. The ten serverError NAMED_COLLECTION_IS_USED assertions are unchanged, and each was confirmed to still fire individually. Each pinned item was shown load-bearing on its own: omitting any one of them reproduces the boot failure. Related: ClickHouse#115326
Related: #77366
Related: #112805
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Three stateless tests briefly leave table metadata on disk referencing a named collection that no longer
exists. The stress test kills and restarts the server at arbitrary points and randomizes
async_load_databases=false; in that modeloadMetadatawaits every table load job and rethrows, so theserver cannot boot:
Measured: 16 occurrences across 13 PRs and 2 master runs in 30 days.
Changes, copying the pattern already in
04626_s3_base_setting.sh:04512_remote_missing_named_collection.shdetachesPERMANENTLY. Startup skips a permanentlydetached table without constructing its storage, while
ATTACH TABLEstill replays the on-diskdefinition, so every assertion is unchanged and the
.referencefile is untouched.04320_url_engine_dispatch_partition_and_format.shand04327_s3queue_server_credentials.shcreatethe collection before dropping a possible leftover table, and chain the two teardown drops so the
collection outlives the table.
Validation. A restart injected where the stress kill lands reproduces the abort deterministically on
master and boots cleanly with the change; restarting at every statement boundary of the changed regions
shows two boundaries dying before and none after. Each change was reverted one at a time and each
reverted half reddens on its own oracle, and pointing an arm at a live collection makes it fail, so the
arms are not vacuous. 200/200 randomized runs of these tests plus
04626pass.Server startup behaviour is unchanged, so the underlying gap remains: dropping a collection while a
dependent table is detached still leaves an unstartable server when
async_load_databases = 0. That wasreported in #77366 and closed in favour of a drop-side guard (#96181), which #112805 is extending to
detached tables.
Tests only: no setting, default or serialization change, so no
SettingsChangesHistory.cppentry.Workflow [PR]
Sync PR [sync-upstream/pr/115326]
Version info
26.8.1.1687(included in26.8and later)