Skip to content

Add SQL-managed CREATE/ALTER/DROP CLUSTER - #116757

Open
ylw510 wants to merge 115 commits into
ClickHouse:masterfrom
ylw510:feature/sql-cluster-simple
Open

ylw510 wants to merge 115 commits into
ClickHouse:masterfrom
ylw510:feature/sql-cluster-simple

Conversation

@ylw510

@ylw510 ylw510 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #93137.

This is a new implementation of SQL-managed cluster definitions.

The earlier approach on branch feature-sql-cluster-interface (#102405) grew too complex: separate CREATE ENDPOINT / CREATE SHARD / CREATE CLUSTER catalog layers, distributed DDL via ON CLUSTER, and a dedicated ClusterMetadataDDLWorker. This PR replaces that design with a simpler model:

  • Single nested CREATE CLUSTER / ALTER CLUSTER / DROP CLUSTER syntax with SHARD and REPLICA
  • Metadata storage behind <cluster_metadata>, modeled after NamedCollections
  • Incremental in-memory updates on local DDL; background sync when metadata is stored in Keeper
  • New source and create_query columns in system.clusters for SQL-managed clusters
  • Dedicated privileges: CREATE SQL CLUSTER, ALTER SQL CLUSTER, DROP SQL CLUSTER

Metadata storage

Configured via <cluster_metadata> in the server config. Supported backends:

type Description
local (default) Metadata stored as .sql files under {data_path}/sql_clusters_metadata on each node
local_encrypted Same as local, with encryption (key_hex, algorithm)
keeper / zookeeper Metadata stored in ClickHouse Keeper; other nodes reload via a background watch
keeper_encrypted / zookeeper_encrypted Same as keeper, with encryption

Example config for local storage:

<cluster_metadata>
    <type>local</type>
    <path>/var/lib/clickhouse/sql_clusters_metadata</path>
</cluster_metadata>

Example config for Keeper storage:

<cluster_metadata>
    <type>keeper</type>
    <path>/clickhouse/sql_cluster_metadata</path>
    <update_timeout_ms>5000</update_timeout_ms>
</cluster_metadata>

Each SQL-managed cluster is stored as a single CREATE CLUSTER ... statement. On startup, SQLClusterFactory loads metadata into Context; local DDL updates both storage and in-memory cluster definitions immediately.

Local vs Keeper behavior

  • Local storage keeps metadata on disk independently on each node. Use ON CLUSTER to run DDL on all nodes so every replica gets its own metadata file. Covered by integration tests (test_local_storage_on_cluster, test_local_storage_encrypted_on_cluster).
  • Keeper storage stores metadata centrally. DDL can be executed on a single node; other nodes pick up changes via background sync (SQLClusterFactory::updateFunc). Covered by integration tests (test_keeper_storage, test_keeper_storage_encrypted).

All three statements also accept an optional ON CLUSTER clause and are executed through the existing distributed DDL infrastructure when it is present.

Example

CREATE CLUSTER my_cluster (
    user = 'Me',
    SHARD (
        user = 'Me', password = 'p@s$w0rd',
        REPLICA (host = 'abc.clickhouse.cloud', port = 9000),
        REPLICA (host = 'def.clickhouse.cloud', port = 9000, user = 'Alexey', password = 'qwerty')
    ),
    SHARD (
        user = 'Me', password = 'p@s$w0rd',
        host = 'xyz.clickhouse.cloud', port = 9000
    )
);

-- local storage: distribute DDL to all nodes
CREATE CLUSTER my_cluster ON CLUSTER 'my_clickhouse_cluster' (...);

ALTER CLUSTER my_cluster (
    user = 'Me',
    SHARD (
        REPLICA (host = 'abc.clickhouse.cloud', port = 9000),
        REPLICA (host = 'def.clickhouse.cloud', port = 9000)
    )
);

DROP CLUSTER my_cluster;

SQL-managed clusters appear in system.clusters with source = 'SQL' and the stored create_query. Secrets in create_query are hidden according to the same rules as system.named_collections.

Config reload behavior

An error in remote_servers (for example, an invalid shard or a config cluster whose name collides with an existing SQL-managed cluster) now makes every config reload fail until the config is fixed, and the old clusters stay installed. This also applies to servers that never use SQL-managed clusters. On master the second reload only appeared to succeed because the first one had already recorded the config while the cluster map was half-applied.

Changelog category (leave one):

  • New Feature

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

Add SQL-managed CREATE CLUSTER, ALTER CLUSTER, and DROP CLUSTER statements with local or Keeper-backed metadata storage.


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

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47c898a]


