Skip to content

Stop stateless tests from stranding metadata that names a dropped named collection - #118504

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:pin-fuzzer-ddl-nc-teardown-r1
Sep 12, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:pin-fuzzer-ddl-nc-teardown-r1

Conversation

@groeneai

@groeneai groeneai commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113117

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Pin ast_fuzzer_any_query = 0 on the table DDL of six stateless tests that build a table from a SQL-created named collection, so the server-side AST fuzzer cannot leave metadata behind that names a collection the test then drops.

Description

Under the Stress profile a table can survive its own DROP TABLE while the test's DROP NAMED COLLECTION still runs. The next server start then cannot load the leftover metadata, and with async_load_databases = 0 (a coin flip in stress_runner.sh) that aborts the whole server, so CIDB records only Cannot start clickhouse-server.

Two injections combine. ignore_drop_queries_probability makes InterpreterDropQuery either ignore a DROP TABLE or rewrite it to TRUNCATE; for S3 (implements truncate) and Distributed (takes the ignore branch) the client still gets rc 0 with the table present, so an exit-code-gated teardown proceeds. ast_fuzzer_any_query then lets the fuzzer replay that DDL as a DETACH (metadata kept) or a __fuzz_N clone inheriting the collection reference. The collection drop's guard uses isTableExist, false for a detached table, so the collection goes.

Fix: pin ast_fuzzer_any_query = 0 on the invocations issuing table DDL for that table, restoring the setting's own default there only; SELECT and SHOW CREATE stay fuzzed. Merged precedent: 03822_named_collection_drop_dependency_check.sh. Commit 2 (the two Remote siblings, 0 CIDB hits) is droppable whole to land only the proven ones.

I do not pin ignore_drop_queries_probability: #113117 removed those as useless, and with it forced to 1 and the pin in place every carrier fails loudly (NAMED_COLLECTION_IS_USED, or Code: 48) instead of stranding. Both directions: with a strand on disk the server exits 210 with Caught exception while loading metadata; with the pins, 24 armed runs of all six tests leave nothing behind and it boots clean. Removing the pin strands again.

04512's remote() arms need a shard on port 9000, so it is left to this PR's CI (its pristine version fails identically here). 04626 keeps a pre-existing ~20% stress-profile failure rate from the fuzzer mutating its data-producing INSERT (base 4/50), a different invariant, left unpinned so the s3() URI path stays covered.

CIDB evidence and the three deliberately unpinned files

Signature: test_name = 'Cannot start clickhouse-server' with NAMED_COLLECTION_DOESNT_EXIST in the context.
30 days: 14 rows, 13 distinct PRs, 0 with pull_request_number = 0, every one a Stress test (*):

carrier test hits stranded object
04320_url_engine_dispatch_partition_and_format_named_collection.sh 6 the table, and __fuzz_4 clones
04626_s3_base_setting_named_collection.sh 3 the table, left detached
04512_remote_missing_named_collection.sh 3 t_engine_sk / t_engine_tf
04327_s3queue_server_credentials.sh 1 a __fuzz_4 clone
03822_named_collection_drop_dependency_check.sh 1 a __fuzz_1 clone (already pinned)

At 45 days it adds two rows with pull_request_number = 0 and head_ref = 'master' (2026-08-07
arm_msan, 2026-07-31 arm_tsan), both stranding 04320_..._n, so this is not PR-only.

The carrier list is mechanical: a candidate creates and drops a collection SQL-side and persists an
engine definition naming it via CREATE TABLE, CREATE OR REPLACE TABLE or a full-definition
ATTACH TABLE (an ASTCreateQuery writing the same metadata, so grepping for CREATE TABLE alone
misses it). Ten candidates; three are left alone, re-checked with the injections armed:

  • 04070_url_base_setting.sh, 04546_postgresql_engine_settings.sql: URL and PostgreSQL override
    neither truncate nor storesDataOnDisk, so the only reachable branch raises
    Code: 48 Truncate is not supported by storage ..., aborting the statement stream before the
    collection drop. The collection outlives the table, the safe direction.
  • 04891_nats_credential_file_path_restriction.sql: its metadata-writing statement is a full-definition
    ATTACH with an explicit UUID, so in an Atomic database a clone either collides with the live
    table's UUID or is rejected by InterpreterCreateQuery.

