Repository navigation
Conversation
…sing
A database whose engine arguments reference a named collection that is absent
at startup stops the whole server from booting:
<Error> Application: Caught exception while loading metadata: Code: 669.
DB::Exception: There is no named collection `nc_cfg`:
while loading database `db_cfg` from file metadata/db_cfg.sql.
(NAMED_COLLECTION_DOESNT_EXIST)
<Information> Application: shutting down
The only recovery was moving metadata/<db>.sql aside by hand, since the
collection cannot be recreated over SQL while the server is down. Reaching this
does not require DROP NAMED COLLECTION: a config-file collection cannot be
dropped over SQL at all, yet retiring its config.d/*.xml and restarting is
enough.
A table in the same state does not do this. The server boots, only that table's
load job fails, and an admin recovers with a plain CREATE NAMED COLLECTION. The
asymmetry comes from the mode: loadDatabase calls executeCreateQuery with
create = true, which gates setForceAttach behind if (!create), so a database is
loaded as ATTACH while TablesLoader gets the FORCE_ATTACH that makes the table
path tolerant.
The two startup loops in loadMetadata now skip such a database instead of
aborting, under four conditions that must all hold:
1. the process is clickhouse-server (clickhouse-local stays strict),
2. the error is exactly NAMED_COLLECTION_DOESNT_EXIST, so metadata syntax
errors, UNKNOWN_DATABASE_ENGINE and LOGICAL_ERROR still stop startup,
3. the database is not the configured default, which assertDatabaseExists
requires immediately afterwards,
4. the engine is in an explicit audited list of engines that own no local
table metadata: S3, Remote, RemoteSecure, MySQL, PostgreSQL.
Of the 17 registered database engines, 7 can raise this error. The two left out
are Replicated and MaterializedPostgreSQL: both extend DatabaseAtomic and own
persistent local tables, so silently dropping one would lose more than it saves.
An explicit list means a future engine has to be added deliberately, which is
the correct fail-closed direction here; an is_external-style flag would not be,
since that flag means "accesses a remote source" and is documented for restore.
The metadata file is never touched on the skip path, so recreating the
collection and restarting brings the database back.
Deliberately not addressed: if the default database is one of these, the server
still refuses to start. Deciding what a server with no default database should
do belongs in its own change. A test pins the current behaviour.
Tests: 5 integration tests in test_named_collections covering boot tolerance for
S3 and RemoteSecure, recovery through the config file and through SQL, the table
positive control, and the two strictness arms (Replicated and
MaterializedPostgreSQL must still abort, and a non-669 metadata error must still
abort). One clickhouse-local stateless test pins that clickhouse-local is
unchanged. Each strictness test was also run against a deliberately widened
build and fails there, so none of them is vacuous.
Related: ClickHouse#110529, which fixes the same startup-abort class for URL tables.
Co-Authored-By: Claude Fable 5 <[email protected]>
…tests The startup-tolerance test suite only exercised S3 and RemoteSecure, so removing Remote, MySQL or PostgreSQL from the skip list left the whole suite green. Parametrize the boot-tolerance arm over all five engine names; each uses a collection that is never defined anywhere, so no external server is needed (in every engine the collection lookup precedes any connection attempt). Add an arm for a skippable engine failing with a non-669 error, which the existing NoSuchEngine arm could not cover: NoSuchEngine is rejected by the engine-name check regardless of the error-code check, so the code check had no oracle. Four positional S3 arguments raise NUMBER_OF_ARGUMENTS_DOESNT_MATCH from an engine that is on the skip list. Add the missing arm for the default-database predicate, asserting both that the original error is reported and that no skip is logged: with the predicate removed the server would still refuse to start on the "default database must exist" assertion, so a bare "does not start" oracle cannot tell the two builds apart. Tag the clickhouse-local test no-fasttest. It needs the S3 database engine, which is compiled only under USE_AWS_S3, and the Fast test configures with ENABLE_LIBRARIES=0. Correct the skip-list comment: MySQL and PostgreSQL do persist local .remove_flag/.removed markers, so those engines' local state is not re-derived. What actually makes the skip safe is that they keep their metadata under metadata/<name>/ rather than store/<uuid>/, which is what the store/ cleanup task scans. Co-Authored-By: Claude Fable 5 <[email protected]>
Same invariant, one line shorter, keeping the block within the per-block comment budget. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings across 2 rounds)
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260816-203500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260816-181900 |
|
Workflow [PR], commit [f10a895] Summary: ✅
AI ReviewSummaryThis PR makes server startup tolerate Final Verdict
LLVM Coverage ReportMeasured on commit f10a895.
Changed lines: Changed C/C++ lines covered: 49/55 (89.09%) · Uncovered code |
|
cc @tavplubix @tuanpach, could you review this? A database created over a named collection (S3, Remote, RemoteSecure, MySQL, PostgreSQL) makes the server refuse to start once that collection is gone, because |
`check_catch_all` in ci/jobs/check_style.py, added upstream after this branch's base, flags every `catch (...)` whose block neither handles the exception nor carries a comment containing 'Ok'. It reports loadMetadata.cpp:171. The swallow there is intentional and loses nothing. Reading a database's engine name out of its metadata file is a best-effort step taken while already recovering from a missing named collection; when it yields no name, loadDatabaseAtStartup falls through to `throw`, so the original NAMED_COLLECTION_DOESNT_EXIST reaches the operator exactly as before. Logging instead would add a second message to a path that is about to rethrow, so the sanctioned 'Ok' comment is the correct remedy. Comment-only: `gcc -fpreprocessed -dD -E -P` token streams before and after are byte-identical at 565 lines, while renaming one symbol in the same probe makes them differ, so the probe is live. Co-Authored-By: Claude Opus 5 <[email protected]>
…ions in the fixture
The skip message offered a server restart as the only way back. Once the missing
named collection is recreated, the short `ATTACH DATABASE <name>` path in
InterpreterCreateQuery::createDatabase re-reads the preserved metadata file
(`need_write_metadata` stays false because the file exists) and the database
returns inside the running process, so the hint pushed operators into bouncing a
healthy server. Measured on a local server: uptime is monotonic across the
recovery, so no restart occurred.
test_startup_skipped_database_recovers_from_sql now recovers with ATTACH DATABASE
rather than a restart, which pins what the message promises; the restart path
stays covered by test_startup_skips_database_with_missing_collection.
The fixture teardown removed `db_extra_*.sql` but not the SQL-defined collection
that recovery arm creates, so an arm failing between the CREATE and the final
DROP left it on disk. The damage is larger than a leak into later arms: once the
teardown restores the config file, config and SQL both define the name, and
NamedCollectionFactory::add refuses the duplicate inside the loadIfNot call at
server startup ("A named collection `nc` already exists",
NAMED_COLLECTION_ALREADY_EXISTS), so the node cannot start again and every later
arm on it fails with "Cannot start ClickHouse". Measured with the recovery arm
forced to fail: without this cleanup the next arm errors, with it the next arm
passes.
Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
The new database-skip tests planted and probed definitions at
/var/lib/clickhouse/metadata/<db>.sql with cat, test -f, cp and rm. That path
only exists when the database disk is local. In the "db disk" flavour
<database_disk> points at a remote object-storage disk, so every write landed
where the server never reads and every probe answered about a file that was
never there:
- the five skippable-engine arms and the two-database arm attached nothing, so
no "Skipping database" line was ever logged;
- the strict arms (Replicated, MaterializedPostgreSQL, NoSuchEngine, bad S3
arguments) armed nothing, so the server started where the test requires it to
fail, silently inverting this PR's negative controls;
- the default-database arm failed earlier still, on cp of an absent file.
Route every definition read, write, move and delete through
helpers/database_disk.py, which drives clickhouse-disks against whichever disk
holds the metadata. The surviving-definition probes now assert the engine clause
is still in the stored statement rather than only that some file exists, which is
what the recovery claim actually needs. Teardown lists the planted databases by
name because that interface takes one path at a time and expands no glob.
The named_collections/*.sql cleanups keep using the container filesystem:
named-collection SQL metadata is rooted at the local path from
context->getPath(), not on the database disk.
Measured on a plain debug binary with test_named_collections -k startup: under
db disk 11 failed / 2 passed before and 13 passed after; the default flavour
stays 13 passed. A mutant deleting the definition before the surviving-definition
assert reddens it ("assert 'S3(db_collection_absent)' in ''"), so that probe is
not vacuous.
Co-Authored-By: Claude Opus 5 <[email protected]>
|
📊 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
|
|
Related: #77366, #112805
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the server refusing to start when a database created with
S3,Remote,RemoteSecure,MySQLorPostgreSQLreferenced a named collection that no longer exists. Such a database is now skipped with a logged error and the server starts; recreating the collection and then runningATTACH DATABASE(or restarting) brings the database back.Description
A database whose engine arguments name a missing named collection stops the whole server from
starting:
Caught exception while loading metadata: Code: 669 ... There is no named collection 'nc_cfg': while loading database 'db_cfg', thenshutting down. Retiring aconfig.d/*.xmlcollection and restarting reaches this. Recovery meant moving
metadata/<db>.sqlaside by hand:the collection cannot be recreated with the server down.
A table in the same state does not: the server boots and only that table's load job fails, so
a plain
CREATE NAMED COLLECTIONrecovers it. That asymmetry is the bug.loadDatabaseruns with
create = true, sosetForceAttachis never called and databases deriveATTACHratherthan the
FORCE_ATTACHthat gives tables their tolerance.The two
loadMetadatastartup loops now skip such a database instead of aborting, under fourconditions, all required: the process is
clickhouse-server, the error is exactlyNAMED_COLLECTION_DOESNT_EXIST, the database is not the configured default, and its engine is inan audited list of engines owning no local table metadata (
S3,Remote,RemoteSecure,MySQL,PostgreSQL). Everything else is unchanged: other error codes still stop startup,ReplicatedandMaterializedPostgreSQLstill do because they own local tables,clickhouse-localstill fails,and
ATTACH DATABASEstill fails while the collection is missing. Once it is recreated,ATTACH DATABASErestores the database with no restart, since the metadata file is untouched.The default database is excluded because
assertDatabaseExists(default_database)runs right after.Validated both directions on identical on-disk state: the pre-fix binary exits 157, the fixed one
starts and logs the skip.
test_named_collectionspasses 29/29 with 13 new cases, plus aclickhouse-localstateless test. Each of the four conditions has its own test that fails on abuild with that condition removed, so none is vacuous.
#120734 is the counterpart for table engines.
Workflow [PR]
Sync PR [sync-upstream/pr/115049]