AI Review

Summary

Adds SQL-managed CREATE CLUSTER, ALTER CLUSTER, and DROP CLUSTER with local or Keeper-backed metadata. Reviewed head 47c898a4bc6a253aaea0fcc313c24878cb69ab61, the current code, and all prior discussion. Earlier persistence, redaction, and asynchronous queue fixes hold. Two explicitly deferred name-resolution defects remain, including an authorization bypass. No new inline findings or thread changes.

Missing context / blind spots
  • ⚠️ The current-head CI report has successful Fast test, Style, and Docs checks, but further builds and the full test suite have not completed. No local server tests were run in this CI job; the findings below are current-source traces.
Findings

❌ Blockers

  • src/Interpreters/Context.cpp:8198–8202 — A macro-spelled database can override an SQL-managed topology without SQL CLUSTER ADMIN. [dismissed by author -- https://github.com/Add SQL-managed CREATE/ALTER/DROP CLUSTER #116757#discussion_r4624125646] With macro replica = r1 and SQL cluster c_r1, a user granted CREATE DATABASE and the required table-engine privilege can create a Replicated database literally named c_{replica}. The ownership check at Context.cpp:8485 compares literal keys and misses c_r1. A lookup through cluster('c_{replica}', system.one) then finds SQL c_r1, but selects the literal database before reaching canonical SQL resolution. This still violates the administrative boundary even though the author deferred the broader macro issue. Resolve ownership and source precedence using one canonical identity, and extend the negative authorization test with this spelling. The other getCluster overload has the same ordering at lines 8171–8174.

⚠️ Majors

  • src/Common/SQLClusters/SQLClusterFactory.cpp:711, src/Interpreters/Context.cpp:8516 — Accepted SQL cluster names containing macros do not survive their lifecycle consistently. [dismissed by author -- https://github.com/Add SQL-managed CREATE/ALTER/DROP CLUSTER #116757#discussion_r4505892639] With replica = r1, creating SQL cluster c_{replica} stores that literal key, while Clusters::getCluster expands lookups to c_r1. The accepted cluster cannot be queried; dropping it removes its metadata but misses the installed entry. Loading the metadata on a peer without the macro, or restarting after removing the macro, throws during startup. This remains a defect because the accepted name cannot resolve even while its macro exists. Reject such names before creation/persistence or implement a consistent identity, preserving cleanup of already-stored names, and cover lookup, deletion, and reload.
Final Verdict

Status: ❌ Block

The two findings were explicitly deferred and remain summary-only. Before approval, close the macro-spelled topology authorization bypass and make accepted SQL cluster names consistent across creation, lookup, deletion, and reload, with focused regression coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Aug 31, 2026
@ylw510 ylw510 changed the title Add SQL-managed CREATE/ALTER/DROP CLUSTER (sample implementation) Add SQL-managed CREATE/ALTER/DROP CLUSTER Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). label Sep 4, 2026
@ylw510
ylw510 marked this pull request as ready for review September 6, 2026 16:41
…rence.

Clear nested vectors in ASTSQLClusterShard and ASTSQLClusterDefinition clone methods so ALTER CLUSTER does not duplicate shards and replicas.
Document CREATE/ALTER/DROP CLUSTER syntax, metadata storage, system.clusters
columns, and integration with Distributed tables and navigation entries.
Document that ALTER CLUSTER replaces the full topology without incremental
updates, remove implementation-specific wording from user docs, and cover
single-replica SHARD syntax in 05045_sql_cluster.
@ylw510

ylw510 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@groeneai Help investigate CI failures and give me some fix advice.

@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

All four integration failures are one root cause, and it is not in the test: the server refuses to boot with a <cluster_metadata> section at all.

From clickhouse1/logs/clickhouse-server.err.log inside the failing job's logs.tar.gz:

Code: 137. DB::Exception: Unknown element 'cluster_metadata' found in config /etc/clickhouse-server/config.xml.
If it is a new option, it should be added to ServerSettings or to the known config sections.
...
5. src/Core/ServerSettings.cpp:3526: DB::ServerSettings::checkUnknownSettings(...)
6. programs/server/Server.cpp:1738: DB::Server::main(...)

checkUnknownSettings runs at Server.cpp:1738, long before SQLClusterFactory::loadIfNot() at Server.cpp:2327, so the storage type never gets a chance to matter: local, local_encrypted, keeper and keeper_encrypted all die identically in install_metadata_storage at the first restart_clickhouse(). That is the 4/4 in both Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6) and the flaky job. The initial cluster.start() succeeds only because cluster_metadata.xml is not installed yet.