Workflow [PR]
Sync PR [sync-upstream/pr/118504]

Version info

  • Merged into: 26.9.1.1318 (included in 26.9 and later)

…d named collection

Under the Stress test a table can survive its own `DROP TABLE` while the test's
`DROP NAMED COLLECTION` still runs. The next server start then cannot load the
leftover metadata:

  Code: 722 Waited job failed: Code: 695 Load job 'load table test_7.test_s3_base_nc'
  failed: Code: 669 There is no named collection `nc_04626_s3_base_setting_test_7`:
  Cannot attach table `test_7`.`test_s3_base_nc` from metadata file
  store/8bc/.../test_s3_base_nc.sql (NAMED_COLLECTION_DOESNT_EXIST)
  -> server process is not running after 11 start attempts

With `async_load_databases = 0`, which `tests/docker_scripts/stress_runner.sh` sets
with probability 1/2, that failure aborts the whole server rather than just the one
table, and the entire Stress exercise for that run produces nothing: no crash
detection, no sanitizer report, no hung check. CIDB records only
`Cannot start clickhouse-server` and `Check failed`.

Four links, all three of the first ones observed in that order in the server log of
the most recent occurrence:

  L1 `ignore_drop_queries_probability = 0.2` (`ci/jobs/scripts/stress/stress.py`)
     makes `InterpreterDropQuery` replace a client `DROP TABLE` with
     `TRUNCATE TABLE` when the engine does not store data on disk, and ignore it
     outright when it does. An engine that implements `truncate` (`S3`) or takes
     the ignore branch (`Distributed`) therefore leaves the table in place and
     still reports rc 0, so an exit-code-gated teardown proceeds. An engine
     implementing neither (`URL`, `PostgreSQL` and `S3Queue` inherit the throwing
     `IStorage::truncate`) gives the client `Code: 48` instead and the teardown
     stops there.
  L2 `ast_fuzzer_runs = 5` with `ast_fuzzer_any_query = true`
     (`tests/docker_scripts/stress_tests.lib`, applied by both the Stress test and
     the Upgrade check) lets the server-side AST fuzzer replay table DDL. The two
     observed mutations are a `DETACH TABLE`, which keeps the metadata file, and a
     `__fuzz_N` clone of a `CREATE TABLE`, which inherits the collection reference.
  L3 `InterpreterDropNamedCollectionQuery` filters dependents through
     `DatabaseCatalog::isTableExist`, false for a detached table, so the dependency
     guard passes and the edge is removed. The collection drop succeeds.
  L4 the `ATTACH` at the next start throws `NAMED_COLLECTION_DOESNT_EXIST` and
     `DatabaseOrdinary` rethrows it.

L1 and L2 are deliberate CI fault injections and L3/L4 are server-side, so the fix
belongs in the tests: pin `ast_fuzzer_any_query = 0` on the client invocations that
issue table DDL for the collection-backed table. That closes both observed strand
shapes, including the clone path, and it restores the setting's own default
(`src/Core/Settings.cpp` declares it `false`) for exactly those statements rather
than switching a feature off. `SELECT` and `SHOW CREATE` stay fuzzed, and
`isReadOnlyQuery` in `executeQuery.cpp` admits them whichever value the setting
has. The merged in-tree precedent for this class is
`03822_named_collection_drop_dependency_check.sh`.

