Repository navigation
Support Remote and RemoteSecure storage engines - #106189
Conversation
Implements #93138. Previously, a table over a remote server built from an ad-hoc set of addresses could only be created via `CREATE TABLE ... AS remote(...)`, i.e. by reusing the `remote` and `remoteSecure` table functions. This adds the persistent counterparts as storage engines, so that CREATE TABLE t ENGINE = Remote('addresses', db, table[, user[, password], sharding_key]) CREATE TABLE t ENGINE = RemoteSecure(...) work as well. This restores the symmetry between the table functions and the storage engines: `Distributed` uses a configured cluster, while `Remote`/`RemoteSecure` build a cluster on the fly from the addresses, exactly like the `remote`/`remoteSecure` table functions. The complex argument parsing previously living inside `TableFunctionRemote::parseArguments` is extracted into a reusable free function `parseRemoteFunctionArguments`, which is shared between the table functions and the new engines. The engines construct a `StorageDistributed` over the resulting owned cluster, so they accept exactly the same signatures as the table functions, and the table structure may be omitted (it is then inferred from the remote table). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [ef7bb68] Summary: ✅
AI ReviewSummaryThis PR adds persistent Findings❌ Blockers
Final VerdictStatus: |
`registerStorageRemote` in `StorageDistributed.cpp` (part of the `dbms`
library) called `parseRemoteFunctionArguments`, which was defined in
`TableFunctionRemote.cpp` in `clickhouse_table_functions`. That library is
not linked into every target that uses `dbms` (e.g. `unit_tests_dbms`),
so the build failed with an undefined symbol:
ld.lld-21: error: undefined symbol: DB::parseRemoteFunctionArguments(...)
Move `parseRemoteFunctionArguments` and the `ParsedRemoteFunctionArguments`
struct into a new file `Storages/Distributed/parseRemoteFunctionArguments.{h,cpp}`,
which is part of `dbms`, so the symbol is available wherever `dbms` is.
`TableFunctionRemote` keeps calling it through the new header (table
functions already depend on storages).
Also add the missing local forward declaration of `registerStorageRemote`
required by `-Wmissing-prototypes`.
CI: #106189
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a `Remote`/`RemoteSecure` table is created without an explicit
structure, the structure is inferred from the remote table. Previously the
inference was left to the `StorageDistributed` constructor, which uses the
storage's global context. For a local target such as
`Remote('127.0.0.1', db, table)` that bypassed the user-context
`SHOW_COLUMNS` access check in `getStructureOfRemoteTableInShard`, so a user
allowed to create a `Remote` table could infer the schema of a local table
they are not allowed to describe.
Infer the columns in `registerStorageRemote` under `args.getLocalContext()`
(the user's context) and pass them to `StorageDistributed`, so the access
check is enforced.
CI: #106189
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The new `Remote` and `RemoteSecure` storage engines were not present in the `engine_to_type` map used by the ArrowFlight SQL server, so `test_arrowflight_interface/test_sql_server.py::test_get_table_types` failed with `Some engine(s) in system.table_engines are not mapped`. Map them to `REMOTE TABLE`, like `Distributed`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…gines `Remote` and `RemoteSecure` accept a positional `password`, but were not registered in `FunctionSecretArgumentsFinder::findTableEngineSecretArguments`, so `SHOW CREATE TABLE` / `system.tables.engine_full` printed the password instead of `[HIDDEN]`. Reuse `findRemoteFunctionSecretArguments`, which handles both the positional and the named-collection forms, since the engines accept exactly the same arguments as the `remote`/`remoteSecure` table functions. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Setting `is_remote_function_` only adjusts the distributed client info; it does
not reproduce the local-shard access checks that `TableFunctionRemote::executeImpl`
performs. A user allowed to create `ENGINE = Remote('127.0.0.1:9000', secret_db,
secret_table, 'default')` could otherwise force the remote path (e.g. with
`prefer_localhost_replica = 0`), sending the query back to this server under the
stored credentials without checking the caller's access on the local target.
Mirror the table-function check in `registerStorageRemote`: when the built
cluster contains a local shard, require the creating user to hold both `SELECT`
and `INSERT` on the local target table (a persistent table can be used for both),
under the user's context.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a persistent `Remote`/`RemoteSecure` table is created from a named collection (`ENGINE = Remote(my_collection, ...)`), the shared parser never passed the table's `StorageID` to `tryGetNamedCollectionWithOverrides`, so the table was not registered as a dependent of the collection. As a result, `DROP NAMED COLLECTION` was not blocked while the table existed and the dependency was not rebuilt on reload, which could leave a stored `Remote` table broken after reload or next use. Thread an optional `dependent_table_id` through `parseRemoteFunctionArguments` and pass `&args.table_id` from `registerStorageRemote`. Table-function callers leave it null, since their lifetime is bound to the query. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The failures of They were introduced by #104690 ("Add #104690 was merged in violation of the ClickHouse team rules: its own CI already showed these two tests failing (10 times between May 12 and June 1) before it was merged. Please update your branch to pick up the revert; the tests should pass again. |
For the persistent `Remote`/`RemoteSecure` engines, the local-shard access check applied `SELECT`/`INSERT` to `parsed.remote_table_id`. When the target is a table function (e.g. `numbers(...)`, `merge(...)`), that field is left at the parser default `system.one`, so the check validated the wrong object: it both spuriously required privileges on `system.one` and, with explicit columns, never analyzed the table function under the creating user's context. A query against such a persisted table could then be routed back to this server under the engine credentials, reading local data the creator was never checked for. Now, when the cluster contains a local shard and the target is a table function, the function is analyzed under the user's context even when the columns are given explicitly (`getStructureOfRemoteTableInShard` runs it through `getActualTableStructureWithAccess`, which performs the access check). The `SELECT`/`INSERT` check on `remote_table_id` is applied only for a plain table target. Added `04318_remote_storage_engine_access`, covering the persistent-engine security and lifecycle invariants: the local-shard `SELECT`/`INSERT` check with explicit columns, schema inference under the creating user's context, and the named-collection dependency that blocks `DROP NAMED COLLECTION` while the table exists. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Updated in c3e41a8 (pushed onto the existing branch, no rebase):
Built and verified locally: both |
|
The
CREATE TABLE t_remote_engine (dummy UInt8) ENGINE = Remote('127.0.0.{1,2}', system, one);
SELECT count() FROM t_remote_engine;with This is the standard I re-ran the failed job (workflow run 27483260206) — it passes when the runner skips the shard tests. @groeneai, could you investigate / track the |
|
@alexey-milovidov Confirmed: same root cause as the wider arm_darwin class. macOS binds only 127.0.0.1 on lo0 and does not auto-route the rest of 127.0.0.0/8, so 127.0.0.2:9000 is unroutable. The Scope over the last 7 days (Fast test arm_darwin, 127.0.0.2:9000 / ALL_CONNECTION_TRIES_FAILED): 15 distinct tests, 90 PRs, 165 failures, 0 on master. Fix is in flight: PR #107435 adds a macOS Fast-test pre-hook aliasing 127.0.0.2..127.0.0.16 on lo0 (the server already listens on 0.0.0.0), so these tests run instead of skip. It also un-skips 5 parallel-replica On the tracking issue: a dedicated tracker is not strictly needed since #107435 fixes the whole class at once. If you would prefer one, I can open an issue enumerating the remaining darwin.skip / shard-tag tail to un-skip incrementally after the aliases land. 04327/04336 are already skipped on master via #107376. |
`04308_remote_storage_engine` exercises the multi-shard case
`Remote('127.0.0.{1,2}', system, one)`, which connects to the second
loopback shard `127.0.0.2:9000`. On the `arm_darwin` Fast test runner,
macOS binds only `127.0.0.1` on `lo0` and does not auto-route the rest
of `127.0.0.0/8`, so `127.0.0.2` is unroutable and the query fails with
`ALL_CONNECTION_TRIES_FAILED`.
This is the same macOS shard-test infrastructure issue already handled
for the sibling tests `04327_rewrite_aggregate_function_with_if_distributed`
and `04336_parallel_blocks_marshalling_low_cardinality_native_format`,
which were added to `ci/defs/darwin.skip` in #107376. `04308` is a new
test introduced by this pull request, so it was not covered there. Add
it to `ci/defs/darwin.skip` for consistency until the runner-side fix
(#107435) aliases the additional loopback addresses and these tests can
run on macOS again.
The test itself is unchanged and keeps full coverage on Linux.
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=dbc0fc28753abffe3096e1064be57a6c440263b6&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
Related: #107376
Related: #107435
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…rom metadata The `Remote`/`RemoteSecure` storage-engine creator analyzes a local-shard table-function target under the user's context to validate the creator's access to the function's underlying tables, even when the columns are given explicitly. This is a `CREATE`-time check, but the creator also runs when the table is loaded from already-validated metadata on server startup (`FORCE_ATTACH`) or `RESTORE` (`FORCE_RESTORE`). In that case re-running it is unnecessary and harmful: analyzing the target can throw if its underlying tables have changed since creation (e.g. the table matched by `merge(...)` was dropped), making a valid persisted table impossible to load. Guard the table-function inference and the local-shard `SELECT`/`INSERT` checks with `isLoadingFromExistingMetadata`, so they run for fresh definitions (`CREATE` and user `ATTACH`) but are skipped when loading from existing metadata. The structure is still inferred unconditionally when it was omitted, because then it is the table's only source of columns. Add an integration test that creates a `Remote` table over a local `view(...)` target, drops the table the view reads from, restarts the server, and checks that the `Remote` table still attaches. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Every integration test directory must contain an `__init__.py`; its absence
made the `Style check` fail with:
./tests/integration/test_remote_storage_engine_attach/__init__.py should exist for every integration test
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A leftover `txn_version.txt.tmp` on a part is an artifact of an interrupted
write, so not only its content but even the disk-level metadata describing it
can be broken. On an object storage disk with local metadata, a raw or
partially written metadata file for it made `getFileSize` throw
`CANNOT_PARSE_INPUT_ASSERTION_FAILED` from
`DiskObjectStorageMetadata::deserialize` inside
`VersionMetadataOnDisk::removeTmpMetadataFile`, failing the part load, the
table load, and with it the server startup ("Cannot start clickhouse-server").
The read there is purely diagnostic (the content is dumped to the log before
the file is removed), so make it best-effort: on failure, log the exception
and proceed with the removal, which is already tolerant to such files
(`UnlinkFileOperation` reads the disk-level metadata with
`tryReadMetadataFile`).
Seen in stress tests when the harness kills the server inside the window in
which `04492_attach_as_replicated_clears_tmp_txn_version` keeps a raw
`txn_version.txt.tmp` on a part, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=73e731bf28d09bb59fa7e7921f58be9d812cf201&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
on ClickHouse#106189, and the same
signature on at least three other PRs within the last 30 days.
Add `test_broken_tmp_txn_version_startup`: a transactional insert on a local
object storage disk, a raw overwrite of the `txn_version.txt.tmp` metadata
file, and a hard restart. Without the fix the server fails to load the table
with the exact `Cannot parse input` error from the report; with the fix it
starts, the committed part survives, and the leftover file is cleaned up.
The AI review noted that the docs contrast was false: a `remote(...)` table
function with a table-function target (e.g. `remote('127.0.0.1', numbers(10))`)
is rejected by `StorageDistributed::write` for the same reason as the
`Remote`/`RemoteSecure` engines, because `TableFunctionRemote::executeImpl`
forwards `remote_table_function_ptr` to `StorageDistributed`. So `INSERT` is
`NOT_IMPLEMENTED` for both the table functions and the engines when the target
is itself a table function.
Reword the `Remote`/`RemoteSecure` engine paragraph in
`docs/en/engines/table-engines/special/distributed.md` to state the read-only
limitation applies equally to the table functions, and add the same caveat to
`docs/en/sql-reference/table-functions/remote.md`, which previously claimed
`INSERT` is always supported.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 306/312 (98.08%) · Uncovered code |
|
Both fixes for #110133 are already open and in review:
No separate/competing PR needed here; tracking both against #110133. |
Resolve conflicts with the `Remote`/`RemoteSecure` engine work (#106189) that landed on master, which touched the same areas as this PR: - `StorageDistributed::write`: both branches added the same `remote_table_function_ptr` guard rejecting `INSERT` into a table-function target with `NOT_IMPLEMENTED`; kept a single copy with a comment covering the `remote()`/`cluster()` table functions, the `Remote`/`RemoteSecure` engines, and the `Distributed` engine over a table function. - Anonymous-namespace helpers before `registerStorageDistributed`: kept both this PR's `bindTableFunctionTargetsToCurrentDatabase` family and master's `finalizeDistributedSettings`; the call sites to `finalizeDistributedSettings` auto-merged into the registration bodies. - `docs/.../distributed.md`: kept both the "From a table function" section and master's "Remote and RemoteSecure engines" section. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Acknowledged. I'll verify whether the new Remote/RemoteSecure storage engines route through the |
|
@PedroTadim yes, both engines respect
Verified locally with a restrictive There was no test covering this, so I added one: #111140 ( |
…allow_hosts Follow-up to ClickHouse#106189. The Remote/RemoteSecure storage engines build a cluster on the fly from user-supplied addresses via the same parseRemoteFunctionArguments as the remote/remoteSecure table functions, which calls RemoteHostFilter::checkHostAndPort for every parsed host. For the engines this runs during CREATE, so a host outside <remote_url_allow_hosts> is rejected with UNACCEPTABLE_URL before the table is created. This adds a regression test that locks in that behavior for both Remote and RemoteSecure (disallowed bare host, glob expanding to a disallowed host, disallowed port; allowed host succeeds). Co-Authored-By: Claude Opus 4.8 <[email protected]>
A leftover `txn_version.txt.tmp` on a part is an artifact of an interrupted
write, so not only its content but even the disk-level metadata describing it
can be broken. On an object storage disk with local metadata, a raw or
partially written metadata file for it made `getFileSize` throw
`CANNOT_PARSE_INPUT_ASSERTION_FAILED` from
`DiskObjectStorageMetadata::deserialize` inside
`VersionMetadataOnDisk::removeTmpMetadataFile`, failing the part load, the
table load, and with it the server startup ("Cannot start clickhouse-server").
The read there is purely diagnostic (the content is dumped to the log before
the file is removed), so make it best-effort: on failure, log the exception
and proceed with the removal, which is already tolerant to such files
(`UnlinkFileOperation` reads the disk-level metadata with
`tryReadMetadataFile`).
Seen in stress tests when the harness kills the server inside the window in
which `04492_attach_as_replicated_clears_tmp_txn_version` keeps a raw
`txn_version.txt.tmp` on a part, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=73e731bf28d09bb59fa7e7921f58be9d812cf201&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
on ClickHouse#106189, and the same
signature on at least three other PRs within the last 30 days.
Add `test_broken_tmp_txn_version_startup`: a transactional insert on a local
object storage disk, a raw overwrite of the `txn_version.txt.tmp` metadata
file, and a hard restart. Without the fix the server fails to load the table
with the exact `Cannot parse input` error from the report; with the fix it
starts, the committed part survives, and the leftover file is cleaned up.
`registerStorageRemote` in `StorageDistributed.cpp` (part of the `dbms`
library) called `parseRemoteFunctionArguments`, which was defined in
`TableFunctionRemote.cpp` in `clickhouse_table_functions`. That library is
not linked into every target that uses `dbms` (e.g. `unit_tests_dbms`),
so the build failed with an undefined symbol:
ld.lld-21: error: undefined symbol: DB::parseRemoteFunctionArguments(...)
Move `parseRemoteFunctionArguments` and the `ParsedRemoteFunctionArguments`
struct into a new file `Storages/Distributed/parseRemoteFunctionArguments.{h,cpp}`,
which is part of `dbms`, so the symbol is available wherever `dbms` is.
`TableFunctionRemote` keeps calling it through the new header (table
functions already depend on storages).
Also add the missing local forward declaration of `registerStorageRemote`
required by `-Wmissing-prototypes`.
CI: ClickHouse#106189
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a `Remote`/`RemoteSecure` table is created without an explicit
structure, the structure is inferred from the remote table. Previously the
inference was left to the `StorageDistributed` constructor, which uses the
storage's global context. For a local target such as
`Remote('127.0.0.1', db, table)` that bypassed the user-context
`SHOW_COLUMNS` access check in `getStructureOfRemoteTableInShard`, so a user
allowed to create a `Remote` table could infer the schema of a local table
they are not allowed to describe.
Infer the columns in `registerStorageRemote` under `args.getLocalContext()`
(the user's context) and pass them to `StorageDistributed`, so the access
check is enforced.
CI: ClickHouse#106189
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address two AI-review findings on PR ClickHouse#106189 (ClickHouse#106189): - The `Remote`/`RemoteSecure` registrations loaded `DistributedSettings` via `loadFromQuery` but skipped the validation and default propagation that `Distributed` runs immediately after. The background `INSERT` queue reads these table settings directly, so `ENGINE = Remote(...)` ignored the global `distributed_background_insert_*` defaults and accepted invalid combinations such as `max_delay_to_insert = 0` or `bytes_to_throw_insert <= bytes_to_delay_insert` that `ENGINE = Distributed(...)` rejects. The shared logic is extracted into `finalizeDistributedSettings` and called from both registrations. - The `Remote`/`RemoteSecure` registrations passed no `Documentation` object, so `system.table_engines` listed them with empty `description` and `syntax`. Both now carry source-level documentation, with `RemoteSecure` noting the secure TCP default port. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review feedback (ClickHouse#106189 (comment)): when analyzing a `Remote`/`RemoteSecure` table-function target on a backup `RESTORE` fails for a reason other than access control, the failure is tolerated (the target may be legitimately absent in the restore environment, e.g. the table matched by `merge(...)` was dropped since the backup was taken) and the restore proceeds with the columns carried in the backup metadata. Previously the exception was swallowed silently. Log it at `WARNING` level with the table name and the full exception (including stack trace) so a genuine problem is surfaced rather than hidden, and the tolerated acceptance is auditable. `ACCESS_DENIED` is still fatal and rethrown as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The named-collection branch of `parseRemoteFunctionArguments` discarded the
collection's own `db`/`table` values as soon as any complex (non-literal)
override was present: `remote(nc, sharding_key = rand())` recorded only the
sharding key and left the database at the hard-coded `system`, routing the
query to `system.<table>`. It also unconditionally required a `table` key,
so the documented table-function form `remote(nc, database = merge(...))`
was rejected unless the collection carried a dummy `table` key. Since the
`Remote`/`RemoteSecure` engines reuse this parser, both misparses carried
into the engines too.
Now the collection's own values are loaded first (simple literal overrides
are already merged into the collection by `tryGetNamedCollectionWithOverrides`)
and the complex overrides are applied on top, and `table` is required only
when the target is not a table function. With a table-function target the
parsed table id stays at the parser default (`system.one`), matching the
positional `remote('addr', table_function())` form, which the callers rely on.
Addresses ClickHouse#106189 (comment)
…ngine Support Remote and RemoteSecure storage engines
…allow_hosts Follow-up to ClickHouse#106189. The Remote/RemoteSecure storage engines build a cluster on the fly from user-supplied addresses via the same parseRemoteFunctionArguments as the remote/remoteSecure table functions, which calls RemoteHostFilter::checkHostAndPort for every parsed host. For the engines this runs during CREATE, so a host outside <remote_url_allow_hosts> is rejected with UNACCEPTABLE_URL before the table is created. This adds a regression test that locks in that behavior for both Remote and RemoteSecure (disallowed bare host, glob expanding to a disallowed host, disallowed port; allowed host succeeds). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Implements #93138.
Previously, a table over a remote server built from an ad-hoc set of addresses could only be created via
CREATE TABLE ... AS remote(...), reusing theremote/remoteSecuretable functions. This PR adds the persistent counterparts as storage engines:This restores the symmetry between the table functions and the storage engines:
Distributeduses a configured cluster, whileRemote/RemoteSecurebuild a cluster on the fly from the supplied addresses, exactly like theremote/remoteSecuretable functions. The table structure may be omitted, in which case it is inferred from the remote table.The complex argument parsing previously living inside
TableFunctionRemote::parseArgumentsis extracted into a reusable free functionparseRemoteFunctionArguments, shared between the table functions and the new engines, so they accept exactly the same signatures with no duplicated logic. The engines construct aStorageDistributedover the resulting owned cluster.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
RemoteandRemoteSecuretable engines, the persistent counterparts of theremoteandremoteSecuretable functions.CREATE TABLE ... ENGINE = Remote('addresses', db, table, ...)now works in addition toCREATE TABLE ... AS remote(...).Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.7.1.1174(included in26.7and later)