Fix: register the section in known_complex_sections (src/Core/ServerSettings.cpp:2115); "named_collections_storage" at :2197 is the closest precedent. This is user-facing, not a test artifact: as it stands, nobody can start a server that configures the feature.

Three things that will surface on the next run once the boot works:

  1. tests/config/config.d/sql_cluster.xml is never installed. tests/config/install.sh links each config explicitly with ln -sf and has no line for it, which is why 05045_sql_cluster* are green: they run with no section at all, so SQLClusterMetadataStorage::create takes the type default local and the path default <clickhouse path>/sql_clusters_metadata. If you wire that file up before the fix above, every stateless and Fast test job will die at server start with the same 137. Separately, the file sets only <path>/clickhouse/cluster_metadata</path> with no <type>, so it selects local storage and would create a filesystem directory literally at /clickhouse/cluster_metadata.

  2. check_local_metadata compares bytes with str. content comes from open(..., "rb"), so content[:3] == "ENC" is always False (the encrypted local scenario fails) and content[:3] != "ENC" is always True (the plaintext one asserts nothing). check_keeper_metadata already gets this right with b"ENC". The signature is 'E','N','C', per src/IO/FileEncryptionCommon.h:112.

  3. read_local_metadata_file reads <node.path>/sql_clusters_metadata/..., but the container's /var/lib/clickhouse is bind-mounted from <node.path>/database (see the generated per-instance docker-compose.yml), so the host path is <node.path>/database/sql_clusters_metadata/.... As written it raises FileNotFoundError. Reading through the container avoids depending on the mount layout: node.exec_in_container(["cat", f"{LOCAL_METADATA_PATH}/{SQL_CLUSTER_NAME}.sql"]).

One isolation point worth fixing while you are there: the four scenarios share one module-scoped cluster and reuse the same metadata path (both local arms use /var/lib/clickhouse/sql_clusters_metadata, both keeper arms /clickhouse/sql_cluster_metadata), and install_metadata_storage restarts before DROP CLUSTER. So a definition left over from the previous scenario is read at startup by reloadFromStorage() with a different format or key, that throws inside loadIfNot(), and the server refuses to start again: one failure cascades into the rest. Give each scenario its own <path>, or clear the path and the Keeper node before the restart. It is the same shape as the point about createFromSQL persisting the definition before materializing it.

Finish Workflow is separate and mechanical: ci/jobs/scripts/workflow_hooks/feature_docs.py fails because a pr-feature PR must change something under docs/ or a source-owned doc file, and this one changes neither. A docs/ page covering CREATE/ALTER/DROP CLUSTER and the cluster_metadata config section satisfies it.