Blast radius, CIDB, `test_name = 'Cannot start clickhouse-server'` with
`NAMED_COLLECTION_DOESNT_EXIST` in the context. Over 30 days: 14 rows, 13 distinct
pull requests (ClickHouse#113903 hit twice), 0 with `pull_request_number = 0`, every one a
`Stress test (*)` flavour, spread over 5 tests. The four changed here carry 13 of
those rows:

  04320_url_engine_dispatch_partition_and_format_named_collection.sh  6  08-08..08-17
  04626_s3_base_setting_named_collection.sh                           3  09-05..09-06
  04512_remote_missing_named_collection.sh                            3  08-15..08-19
  04327_s3queue_server_credentials.sh                                 1  08-14

The 14th belongs to `03822`, which is already pinned; its single hit predates its
pins and it has had none since.

The 30-day window is what shows no master hits, and that is a property of the window
rather than of the defect. Widening the same signature query gives 19 rows at 40 days
and 20 at 45, and the two extra rows both satisfy the full true-master predicate
(`pull_request_number = 0` with `head_ref = 'master'`), both stranding
`04320_url_engine_dispatch_partition_and_format_..._n`:

  2026-08-07 15:13:26  Stress test (arm_msan)
  2026-07-31 10:53:22  Stress test (arm_tsan)

So this is not confined to pull requests: it has already destroyed two master Stress
runs.

The carrier list is mechanical rather than a reading of a sample. A candidate is a
stateless test that creates and drops a named collection SQL-side and persists an
engine definition naming it, which means `CREATE TABLE`, `CREATE OR REPLACE TABLE`
or a full-definition `ATTACH TABLE`: the last is an `ASTCreateQuery`, writes the
same metadata file and is cloned the same way, so scanning for `CREATE TABLE` alone
misses it. Three candidates are deliberately left unpinned:

  - `04070_url_base_setting.sh` and `04546_postgresql_engine_settings.sql`, because
    `URL` and `PostgreSQL` implement neither `truncate` nor `storesDataOnDisk`, so
    L1's only reachable branch for them raises `Code: 48`, and in both files that
    aborts the statement stream before the collection drop. The collection outlives
    the table, which is the safe direction.
  - `04891_nats_credential_file_path_restriction.sql`, whose metadata-writing
    statement is a full-definition `ATTACH` carrying an explicit UUID. In an
    `Atomic` database a clone either collides with the live table's UUID or is
    rejected by `InterpreterCreateQuery`, and an `attach`-flag-dropped mutant fails
    NATS strict startup before committing metadata, so no mutant can persist an
    engine definition of its own. The lane is `Atomic`: neither `stress.py` nor
    `stress_runner.sh` passes `--db-engine`.
…and a collection reference

Same defect class and same one-line fix as the previous commit, on the two carriers
the census finds that have no CIDB occurrence yet. They are kept separate so this
commit can be dropped whole if a reviewer prefers to land only the proven ones.

Both use the `Remote` engine, so they are on the mechanism rather than on a
resemblance: `Remote` is `StorageDistributed`, which implements `truncate` and whose
`storesDataOnDisk` is true once it has a data volume. Whichever branch L1 takes, the
injected `DROP TABLE` therefore returns rc 0 with the table still present, which is
the same silent survival that produced the three recorded occurrences of
`04512_remote_missing_named_collection.sh`, also a `Remote` carrier.

`04318_remote_storage_engine_access.sh` has a second reason: it asserts that
`DROP NAMED COLLECTION` is refused while the table exists, by grepping for
`NAMED_COLLECTION_IS_USED`. That assertion needs the table attached, so a fuzzed
`DETACH` changes the test's own output as well as stranding the metadata. Only the
collection-backed table is pinned; the sibling tables in that file carry literal
engine arguments and cannot reference a collection.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 7, 2026
@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

⚠️ "Ordinary runs use the setting's false default, so reverting every pin produces identical reference
output"
: correct, and it is why the proof is an external forced-injection harness rather than a test
oracle. With the injections delivered as CI delivers them and ignore_drop_queries_probability forced to
1 (5x CI's rate), async_load_databases = 0: without a pin the teardown strands metadata and the restart
gives SERVER_EXIT=210 with Caught exception while loading metadata and the CI message verbatim; with
the pins, 24 armed runs of all six tests strand nothing and the server boots (24 databases, 63 tables).
Removing a pin strands again. A stateless test cannot assert a boot abort, so nothing here is shippable
as an oracle.

💡 The pin comments were rewritten to one invariant per site after this review; the mechanism and the
CIDB table live in the commit messages.

💡 The three unpinned candidates (04070, 04546, 04891) carry 0 of the 14 recorded occurrences and
strand nothing with the injections armed. The Code: 48 argument in the commit message is why they
cannot strand through the ignored or rewritten DROP; the armed re-check is what covers the fuzzer path.

💡 04318's teardown line is also rewritten by my open #116768, which adds a src/ fix and a
system.tables/system.detached_tables post-condition on that one file. It covers 1 of these 6 tests
and leaves the CREATE unpinned, so I kept the uniform pin here and will rebase whichever lands second
over the other.

@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e71a2e2]

Summary: ✅


AI Review

Summary

This PR narrows the server-side AST fuzzer only around the non-read-only table DDL that can strand metadata referencing a dropped named collection in six stateless tests. I reviewed the current diff, the touched tests, and the prior PR discussion, and I did not find a remaining correctness gap in the patched coverage.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 7, 2026
@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat, could you review this? With the stress harness arming ast_fuzzer_any_query, the server-side AST fuzzer replays these tests' table DDL as a DETACH or a __fuzz_N clone, so the teardown drops the named collection while metadata still names it and the next server start aborts on it. The fix pins that one setting off on the table DDL only, so read-only fuzzing stays on.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 7, 2026
@PedroTadim

Copy link
Copy Markdown
Member

cc @qoega

@qoega

qoega commented Sep 7, 2026

Copy link
Copy Markdown
Member

That looks as not a real fix. If we can't start server after some sql queries we should fix it and not just mute the test

@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

You are right, and the product defect is bigger than the CI symptom: reaching it needs no fuzzer at all. Four ordinary statements on master (e568d262dc86, debug build):

CREATE NAMED COLLECTION nc_probe AS url = 'http://127.0.0.1:1/none', format = 'TSV';
CREATE TABLE t_probe (n UInt32) ENGINE = URL(nc_probe);
DETACH TABLE t_probe;
DROP NAMED COLLECTION nc_probe;   -- succeeds, and it should not

t_probe.sql on disk still says ENGINE = URL(nc_probe). Restarting that data directory:

With async_load_databases = 0, the server never reaches Ready for connections and the process exits:

<Error> Application: Caught exception while loading metadata: Code: 722. Waited job failed:
Code: 695. Load job 'load table default.t_probe' failed: Code: 669. There is no named collection
`nc_probe`: Cannot attach table `default`.`t_probe` from metadata file store/b91/.../t_probe.sql
(NAMED_COLLECTION_DOESNT_EXIST)

That is the CI signature verbatim. With async_load_databases = 1 (the packaged default, programs/server/config.xml:490) the server does start, but the failed load job poisons the database: SELECT name FROM system.tables WHERE database = 'default' itself fails with Code: 722 ... (ASYNC_LOAD_WAIT_FAILED), so the user cannot even list their own tables.

Control arm: leave the table attached and the same drop is correctly refused with Code: 769 NAMED_COLLECTION_IS_USED. The dependency guard works; only the detached case slips past it. ENGINE = S3(...) behaves identically to URL in both arms.

So there are two separable product bugs, and both already have open PRs:

  1. DROP NAMED COLLECTION removes a collection that a persisted table still names. InterpreterDropNamedCollectionQuery.cpp:53 gates the check on DatabaseCatalog::isTableExist, which is false for a detached table, and line 56 then deletes the dependency edge instead of refusing. That is @ alexey-milovidov's Do not drop a named collection that a detached table still uses #112805, open since 2026-07-31.
  2. One unattachable table takes down the whole server instead of just that table. My Do not abort server startup when a URL table's named collection is missing #110529 does this for URL only, open since 2026-07-15, so the S3 case above is not covered.

With (1) merged, the fuzzer sequence ends in a visible Code: 769 on the collection drop rather than a server that will not start, and this PR stops being needed. So I am not asking for #118504 to be merged and have no objection to it being closed. I will put the effort into (2) instead, so that a missing named collection fails one table's load rather than the process. I plan to extend #110529 to the remaining engines; say so if you would rather have it somewhere else.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good at least as an immediate measure.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit fc7975b Sep 12, 2026
174 of 175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The product fix is open: #120734

It goes through the load path rather than extending #110529, so it covers every engine at once: a table whose stored ENGINE names a missing named collection now fails only that table's load, the server starts, and a system.tables scan of that database no longer fails with ASYNC_LOAD_WAIT_FAILED. A streaming source still fails its load deliberately, since a lazy stand-in would never start its ingestion.

@PedroTadim

Copy link
Copy Markdown
Member

Good at least as an immediate measure.

@alexey-milovidov we should fix the real root causes instead

@groeneai

Copy link
Copy Markdown
Collaborator Author

For the root causes: they are split across two open PRs, and I answered on #120734.

The drop-side refusal is @ alexey-milovidov's #112805, which counts detached tables as dependents. #120734 is the load-side half: a server whose stored metadata names a collection that is already gone boots and stays introspectable, which also covers the cases where no DROP ran (a config.d entry edited out, or check_named_collection_dependencies = 0). Neither replaces the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants