Repository navigation
Conversation
A database SETTINGS clause is one ASTSetQuery with three payloads: `changes` (name = value), `default_settings` (name = DEFAULT) and `query_parameters` (param_name = value, prefix stripped). All six database engines that accept settings apply `changes` only, and InterpreterCreateQuery::createDatabase serialises the whole AST into the database .sql after the creator ran, so a name in either of the other two payloads was accepted and then persisted in system.databases.engine_full where no code ever reads it. DatabaseFactory::validate checks only whether a clause is allowed for the engine, never the names in it. Add checkDatabaseSettingNames and call it once from createDatabase, which is the only caller of DatabaseFactory::get and the only place where all three replay discriminators exist at once. `changes` is deliberately left to the engines: every one of the six already rejects an unknown name there, and DatabaseDataLakeSettings::loadFromQuery attaches a tailored "use the setting without `iceberg_` prefix" hint that a generic UNKNOWN_SETTING would replace. A param_name entry is rejected outright rather than looked up, mirroring the storage side: nothing hoists a name out of query_parameters and no database engine reads one, so such an entry did nothing even where a custom setting of that name existed. The freshness predicate is the database-side one, not isFreshTableDefinition. loadMetadata.cpp hard-codes /*create*/ true for a database, so setForceAttach is never called and the stored full `ATTACH DATABASE db ENGINE = ...` is replayed at plain ATTACH with attach_short_syntax == false, the same (mode, attach_short_syntax) pair a user's own full-definition ATTACH DATABASE carries. isFreshTableDefinition would therefore have rejected every settings-carrying database at server startup. DatabaseBackup.cpp already computes the correct database-side form, and it is reused here. RESTORE was the one replay path with no marker: RestorerFromBackup set only setInternal(true), and the backup stores a CREATE DATABASE, so the mode is CREATE. It now also sets setIsRestoreFromBackup(true), which the table path already used for this purpose and which is behaviour-neutral on the database path today, every other consumer of that member being table-only. Two alternatives were rejected: passing secondary = is_restore_from_backup would move the mode to SECONDARY_CREATE and flip DatabaseReplicated's is_create_query and its DROPPED_MARK handling for every restored Replicated database, and setRecoveryFromStoredMetadata is the broad flag that also disables StorageDistributed local-shard access checks. No is_ddl_replay term is added, because a Replicated database's DDL log carries the definitions of the tables inside it and never its own, so no CREATE DATABASE is ever replayed under a ZooKeeperMetadataTransaction. Related: ClickHouse#121202 Related: ClickHouse#121394
… engines
The sibling checkStorageSettingNames carries five exemption terms. Four have
a correctly translated or correctly absent database analogue, but
is_shared_catalog_replay had none, and the path is real from this tree alone:
the DatabaseMySQL constructor has an explicit
`SharedDatabaseCatalog::initialized() && !isInitialQuery(context_)` branch
that tolerates a connection failure exactly as it does for attach, reachable
only through DatabaseFactory::get and so only through createDatabase. A
CREATE DATABASE therefore is re-executed on a secondary as a non-initial
shared-catalog query, and MySQL is one of the six engines that accept
settings. On that path is_metadata_replay, attach_short_syntax and
is_restore_from_backup are all false with mode CREATE, so nothing exempted
it and a definition stored before this change could be refused on a
secondary, which retries its queue entry forever.
No test: SharedDatabaseCatalog.h is not in this tree, so the branch is
unreachable in an OSS build and a test would assert nothing.
The stateless test previously proved the rejection on Atomic and Ordinary,
which share one has_builtin_setting_fn, leaving four of the six engines
measured only by hand. Because the check runs before the creator, a
rejection needs no external service, so the remaining engines are asserted
directly: Replicated (both spellings, since the param_ loop is
engine-independent), MySQL, DataLakeCatalog, and MaterializedPostgreSQL
behind its experimental gate, which fires earlier than the check.
The Replicated path stays a literal. A {...} inside a Replicated zk path is
expanded as a macro rather than substituted as a query parameter, so the
per-run form fails with NO_ELEMENTS_IN_CONFIG once the path is reached. It is
never reached here, the settings check rejecting first, which is exactly why
the arm would have passed either way.
The fast test build configures -DENABLE_LIBRARIES=0, which defaults ENABLE_MYSQL, ENABLE_LIBPQXX and ENABLE_AVRO off, so configure_config.cmake leaves USE_MYSQL, USE_LIBPQXX and USE_AVRO unset and registerDatabases.cpp never registers MySQL, MaterializedPostgreSQL or DataLakeCatalog. With the engine absent from the registry the new check takes its own early exit for an engine it cannot resolve, and DatabaseFactory::get then throws UNKNOWN_DATABASE_ENGINE where those three arms assert UNKNOWN_SETTING. The file carried no tag line, so --fast-tests-only selected it. The merged sibling 05227_storage_settings_unknown_name.sql already carries the same block for the same reason on the S3 engine. The companion .sh test needs no tag: its only engines are Atomic, MergeTree and File backups, and registerBackupEnginesFileAndDisk registers File and Disk unconditionally.
On a short `ATTACH DATABASE db` the interpreter replaces the query with the definition parsed out of the stored metadata file, so the stored clause is the one that reaches the check, and then sets attach_short_syntax. On that path the metadata-replay flag is false because it is a user query rather than the startup load, the restore flag is false, the Shared Catalog term is false in an OSS build, and the mode is exactly ATTACH. So attach_short_syntax is the only term that exempts it, and nothing in the tree exercised a short detach and attach of a database whose stored clause names a non-setting. The other three terms already have live arms: a full-definition ATTACH is rejected, a stored definition still loads at startup, and a RESTORE still succeeds. The new arm re-asserts the stored name first, so a definition rewritten by the load above it cannot make it pass while asserting nothing.
Drop the restore-flag narration; state the ATTACH-mode, DEFAULT-parse and declaration contracts as bare invariants.
…nown-database-setting-name Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nown-database-setting-name Resolved `src/Databases/DatabaseFactory.cpp` by keeping both additions: master's `DatabaseFactory::Arguments::isLoadingFromExistingMetadata` and this branch's `checkDatabaseSettingNames`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a setting For a database, the initiator of `CREATE DATABASE ... ON CLUSTER` only enqueues the query, so the clause is judged on the host that runs the queue entry. No arm covered that leg, so exempting the DDL worker (which would reopen ClickHouse#121202 for every ON CLUSTER create) left the suite green. Both spellings are asserted; `FORMAT Null` keeps the per-host status row out of the output under the default `throw` mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…SE on the initiator A plain `ON CLUSTER` leg runs with no Keeper metadata transaction, so it judged the `SETTINGS` names of the enqueued `CREATE` as a fresh definition. A host then refused an entry that an older initiator, which judged nothing, had enqueued: the object ended up on some hosts only. The initiator now judges the names before it enqueues anything, and the hosts skip the check: a database at every entry format (its engine is explicit or `Atomic`), a table only for entries stored in format 4 or later, whose `CREATE` the initiator normalized (format 3 is stored as 2); with the legacy formats the hosts keep judging tables. The engines that judge names carry `StorageFeatures::checks_setting_names`, so `StorageFactory::get` and the initiator read one flag instead of seven creator calls. Requested in ClickHouse#121661 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erialized view Only a host knows whether the object of `CREATE ... IF NOT EXISTS` exists, and where it does the statement is a no-op before any name is judged. The initiator therefore skips such a statement and the hosts judge it as before, with the decision taken from the entry's own query, so the inner table of a materialized view inherits it. New arms: a materialized view whose inner engine has an unknown name is refused before enqueueing, `IF NOT EXISTS` over an existing table or database is still a no-op, and over a missing one is still refused by the host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the flag and DDL entry format comments to one line and drop the repeated IF NOT EXISTS note in checkSettingNamesOnInitiator. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
Internal review: 2 rounds, 3 major + 2 nits fixed, 1 finding disagreed
|
Collaborator
Author
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261105-175700 |
Contributor
|
Workflow [PR], commit [c4a0a31] Summary: ❌
|
Collaborator
Author
|
cc @tuanpach, could you review this and add the |
Member
|
Too large PR, ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #121202
Related: #121661
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
CREATE TABLE ... ON CLUSTERandCREATE DATABASE ... ON CLUSTERcheck on the initiator, before enqueueing the query, theSETTINGSnames that older servers accepted although they are not settings, so such a name is reported once instead of by each host, and an upgraded host no longer refuses such a query enqueued by an older server.IF NOT EXISTSis still checked on each host.Description
Requested in #121661 (comment). Builds on #121661 (open); its commits show here until it merges.
Problem. For
ON CLUSTER, the name check (#120898 for tables, #121661 for databases) runs on each host's DDL worker, which judges the enqueued text as a freshCREATE. So with a 26.9 host and an upgraded one, a query issued on 26.9, which checks nothing, leaves the table on one host only:Change. The initiator judges the names before enqueueing: tables (inner engines of materialized views included) in
createTable, where the definition is normalized, databases in the earlyON CLUSTERbranch ofexecute. A plain DDL leg then skips the check: for a database at every entry format, for a table at entry format 4 or higher (format 3 is stored as 2).IF NOT EXISTSstays judged on each host, which alone knows whether the object exists.Replicateddatabases are unchanged. The engines that check names carryStorageFeatures::checks_setting_names, read byStorageFactory::getand the initiator, instead of seven creator calls. An initiator built without an engine cannot judge it, nor do the hosts.Validation. A mixed-version integration test with a 26.9 node: the upgraded host creates a table, a database and a format-2 database that 26.9 enqueued; an upgraded initiator rejects a table, a materialized view and a database before 26.9 sees them; the host still rejects a format-2 table and an
IF NOT EXISTSobject it lacks, andIF NOT EXISTSover existing ones stays a no-op. 6 of the 11 cases fail without the change, and removing each part reddens its own case.Workflow [PR]
Sync PR [sync-upstream/pr/129609]