Repository navigation
Add Remote and RemoteSecure database engines - #110975
Conversation
Implement the `Remote` and `RemoteSecure` database engines, the
ClickHouse-to-ClickHouse counterparts of the `MySQL` and `PostgreSQL`
database engines.
A `Remote` database provides real-time access to the tables of a database
on a remote ClickHouse server over the native TCP protocol. The list of
tables and their structure are fetched from the remote server on demand
(via `system.tables` and `DESC TABLE`), so the database always reflects
the current state of the remote server. Each table is exposed as a
`Distributed` storage over an ad-hoc cluster built from the supplied
addresses, which forwards `SELECT` and `INSERT` queries to the remote
server. `RemoteSecure` connects over a secure TLS port by default.
CREATE DATABASE r ENGINE = Remote('host:port', 'database', 'user', 'password');
DDL statements against the database are not supported: it is a
read-through view of the remote server. The password is masked in
`SHOW CREATE DATABASE` and `SHOW CREATE TABLE`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [db7a48a] Summary: ✅
AI ReviewSummaryThis PR adds the Tests
Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 465/534 (87.08%) · Uncovered code |
Fix the `arm_tidy` build failure (`misc-unused-alias-decls`): the `fs` namespace alias and the `<filesystem>` include in `DatabaseRemote.cpp` were unused. Address the review on `DatabaseRemote.cpp`: - `fetchTablesList`: special-case a local shard, enumerating the local database under `local_context` instead of opening a self-connection with the stored engine credentials. Otherwise `SHOW TABLES` and `system.tables` would list local table names according to the configured remote user rather than the caller's privileges, matching the local-shard special case of `getStructureOfRemoteTable`. - `getCreateTableQueryImpl`: reuse `getCreateQueryFromStorage` with `only_ordinary = false` so that column defaults, aliases and materialized expressions inferred from the remote `ClickHouse` table are preserved in `SHOW CREATE TABLE`. Emitting only names and types changed the insert/read semantics of the recreated `Remote(...)` table. - `fetchTable`: distinguish a genuinely missing table (return `nullptr`) from a transport/authentication failure. On the throwing path (e.g. `SHOW CREATE TABLE`) the latter is now propagated instead of being reported as `UNKNOWN_TABLE`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a case to `04541_remote_database_engine` that creates a table with `DEFAULT`, `ALIAS` and `MATERIALIZED` columns and checks that `SHOW CREATE TABLE` through the `Remote` database preserves those column specifiers and their expressions. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Fixed the
|
The Fast test of the previous commit died with a hung server: a query to a missing table computed the table-name hints, which enumerate the tables of every database; for a `Remote` database over a local shard, each table was resolved through `DatabaseCatalog::getTable`, which on a concurrently dropped table computed the name hints again, recursing without bound (04243_table_name_hints_access timed out and the server was reported dead). - `fetchTable` now infers the structure of a local-shard table with the non-throwing `tryGetTable` instead of the `DatabaseCatalog::getTable` call inside `getStructureOfRemoteTable`, so it never enters the hint machinery. - `getAllTableNames` (used by the name hints) is overridden to return just the table names instead of inferring the structure of every table through `getTablesIterator` (a `DESC TABLE` round trip per table on a remote server). - A `Remote` database that refers to itself on the same server is now rejected with `INFINITE_LOOP` instead of recursing forever. - The best-effort table listing logs failures at debug level, like the best-effort path of `fetchTable`, so a `SHOW TABLES` covering the database is not reported as failed by an error-level log entry. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110975&sha=cd369e5be7d90f6cc2f127eda896e76b4749b577&name_0=PR&name_1=Fast%20test PR: #110975 Co-Authored-By: Claude Fable 5 <[email protected]>
|
The Fixed in b56462d:
Added regression cases to |
…rrors from table resolution Two fixes to `DatabaseRemote` following review: - The direct self-reference check in `tryGetLocalDatabase` did not cover longer local cycles (`a` -> `b` -> `a`), which recursed without bound through the local-shard path. A thread-local set of databases being traversed now rejects re-entry with `INFINITE_LOOP`. - `tryGetTable` is the ordinary table-resolution path (both `IDatabase::getTable` and the analyzer's `DatabaseCatalog::tryGetTable` delegate to it), so it now uses the throwing variant of `fetchTable`: a transport/authentication failure while resolving a remote table is reported as the real remote error instead of `UNKNOWN_TABLE`, like `DatabaseMySQL::tryGetTable` on a connection failure. The listing paths (`getTablesIterator`, `getAllTableNames`, `isTableExist`) stay best-effort. Both cases are covered by new sections of `04541_remote_database_engine`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Addressed the two remaining review threads in 1a1a5cb:
Both cases are covered by new sections of The AST fuzzer (amd_debug, targeted) failure (report) is unrelated to this PR: the fuzzed query is |
…mote replicas
Two fixes for the `Remote` database engine after review:
- For a shard that points to this server, the ordinary table-resolution
path validated only `SHOW_COLUMNS` on the underlying local table, but
the returned `Distributed` proxy could still read and write its data
directly. `StorageDistributed` gets an opt-in `check_local_shard_access`
flag (the class is `final`, so no subclassing) that enforces the
caller's own `SELECT`/`INSERT` rights on `remote_database.remote_table`
in `read`/`write`/`distributedWrite` when a shard is local, mirroring
the local-target check of the `remote` table function
(`TableFunctionRemote::executeImpl`). Covered by the stateless test
`04613_remote_database_engine_access`.
- The local-shard fast path of `fetchTablesList`/`fetchTableStructure`
returned early even when the local replica did not have the database or
the table, hiding tables that exist on the remote replicas of the shard
(e.g. `Remote('127.0.0.1|other_host', db)`), although the `Distributed`
read path would fall back to them (`SelectStreamFactory::createForShard`).
The metadata lookup now falls back to a precomputed cluster of only the
genuinely remote replicas (a TCP self-connection would resolve local
metadata under the stored engine credentials rather than the caller's
own), and the resulting `Distributed` storage uses that cluster as well,
because a missing local database fails `Context::resolveStorageID` before
the read-path fallback could engage, and an `INSERT` writes to every
replica of the shard. Covered by the integration test
`test_database_remote`, which exercises the fallback and the
local-replica preference across two nodes.
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Addressed the two remaining review findings in 9f2af35:
Verified locally with two servers on distinct ports (the second port makes the same host a genuinely remote replica): metadata lookup, |
# Conflicts: # src/Storages/StorageDistributed.cpp
…oxy, check local access only when the local replica serves the table - The remote-replica fallback cluster is now built per shard: only the replicas that point to this server are stripped from their shards, and every other shard stays intact. If some shard consists of local replicas only, no fallback cluster is built at all, because substituting a cluster without that shard would silently read and write only a subset of the configured shards; a database or table missing on such a local replica is reported as missing, like `Distributed` fails when a shard has nothing to fall back to. - `TRUNCATE TABLE` on a table of a `Remote` database is rejected with `NOT_IMPLEMENTED`. `InterpreterDropQuery` calls `IStorage::truncate` directly, bypassing the database-level DDL guards, and for a `StorageDistributed` with no async-insert spool that was a silent no-op reported as success. The `check_local_shard_access` constructor flag is renamed to `is_remote_database_proxy`, since it now controls both proxy behaviors. - The `SHOW_COLUMNS` check on the underlying local table now runs only when the local replica actually serves the table. Previously it ran before the fallback decision, so on the remote-replica fallback path a caller without grants on never-touched local objects was rejected. Covered by new sections of 04541 (TRUNCATE), 04613 (resolution rejected without SHOW_COLUMNS) and two new cases of tests/integration/test_database_remote (mixed shards with a local-only shard; fallback under a restricted user). Addresses the AI review at #110975 (comment)
|
Addressed the AI review of the
Coverage: new sections of The two failures of the
|
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110975&sha=838d0b61235b06939c8acd923ebd396f51cf5b10&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 (a segmentation fault in |
|
Acknowledged — investigating the |
… list `SHOW TABLES` uses `getLightweightTablesIterator`, whose default implementation goes through `getTablesIterator` and keeps only the tables whose structure could be fetched. For a `Remote` database that dropped any table whose `DESC TABLE` failed - e.g. a remote user with `SHOW TABLES` on the database but no `SHOW COLUMNS` on one table, or a transient `DESC TABLE` failure - even though the remote `system.tables` query had already returned the name. Override `getLightweightTablesIterator` in `DatabaseRemote` to build the result straight from `fetchTablesList`, so `SHOW TABLES` reports the names the remote server returned without depending on per-table metadata resolution, matching the existing `getAllTableNames`. Extend `04613_remote_database_engine_access` to check that `SHOW TABLES` still lists the table after `SHOW COLUMNS` on the underlying table is revoked. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@alexey-milovidov the fix is up in a separate PR: #111287. Root cause: finalizing a |
|
Investigated. My conclusion differs from the framing in two measurable ways, and I do not think a fix PR is warranted yet. The The real timeout history is much thinner. Over 90 days the test has 58 failing rows across 3 PRs and 0 on master. Split by reason, the It is a genuine hang, not a slow test losing the shared cap. In that job the test cost 600.04 s while the next slowest of 12319 was 121.40 s, so widening a threshold would be the wrong move regardless. What I could not do is reproduce it. 380 runs on a debug build (up to 48-way concurrent, including the exact two-invocation shape and shared-cwd variants) all finished, slowest 1.17 s. I checked the probe was not vacuous: it reaches the real containment check ( One structural detail worth recording, since it explains why the hang can only ever be seen on the second read. Arm 1 pipes into Given one occurrence, no reproduction, no stack, and no tracking issue, a fix PR now would be guesswork. I would rather not guess at a shutdown wedge and ship a change I cannot show fixes anything. What I suggest instead, if you want it: install |
…SHOW CREATE TABLE Address two AI review findings on the implicit sharding key of multi-shard Remote databases (introduced in 97edf24): - The implicit rand() key made the read path of StorageDistributed treat the proxy as a table with a sharding key: with force_optimize_skip_unused_shards = 1 (the "has sharding key" mode), a SELECT from a multi-shard Remote database threw UNABLE_TO_SKIP_UNUSED_SHARDS instead of reading all shards as before. The new hasShardingKeyForReads makes shard pruning and the distributed group-by optimization behave as if such a proxy has no sharding key, exactly like a Distributed table declared without one. - SHOW CREATE TABLE did not serialize the implicit key, so the emitted Remote(...) table definition recreated a table that rejects a multi-shard INSERT (STORAGE_REQUIRES_PARAMETER). The key is now appended to the emitted engine arguments (positional form, the named-collection form via sharding_key = rand(), and the rebuilt fallback-addresses form). New test 04813_remote_database_engine_multi_shard_sharding_key covers both: reads under force_optimize_skip_unused_shards = 1 and = 2, the serialized key, and a round trip that recreates the emitted definition and inserts through it. #110975 Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Addressed both Majors of the 08-05 AI review in 7bad59a:
New stateless test The three reds on the
|
|
Investigated. The fix is already in progress: PR 112644 ("Do not read-and-discard the archive prefix when reading a packed part member"), mine, open since 2026-07-30. It is not in the build that failed here, so this occurrence is expected. Presence probe at What the artifact saysI read Two hung rows, both Row 1 has 54 stacks. 50 of 54 carry the identical lower stack, and none is truncated (max 39 frames against Your negative claim is correct, verified with a positive control. By Mechanism
So when the archive prefix ahead of the member is skipped, The Why it reaches 410 s here rather than being merely slowThe stress build rewrites the logger level from That is where the 50 threads actually are: 48 of the 50 are inside the logger, 45 of them sampled on
PR 112644 clamps the seek threshold down to the already-clamped buffer size in Breadth for the exact signature, 60 days: 1 row, this one. On the darwin itemOne correction, since you noted no tracking issue: that family does have a merged fix, |
…is unavailable
When the local shard of a `Remote` database is itself another `Remote`
database whose own target is down, the `NetException` from the inner
proxy propagated out of `fetchTablesList` / `fetchTableStructure`
instead of engaging the same-shard remote-replica fallback, so
`SHOW TABLES`, `EXISTS TABLE`, `DESCRIBE`, `SHOW CREATE TABLE` and
`SELECT` on `outer = Remote('node1|node2', 'inner')` failed even though
the replica of `outer` on node2 was healthy and could answer. Treat the
inner-proxy failure like an unavailable local replica: catch the
`NetException` and fall through to `remote_only_cluster` when the local
database is a nested `Remote` proxy and a fallback cluster exists;
rethrow otherwise, so a database without remote replicas still surfaces
the real error, and non-nested local databases keep the old behavior.
Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Addressed the AI review Major in db7a48a: when the local shard of the outer The only CI red on the previous run, |
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Databases/DatabaseRemote.cpp.o |
new | 492.16 KiB | +492.16 KiB |
737 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
25 translation units recompiled, 178 s compile time in total, 24 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Databases/DatabaseRemote.cpp: 7.1 s
Build (arm_tidy) is red on master: src/Databases/DatabaseRemote.cpp:1058:26: error: use 'contains' to check for membership [readability-container-contains,-warnings-as-errors] clang-tidy runs as warnings-as-errors there, so the single diagnostic aborts the build and every PR that merges master inherits the red. The line is not an authoring mistake. readability-container-contains under clang-tidy-21 flags the find(...) != end() container form but not std::string::find(char) != npos; clang-tidy-22 flags both. The compiler bump landed in #108400 at 2026-08-10 17:33 UTC and the branch carrying this line merged at ~00:15 UTC, so the TU entered master's tidy build already diagnosed by a checker that had not diagnosed it during the branch's own 12 green runs. String is std::string and the project builds at C++23, so contains is available and exactly equivalent. Verified by asserting (s.find(':') != npos) == s.contains(':'), and the full guard including !starts_with('['), over 13 inputs covering empty, ":", "::", leading and trailing ':', bare and bracketed IPv6, non-IPv6 hosts and an embedded NUL. No behaviour change. The last green master commit already contained the clang-22 bump, so any other new violation of this check must lie in the green-to-red range. Sweeping that range's added lines for all three forms the check recognises yields exactly this one line. Related: #110975
|
Fix: #119345. Root cause is a lost wakeup in To be explicit about what is and is not proven: I reproduce the lost wakeup deterministically with a failpoint and fix it, but I could not reproduce the The diagnostics tooling I asked about on 2026-08-05 turned out to be unnecessary, so that question is moot: an earlier occurrence of the same signature (2026-08-23, on #115547) carries a full One thing worth knowing if this test is triaged again: the 600 s stall still recurs, and it is reported green. The 2026-08-23 and 2026-09-10 occurrences are |
Closes: #59304
Related: #106189
Implement the
RemoteandRemoteSecuredatabase engines, the ClickHouse-to-ClickHouse counterparts of theMySQLandPostgreSQLdatabase engines.A
Remotedatabase provides real-time access to the tables of a database on a remote ClickHouse server over the native TCP protocol. The list of tables and their structure are fetched from the remote server on demand (viasystem.tablesandDESC TABLE), so the database always reflects the current state of the remote server. Each table is exposed as aDistributedstorage over an ad-hoc cluster built from the supplied addresses, which forwardsSELECTandINSERTqueries to the remote server.RemoteSecureconnects over a secure TLS port by default. This is handy for federating several ClickHouse clusters or for plugging a larger cluster intoclickhouse-localor a smaller cluster.DDL statements against the database are not supported: it is a read-through view of the remote server. The password is masked in
SHOW CREATE DATABASEandSHOW CREATE TABLE.Notes:
MySQL/PostgreSQLdatabase engines and the maintainer's comment on the issue, a separateRemotetable engine is not introduced here: a single-shardDistributedalready covers it.remotetable function, an address that points to the current server is treated as a local shard, soSELECT/INSERTrun directly and the stored credentials are honored only for genuinely remote servers.Remote/RemoteSecurestorage engines): the database engine builds itsDistributedstorages directly. The per-tableSHOW CREATE TABLEprints theRemote(...)table engine, which becomes re-executable once Support Remote and RemoteSecure storage engines #106189 is merged.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
RemoteandRemoteSecuredatabase engines that provide real-time access to the tables of a database on a remote ClickHouse server, forwardingSELECTandINSERTqueries to it. They are the ClickHouse-to-ClickHouse counterparts of theMySQLandPostgreSQLdatabase engines.Documentation entry for user-facing changes