Nothing else at b88a79a6 is yours: Fast test and Style check are green (the earlier .reference diffs are gone), Build profile diff errored inside ci/jobs/build_profile_diff_job.py::has_pr_data on a CI-database query, and Integration tests (amd_asan_ubsan, targeted) was SKIPPED, so only the db disk, old analyzer, 4/6 shard plus the flaky job exercise the new test.

On the scope validation you mentioned: rejecting a mis-scoped property earlier is a better error message, but it does not make the syntax work. shard_properties = definition.cluster_properties and then replica_properties = shard_properties are what carry cluster-level secret and allow_distributed_ddl_queries down into applyReplicaProperties, which throws on them.

… config.

Register cluster_metadata as a known config section so servers can start with
metadata storage enabled. Validate SQL cluster properties at DDL time, reject
name conflicts with config and discovery clusters, and preserve SQL-managed
clusters across config reloads while bumping clusters_version for DDL worker
notifications. Fix integration test isolation and local metadata checks, migrate
05045 to a SQL test, and document user/password inheritance defaults.
Revert direct changes inside the AUTOGENERATED region of distributed.mdx
and update the table engine Documentation string instead, so docs CI accepts
the PR without the pr-autogenerated-docs label.
The test env removes the config `default` cluster, so CREATE CLUSTER default
succeeded instead of raising CLUSTER_ALREADY_EXISTS.
Comment thread src/Access/Common/AccessType.h Resolved
Comment thread src/Interpreters/Cluster.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 47c898a4b with master 515c1baee (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

311 object files changed (+1.36 MiB total), 5 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Common/SQLClusters/SQLClusterMetadataStorage.cpp.o new 338.44 KiB +338.44 KiB
src/CMakeFiles/dbms.dir/Common/SQLClusters/SQLClusterFactory.cpp.o new 337.13 KiB +337.13 KiB
src/CMakeFiles/dbms.dir/Access/ContextAccess.cpp.o 1.16 MiB 1.41 MiB +255.96 KiB (+21.52%)
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ASTSQLClusterQuery.cpp.o new 174.52 KiB +174.52 KiB
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserSQLClusterQuery.cpp.o new 90.94 KiB +90.94 KiB
src/CMakeFiles/dbms.dir/Interpreters/InterpreterSQLClusterQuery.cpp.o new 55.73 KiB +55.73 KiB
src/CMakeFiles/dbms.dir/Access/AccessRights.cpp.o 504.51 KiB 540.39 KiB +35.88 KiB (+7.11%)
src/CMakeFiles/dbms.dir/Interpreters/Context.cpp.o 3.67 MiB 3.69 MiB +27.34 KiB (+0.73%)
src/CMakeFiles/dbms.dir/Interpreters/Cluster.cpp.o 340.63 KiB 359.78 KiB +19.15 KiB (+5.62%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1797 translation units recompiled, 8534 s compile time in total, 1792 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -684.3 s (-7%) in total before that adjustment.

Job report

@ylw510

ylw510 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I read the delta since 906da965.

1. Style check is red on the new head e7c8948 (report): settings_changes_history reports that master is now on 26.12, so the record of ignore_on_cluster_for_replicated_sql_cluster_queries (Settings.cpp:3521) has to move from "26.11" to "26.12".

2. 22c7c79 (dropping the {macros} ban) brings back item 6 of my 2026-11-08 comment, and such a name can also keep a server from starting. I ran this on the CI amd_release binary of c8166ad4, one server with <macros><replica>r1</replica></macros> and local metadata storage:

  • CREATE CLUSTER `c_{replica}` (SHARD (...)) succeeds and writes sql_clusters_metadata/c_%7Breplica%7D.sql. The cluster is not in system.clusters, and both cluster('c_{replica}', system.one) and Distributed('c_{replica}', ...) fail with CLUSTER_DOESNT_EXIST, because the lookup expands the name to c_r1.
  • After I removed the replica macro and restarted, the server exited with code 36: SQLClusterFactory::loadIfNot at startup throws BAD_ARGUMENTS: Failed to expand macros in cluster name: No macro 'replica' in config ... 'c_{replica}' from reloadFromStorage, where tryGetCluster expands the stored name. With cluster_metadata.type = keeper, every server that shares the metadata and lacks that macro fails to start the same way (a running one, from the code, keeps failing the background reload and stops applying SQL cluster DDL from the others).

The case deferred in the bot's thread (a Replicated database whose name is spelled with macros) does not need the ban to go: the ban only rejected { in SQL cluster DDL, so restoring validateSQLClusterName fixes the above without touching database names.

The plan-based job you flagged failed only 05829_autopr_skip_index_on_read_in_subquery on c8166ad4. That test failed in 109 PRs and 50 master runs on 2026-11-19, #132867 fixed it, and e7c8948 includes the fix. I have nothing on the rest of the delta (the async queue pool changes, the all_groups. guard, SecretString).

@ylw510

ylw510 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

I read the delta since 906da965.

1. Style check is red on the new head e7c8948 (report): settings_changes_history reports that master is now on 26.12, so the record of ignore_on_cluster_for_replicated_sql_cluster_queries (Settings.cpp:3521) has to move from "26.11" to "26.12".

2. 22c7c79 (dropping the {macros} ban) brings back item 6 of my 2026-11-08 comment, and such a name can also keep a server from starting. I ran this on the CI amd_release binary of c8166ad4, one server with <macros><replica>r1</replica></macros> and local metadata storage:

  • CREATE CLUSTER `c_{replica}` (SHARD (...)) succeeds and writes sql_clusters_metadata/c_%7Breplica%7D.sql. The cluster is not in system.clusters, and both cluster('c_{replica}', system.one) and Distributed('c_{replica}', ...) fail with CLUSTER_DOESNT_EXIST, because the lookup expands the name to c_r1.
  • After I removed the replica macro and restarted, the server exited with code 36: SQLClusterFactory::loadIfNot at startup throws BAD_ARGUMENTS: Failed to expand macros in cluster name: No macro 'replica' in config ... 'c_{replica}' from reloadFromStorage, where tryGetCluster expands the stored name. With cluster_metadata.type = keeper, every server that shares the metadata and lacks that macro fails to start the same way (a running one, from the code, keeps failing the background reload and stops applying SQL cluster DDL from the others).

The case deferred in the bot's thread (a Replicated database whose name is spelled with macros) does not need the ban to go: the ban only rejected { in SQL cluster DDL, so restoring validateSQLClusterName fixes the above without touching database names.

The plan-based job you flagged failed only 05829_autopr_skip_index_on_read_in_subquery on c8166ad4. That test failed in 109 PRs and 50 master runs on 2026-11-19, #132867 fixed it, and e7c8948 includes the fix. I have nothing on the rest of the delta (the async queue pool changes, the all_groups. guard, SecretString).

Thanks. The second is a common issue which has existed in other DDLs. We probably don't need to address it in this PR.

Comment thread src/Storages/StorageDistributed.cpp Resolved
…t supplied its addresses

`createPool` read `getCluster` again and reused a replica pool by host, user and port,
ignoring `cluster_secret`. An `ALTER CLUSTER` in that window stored one generation's
addresses with the next generation's pool. Both now come from one `Cluster`, and the
pool match includes the secret, compression and priority.

PR: ClickHouse#116757
Co-authored-by: Young <[email protected]>
…er-simple

Keep the SQL cluster privilege rows in `SHOW PRIVILEGES`, and keep the new
column added on `master`.

Co-authored-by: Young <[email protected]>
…resh

`getDirectoryQueue` copies the cluster before `createPool` pauses, so `05829_sql_cluster_pool_refresh_keeps_previous_endpoint` no longer expects `CLUSTER_DOESNT_EXIST`. The resumed insert must be sent as the endpoint captured before the drop.

Co-authored-by: Young <[email protected]>
@ylw510
ylw510 requested a review from groeneai November 20, 2026 15:40

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I read the delta since e7c8948. I have nothing on the code of 780781b and d9a7e6d: both paths in getDirectoryQueue now take the addresses and the pool from the same getCluster() result.

I ran both tests on the CI amd_release binaries of d104e466 (before 780781b) and d9a7e6d2. Both fail on the first and pass on the second:

  • 05837_sql_cluster_secret_rollback_keeps_snapshot: on d104e466, SYSTEM FLUSH DISTRIBUTED fails with ALL_CONNECTION_TRIES_FAILED, the server logs Interserver authentication failed, and the count is 0.
  • 05829_sql_cluster_pool_refresh_keeps_previous_endpoint: on d104e466, the refresh insert fails with CLUSTER_DOESNT_EXIST from createPool.

CI on d9a7e6d2 has no failed check.

Small: 05829 now asserts that the block reaches the new endpoint, so keeps_previous_endpoint in its name says the opposite. The failpoint distributed_async_insert_queue_pause_before_pool_cluster_lookup also no longer comes before a cluster lookup.

…lpoint

`05829_sql_cluster_pool_refresh_keeps_previous_endpoint` asserts that the block reaches the new endpoint, so it is now `05829_sql_cluster_pool_refresh_after_drop_uses_new_endpoint`.

The failpoint `distributed_async_insert_queue_pause_before_pool_cluster_lookup` no longer precedes a cluster lookup, because `createPool` receives the cluster snapshot. It is now `distributed_async_insert_queue_pause_in_create_pool`.

PR: ClickHouse#116757

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (head 124200a4b7b7):

  • CH Inc sync was red because the private sync PR conflicted with the private master in StorageSystemClusters.cpp. I merged it by hand, with the same resolution as in the previous sync merge, and the sync PR is mergeable again. All other checks on d9a7e6d21d5c were green.
  • Addressed the two small points from the latest review by @groeneai: the test is now 05829_sql_cluster_pool_refresh_after_drop_uses_new_endpoint, and the failpoint is now distributed_async_insert_queue_pause_in_create_pool (124200a). The setting record is already at "26.12".
  • Still open, and it needs a maintainer decision: a SQL cluster name with {macros} (item 2 of the review of 2026-11-20). CREATE CLUSTER accepts such a name, the cluster cannot be looked up, and a server without that macro fails to start in SQLClusterFactory::loadIfNot. @ylw510 prefers to handle it outside this PR; @groeneai suggests restoring validateSQLClusterName. I did not change it.
  • No review threads are unresolved.

@groeneai

Copy link
Copy Markdown
Collaborator

Both renames in 124200a look right, and the old names are gone from the PR.

On the {macros} name, two facts for the decision:

  • The author is right that the startup failure is not specific to SQL clusters. On master, a Replicated database created with '{shard}', '{replica}' in its engine arguments also keeps the server from starting once that macro is removed (NO_ELEMENTS_IN_CONFIG while loading the database).
  • The difference is that those macros work while they are defined, whereas a SQL cluster whose name contains { never resolves: it is stored under the literal name, and Clusters::getCluster always looks up the expanded one. So restoring validateSQLClusterName rejects no name that can be used. If the check comes only after a release, note that the removed function also ran in DROP CLUSTER; the later check would have to keep DROP CLUSTER working for names that are already stored.

Comment thread src/Parsers/ASTSQLClusterQuery.cpp Resolved
@stresshouse

stresshouse Bot commented Nov 22, 2026

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

no significant changes detected. K_source=4 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 57671cb1-6ff2-4d32-b8ff-acb7ed34fe44
  • MIRAI run: be70faff-92e0-476a-8b6d-7c847bd2ac7f
  • PR check IDs:
    • clickbench_832840_1795372535
    • clickbench_832846_1795372535
    • tpch_adapted_1_official_832864_1795372535
    • tpch_adapted_1_official_832890_1795372535

`formatPropertiesAssignments` compared those property names by exact spelling, so `SECRET` and `Password` stayed visible in `system.clusters` and `system.distributed_ddl_queue`.

https: //github.com/ClickHouse/pull/116757#discussion_r4659264451
Co-authored-by: Young <[email protected]>
Local metadata storage keeps the clause, and distributed DDL checks `CLUSTER` before running it. Keeper storage drops the clause by default, so that grant is only required when the clause is executed.

https: //github.com/ClickHouse/pull/116757#discussion_r4659264452
Co-authored-by: Young <[email protected]>
`validateClusterLevelProperties` compared the original spelling, so `SECRET` and `Password` were rejected before a cluster could be stored. Lookups and the keys written into the cluster config now use the canonical lowercase name. The stored `CREATE` statement keeps the spelling from the query.

https: //s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116757&sha=43aa8bd48b62e9deeb1193e64243c5ad785a5863&name_0=PR&name_1=Fast%20test
https: //github.com/ClickHouse/pull/116757
Co-authored-by: Young <[email protected]>
`equalsCaseInsensitive` and `toLowerCopyASCII` already compare ASCII identifiers without applying the locale. The local `strncasecmp` and `std::tolower` copies are unnecessary.

Co-authored-by: Young <[email protected]>
`SettingsChanges::setSettings` matches names exactly, so `user` and `USER`
stayed as two entries and the shard value was written last. Merge with
`equalsCaseInsensitive` so a replica property replaces the shard and cluster
property of the same name.

Co-authored-by: Young <[email protected]>

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I re-reviewed the 5 commits since 124200a (head 399173b). Nothing blocking from me.

Measured on the CI build_amd_release binary of 399173b (one server, local metadata storage, embedded Keeper, a config cluster for ON CLUSTER):

  • Masking: SeCrEt, `PASSWORD`, PassWord and PASSWORD at cluster, shard and replica scope are [HIDDEN] in system.clusters.create_query, in system.query_log (QueryStart and QueryFinish) and in system.distributed_ddl_queue after CREATE CLUSTER ... ON CLUSTER.
  • The mixed-case secret is applied: with SECRET = 'abc' the secondary query of cluster(...) runs as the initial user, the same as with secret = 'abc'; without a secret it runs as default.
  • Merge: the case from the bot thread (cluster user, shard USER, replica user) gives replica_user, shard_user and cluster_user, and system.clusters is identical after a restart.
  • Validation is case-insensitive in every case I tried: Weight = -1, Port = 70000, Secure = 'maybe', and duplicates in one scope (user/USER, SECRET/secret, host/HOST, Port/PORT) all fail with BAD_ARGUMENTS; SECURE = 1 without a port looks up tcp_port_secure.
  • Docs: with local storage, CREATE CLUSTER ... ON CLUSTER by a user with only CREATE CLUSTER fails with ACCESS_DENIED (CLUSTER ON *.*) and works after GRANT CLUSTER, as the new paragraph says.

One small suggestion: 05483 has only an exact-case duplicate (user, user). A mixed-case one (user = 'a', USER = 'b') would pin the check that mergeProperties relies on, since it replaces only the first match.

CI: the only red check is 02423_ddl_for_opentelemetry in Stateless tests (arm_asan_ubsan, azure, targeted) ([operation_name like 'TCPHandler' ]=2, expected: 1). The same assertion failed the same day on 2 other PRs that do not touch DDL code (report 1, report 2), so I don't think this PR causes it.

This branch has not been deployed

No deployments
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-distributed Distributed table engine & query routing across shards (sharding/load balancing). external Author is not a member of the ClickHouse organization pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants