Repository navigation
Add the Cluster database engine - #114417
Conversation
A follow-up to the `Remote` database engine: provides real-time access
to the tables of a database on a cluster from the server configuration,
the same way the `cluster` table function relates to the `remote` table
function.
CREATE DATABASE db ENGINE = Cluster('cluster_name', 'database');
The engine shares the metadata and query machinery with
`DatabaseRemote`. The named cluster is re-resolved from the server
configuration on every access, so the database follows configuration
reloads and cluster auto-discovery; connections use the per-replica
settings of the cluster configuration (credentials, secure connections,
compression, the inter-server secret) instead of credentials of its
own, and `SHOW CREATE TABLE` prints a re-executable
`Distributed(cluster_name, database, table)` definition.
The remote-only metadata-lookup fallback (the cluster with the local
replicas stripped from their shards) is derived by the new
`Cluster::tryGetClusterWithoutLocalReplicas`, which preserves the
per-replica settings; the `Remote` database engine now uses it too.
Closes: #114411
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [65276f9] Summary: ✅
AI ReviewSummaryThis PR adds the new Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 65276f9.
Changed lines: Changed C/C++ lines covered: 349/398 (87.69%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes69 object files changed (+181.74 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1293 translation units recompiled, 8689 s compile time in total, 1292 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
`master` moved the documentation from `docs/en/**/*.md` to the Mintlify tree `docs/**/*.mdx` and made the database-engine reference pages generated from `system.database_engines`, so the docs part of the branch is relocated: - The new `Cluster` page moves to `docs/reference/engines/database-engines/cluster.mdx` with the Mintlify frontmatter (`sidebarTitle`, no `sidebar_position`, no `H1`) and the links rewritten to the new tree, and is registered in `docs/reference/navigation.json`, `docs/_site/redirects.json` and `docs/_migration/slug-map.csv`, exactly as the `Remote` page was moved in 05df4be. - The cross-reference from the `Remote` page to the `Cluster` engine moves into the `Documentation` description in `src/Databases/DatabaseRemote.cpp`: the body of `remote.mdx` now lives between the `AUTOGENERATED` markers and is regenerated from that description, and direct edits to it are rejected by the generated-region guard in `ci/jobs/docs_job_mintlify.py`.
…TE and skip it in listings A cyclic chain of `Remote`/`Cluster` databases on the same server (e.g. `a` -> `b` -> `a`) was reported lazily: `LocalTraversalGuard` threw `INFINITE_LOOP` from the local-shard traversal on re-entry. The listing path (`fetchTablesList`) also serves whole-server scans, so while such a pair of databases existed, every `SELECT ... FROM system.tables` / `system.columns` of every user failed with `INFINITE_LOOP` — in CI, the cycle case of the tests `04541_remote_database_engine` and `04846_cluster_database_engine` made unrelated concurrent tests (`00938_fix_rwlock_segfault_long`, `00821_distributed_storage_with_join_on`) fail with that exception: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114417&sha=26b4fa30e58ff7401d7b32c614638491d816d768&name_0=PR (#114417) Now the chain is rejected eagerly, at `CREATE DATABASE` of the database that would complete it (`throwIfLocalChainRefersBack` walks the local proxy chain by database name, following an edge only while the cluster of the hop currently has a local shard). The check deliberately does not run on any form of attach: a server that persisted such a chain must still start, and the metadata loading of server startup attaches the databases with the same `ATTACH` mode as the explicit query. A cycle can still come into existence later (e.g. a configuration reload turns a shard of a `Cluster` database into a local one, or an explicit `ATTACH DATABASE` completes it), so `LocalTraversalGuard` remains as the lazy backstop, but it no longer throws from the listing path: the re-entered database is skipped (with a warning in the log) and lists no tables, so whole-server scans are unaffected; table resolution (`fetchTableStructure`) still reports `INFINITE_LOOP`, because it only affects queries that name a database of the cycle. Also covers the scenario with an integration test case (a cycle formed by a configuration reload) and updates the stateless tests to the eager rejection.
…ists in the fallback state
Address the review finding on `SHOW CREATE TABLE` of the `Cluster` database engine: when the
live proxy is bound to the remote-only fallback cluster (the local replica of a shard does not
have the database or the table), the emitted `Distributed('cluster_name', ...)` definition
recreated a different object — a `Distributed` table over the whole cluster performs no such
fallback on the metadata lookup, so replaying it fails on the missing local objects.
Unlike the `Remote` engine, which serializes the effective fallback addresses together with
its stored credentials, the connections of the `Cluster` engine are defined by the per-replica
settings of the cluster configuration, which no explicit address list can carry, and the
fallback subset has no name of its own — no equivalent re-executable definition exists for this
transient state. `SHOW CREATE TABLE` now reports `THERE_IS_NO_QUERY` with an explanation
instead of emitting a misleading definition; the best-effort paths (e.g. the
`create_table_query` column of `system.tables`) return nothing for it and do not fail.
Covered by a new case in the `test_replica_fallback` integration test.
|
🕵 Merged
Verified locally: |
- The `catch (...)` in `DatabaseRemote::tryGetLocalChainNext` is a deliberate negative answer of the cycle walk, so mark it as such for the `catch_all` style check. - The chain-cycle note belongs to the generator source of the docs, the engine description registered in `DatabaseRemote.cpp`, not to the `AUTOGENERATED` region of `docs/reference/engines/database-engines/remote.mdx`.
|
🕵 Merged
No behavior change; the binary builds. The only unresolved review thread is the |
Carry one `ProxyClusters` snapshot through `fetchTable` and `getCreateTableQueryImpl`, so a configuration reload cannot make `SHOW CREATE TABLE` compare clusters from separate resolutions.
|
It reappeared, so here is the fix in a separate PR as you asked: #120928. The recurrence was on 2026-09-18, on another PR's head, in the same two Root cause: One thing worth knowing for anyone measuring this family: it leaves no row in |
…ection step
A `Stateless tests (..., selected tests)` job dies before running a single test
with `Failed to select tests: Failed to get previously failed tests required for
test selection`. Eight such job deaths were measured over six days on six PRs
between 2026-08-20 and 2026-09-18; four of them, including both on 2026-09-18,
are the CI database answering HTTP 500 `Code: 202. DB::Exception: Too many
simultaneous queries. Maximum: 1000`.
`queue_max_wait_ms` defaults to 0, and it is honoured by exactly the 202 branch
these requests hit: `ProcessList.cpp:183-193`, the `max_size`
(`max_concurrent_queries`) branch. At 0 the server throws immediately; at a
positive value it logs "Too many simultaneous queries, will wait N ms." and waits
on `have_space` for an admission slot, throwing only if the wait expires. The
sibling 202 branches carry different messages ("for all users", "for user X",
"insert/select queries", "for table X"), so the attribution is exact. praktika
never sends the setting, so every CI database request asks to be rejected rather
than queued, and `_post_with_retries` then spends its five attempts in 31 s
re-asking a saturated server. Because a `selected tests` run passes
`include_changed_tests=True`, `find_tests.py` has `strict=True` and converts that
into an ERROR result with zero tests run.
Send `queue_max_wait_ms` at half the caller's own timeout (30000 ms for queries,
10000 ms for inserts and the smoke test) from the single shared helper, so the
server waits for a slot instead of rejecting, and without issuing another request
to an already saturated server. This covers `query`, `insert_rows` and `check`.
The fail-closed selection policy itself is deliberate and is left untouched.
Separately, the selected-tests error handler rendered only `str()` of the outer
exception, whose message is a fixed string, so the preserved `__cause__` chain
was never shown. One of the eight occurrences (2026-09-06) therefore carries no
diagnostic at all and cannot be attributed today. Render `traceback.format_exc()`
as well; that handler catches every selection leg, and `Result.info` reaches all
three places a human looks: the job log, the HTML report and the CI database.
Validated on a server with `max_concurrent_queries=1` and the only slot held:
plain `SELECT 1` returns 500 `Code: 202` in 0.06 s; with
`queue_max_wait_ms=30000` it returns 200 after a 4.01 s wait, the holder's
remaining time, and the server logs "will wait 30000 ms."; with
`queue_max_wait_ms=1` it returns 500 again, which isolates the wait duration as
the causal variable. Seam assertions cover both hunks, each with a patch-revert
negative control.
Related: ClickHouse#114417
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Dear @thevar1able, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…-shard `Remote` proxy `getCreateTableQuery` is not specific to `SHOW CREATE TABLE`: it also serves `CREATE TABLE dst AS remote_db.t` and the `create_table_query` / `engine_full` columns of `system.tables`. Rejecting a multi-shard `Remote` proxy with `THERE_IS_NO_QUERY` therefore regressed an existing engine. Restore the `master` behavior (the emitted `Remote(...)` definition carries the `rand()` key) together with its test coverage. The new `Cluster` engine keeps reporting `THERE_IS_NO_QUERY`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Merged The only red on the previous head was |
| throw Exception(ErrorCodes::LOGICAL_ERROR, "Cluster is empty"); | ||
|
|
||
| secret = from.secret; | ||
| name = from.name; |
There was a problem hiding this comment.
tryGetClusterWithoutLocalReplicas keeps the original shard numbering here: it only strips local replicas from each shard and preserves the shard order, weights and names. That means _shard_num provenance must carry over as well, exactly like it does in SubclusterTag.
Right now RemoteReplicasTag leaves shard_scope_identity empty, so any query that reaches remote_only_cluster and then hits a nested Distributed / parallel-replicas read on the answering replica will treat the shipped shard scope as Foreign. The inner read then becomes unscoped (or disables parallel replicas) even though the fallback cluster is supposed to be “the same cluster without local replicas”.
Please copy from.shard_scope_identity before initMisc(). Without that, the new Cluster database fallback path changes query semantics for nested distributed reads as soon as the local replica is missing the table or database.
alexey-milovidov
left a comment
There was a problem hiding this comment.
This looks ok. Some parts look excessive, but the reasoning is well-thought.
… into 2 batches `Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel)` and `Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel)` are the only coverage stateless *parallel* shards that still run the whole suite un-batched, and they are the two shards that hit the 9000 s job timeout: 21 at-cap runs in 90 days, every single one reported as `error`. An at-cap kill is an unattributable red. The ordinary functional-test path passes `global_time_limit=0`, so there is no graceful stop: praktika's job watchdog SIGTERMs the process group and the job exits -15 with zero failing tests. On PR ClickHouse#114417 head f1b87f1 the shard reported 13153 of 13154 tests and died 184 s past its budget with one worker still inside its last test. Runtime is drifting: over Mar->Aug the AsyncInsert parallel shard's p99 went 4397 -> 5936 s (p50) and 5121 -> 7655 s (p99), and runs over 8000 s went from 0 in April to 127 in August, against a 9000 s cap. `prepare_stateful_data` costs ~1431 s and is paid per shard, so the model is `setup + (total - setup)/N`. N=2 puts the observed max at 5276 s (59% of the cap) and, at the measured 507 s/month test-phase drift, buys ~15-18 months of headroom. N=3 would cost 2862 extra runner-seconds per workflow for headroom nobody has asked for, and 3708b71 merged two-way stateless splits back into single jobs, so the batch count is kept at the measured minimum. The two `sequential` counterparts are deliberately left un-batched: their p99 is 4071 s and 3296 s. Cost: 2 jobs become 4, i.e. +2 AMD_MEDIUM runners per PR and per master run. The per-batch coverage artifact names had to be generated rather than listed: the four `_ft_s3*` entries in `LLVM_FT_ARTIFACTS_LIST` were hardcoded singletons, unlike every sibling shard's generated list, and that list feeds both `ArtifactConfigs.llvm_profdata_file` and `llvm_coverage_job.requires`. Workflow YAML is regenerated, not hand-edited.
Closes: #114411
Related: #59304
Related: #110975
Implement the
Clusterdatabase engine, a follow-up to theRemotedatabase engine (#110975). It provides real-time access to tables in a configured cluster database. Each table is exposed as aDistributedproxy that forwardsSELECTandINSERT, with the same local-shard visibility rules and remote-replica fallback asRemote.The cluster is resolved from server configuration by name on every access, supports macros, and follows configuration reloads. Connections use each replica's configured credentials, secure connections, compression, and inter-server secret; the engine stores no credentials.
SHOW CREATE TABLEreportsTHERE_IS_NO_QUERYfor a table of aClusterdatabase: the proxy follows configuration reloads (a reload can add shards and give the proxy an implicitrand()sharding key that is used only forINSERT, while a standaloneDistributedtable would also use it for read shard pruning), it expands macros on every access, and it falls back to a remote replica on the metadata lookup, so no standaloneDistributeddefinition is equivalent to it. Best-effort paths, such as thecreate_table_querycolumn ofsystem.tables, return nothing instead of failing.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
Clusterdatabase engine, which provides real-time access to the tables of a configured cluster database and forwardsSELECTandINSERTqueries to it.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/114417]
Version info
26.10.1.863-master(included in26.10and later)