Repository navigation
Fix zero initiator version in the remote structure fetch of StorageDistributed - #113675
Conversation
…istributed` A structure-less `CREATE TABLE ... ENGINE = Distributed` fetches the structure of the remote table with a `DESC TABLE` service query, sent under the storage's global context, which carries no client version. Since the hardening check in `RemoteQueryExecutor` (#109408), such a query is rejected with the logical error "Sending a distributed query with unknown (zero) client version", so the `CREATE` fails. Stamp the server's own version on the service-query context in `getStructureOfRemoteTable` when it is unknown, the same way `DDLTaskBase::makeQueryContext` does for distributed DDL. Found by BuzzHouse fleet-wide, e.g. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110179&sha=f33258e4ed419d3eb7e77629b1e833cb36cadf7c&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [b9f02f0] Summary: ✅
AI ReviewSummaryThis PR correctly stamps the server's own client version onto the Findings❌ Blockers
Final Verdict❌ Changes requested LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
…ucture-fetch-client-version
…ser's context Address review: the `Distributed` engine inferred omitted columns in the `StorageDistributed` constructor under the storage's global context, so the `SHOW_COLUMNS` access check in `getStructureOfRemoteTableInShard` for a local shard ran with global privileges - a user who can create a `Distributed` table could learn the schema of a local table they are not allowed to describe. Mirror the `Remote`/`RemoteSecure` treatment: infer the structure in `registerStorageDistributed` under `args.getLocalContext()` when the definition is first introduced (`CREATE`, full-definition `ATTACH`, backup `RESTORE`), and keep the constructor's global-context inference only for loads of already-validated metadata stored on this server (server startup, short `ATTACH`), where there is no user to check against. Add an access regression test: without `SHOW_COLUMNS` on the target, a structure-less `CREATE TABLE ... ENGINE = Distributed` over a cluster with a local shard must fail with `ACCESS_DENIED`. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
| const bool loading_from_existing_metadata = isLoadingFromExistingMetadata(args.mode) || args.query.attach_short_syntax; | ||
|
|
||
| ColumnsDescription columns = args.columns; | ||
| if (columns.empty() && !loading_from_existing_metadata) |
There was a problem hiding this comment.
This only moves omitted-column schema inference under args.getLocalContext(). A Distributed definition with explicit columns still skips any local-shard SELECT / INSERT validation here, so a user can persist ENGINE = Distributed('local_cluster', db, protected) and then query it with prefer_localhost_replica = 0. In that mode SelectStreamFactory / DistributedSink send the local shard through a real remote connection, and ClusterProxy::updateSettingsForCluster explicitly notes that without a cluster secret the shard user differs from the initiator (src/Interpreters/ClusterProxy/executeQuery.cpp:159-166), so the request runs under cluster credentials instead of the caller's rights. Remote already closes this exact hole at src/Storages/StorageDistributed.cpp:2663-2675; Distributed needs the same SELECT / INSERT check when the definition is first introduced (CREATE, full-definition ATTACH, RESTORE), not only when columns.empty().
There was a problem hiding this comment.
🕵 The explicit-column case is a pre-existing design point of master, not something this PR introduced or can change without breaking a master test: #113220 (merged today) deliberately pins it in 04715_distributed_infer_columns_access.sh — "3. explicit columns, no rights on the target: still allowed" (and case 2 allows a structure-less CREATE with only SHOW_COLUMNS). Requiring the caller's own SELECT/INSERT on the target would make this PR red on that untouched test, and unlike the new Remote engine (strict from day one), Distributed has long-standing deployments where the creator of a distributed table does not hold INSERT on the underlying table. After merging master, this PR no longer touches registerStorageDistributed at all — it is reduced to the zero-initiator-version fix in getStructureOfRemoteTableInShard plus its tests. Tightening the explicit-column path for Distributed is a real design question, but it belongs to a separate discussion against master's pinned behavior, not to this bug fix.
Build profile diff (arm_release)Comparing ✅ No significant changes. 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. Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
|
||
| finalizeDistributedSettings(distributed_settings, context); | ||
|
|
||
| /// When the structure is not specified, infer it from the remote table under the user's |
There was a problem hiding this comment.
🕵 Done — after merging master, the long comment block is gone entirely: #113220 landed an equivalent inference fix with a much shorter comment, so this PR no longer modifies StorageDistributed.cpp at all.
…ucture-fetch-client-version # Conflicts: # src/Storages/StorageDistributed.cpp
…ucture-fetch-client-version
…e from legacy column-less metadata After #113220, a plain `CREATE` infers the omitted structure under the user's context and `addColumnsDescriptionToCreateQueryIfNecessary` persists the inferred columns into the stored definition, so the `CREATE`-based tests no longer reach the constructor's global-context structure fetch. The remaining zero-version path is a column-less definition loaded from metadata written by an older server version, which `DatabaseOnDisk::createTableFromAST` deliberately loads with empty columns. The new test simulates such legacy metadata by stripping the persisted column list while the table is detached; before the fix in `getStructureOfRemoteTable` the re-`ATTACH` failed with the logical error `Sending a distributed query with unknown (zero) client version`.
|
🕵 Status of the two red checks on commit 7115c39, both unrelated to this change:
The |
…ucture-fetch-client-version
…tch` The new test `test_structure_less_distributed_loaded_from_legacy_metadata` edits the table's metadata `.sql` file on the local disk, but in the "db disk" CI variant the database metadata is stored on a remote `plain_rewritable` disk, so the file does not exist and the test failed with "No such file or directory": https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113675&sha=8bb313a080b9b7f7349a5e22695e81b03789c493&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan,%20db%20disk,%20old%20analyzer,%202/6) Co-Authored-By: Claude Fable 5 <[email protected]>
…ucture-fetch-client-version
Address review: the `ATTACH` in `test_structure_less_distributed_loaded_from_legacy_metadata` throws on unfixed code, and the table then stayed detached: `DROP TABLE IF EXISTS` only sees attached tables, so repeated runs on the module-scoped cluster (flaky-check) cascaded into `TABLE_ALREADY_EXISTS ... (detached)` setup failures. Switch the `DETACH` to `SYNC` and add a detached-table recovery that restores the backed-up metadata (bringing the column list back, so the recovery `ATTACH` needs no structure inference and succeeds even on unfixed code), mirroring `test_part_loading_tree_rollback`. Verified both ways locally: with the fix, all 4 tests pass; on a stale unfixed binary the test fails at `ATTACH` with the original logical error and the recovery in `finally` cleans up without breaking the following tests.
|
🕵 Both stress-test failures on |
|
A fix PR is already open: #113933, which It is the same mechanism, not merely the same STID. The failing frame on Origin is my merged #112831, as the issue records. One thing worth a look while that is in review: #113534 is still open and addresses the same mixed-condition-over-dictionary family one layer up ( |
|
🕵 Status of commit 63b38b0: the only red check is Everything else is green, including |
…ucture-fetch-client-version
|
🕵 Status of commit d6e21a7: both red checks are unrelated to this change.
Neither fix has landed on |
…ucture-fetch-client-version
|
🕵 Merged |
Closes: #113671
Caused by: #109408
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error
Sending a distributed query with unknown (zero) client versionwhen a structure-lessDistributedtable over a remote shard is attached or loaded from metadata written by an older server version.A structure-less
Distributeddefinition has to fetch the structure of the remote table with aDESC TABLEservice query. When the definition is loaded from metadata with no persisted column list,StorageDistributed's constructor sends that query under the storage's global context, which carries no client version, so the hardening check from #109408 rejected it with a logical error and the table failed to attach or load. The fix stamps the server's own version on the service-query context ingetStructureOfRemoteTablewhen the version is unknown, the same wayDDLTaskBase::makeQueryContextdoes for distributed DDL.Modern servers persist the inferred structure into the stored definition (
InterpreterCreateQuery::addColumnsDescriptionToCreateQueryIfNecessary), but metadata written by older versions can still be column-less, andDatabaseOnDisk::createTableFromASTdeliberately loads such definitions with empty columns. The regression test simulates this legacy metadata by stripping the persisted column list from the stored definition while the table is detached: before the fix, the re-ATTACHfailed with the logical error above.The bug was originally found by BuzzHouse fleet-wide across at least 19 unrelated PRs since 2026-08-04, e.g. this report on #110179, where the same zero-version fetch was reached from a plain
CREATE. ThatCREATEpath was moved under the user's context onmasterin the meantime via #113220, so this PR is reduced to the client-version fix for the metadata-load path and its tests. The integration testtest_distributed_structure_fetchalso keeps coverage for the directCREATE, theSHOW_COLUMNSaccess check of the structure inference over a local shard, and theReplicated-databaseDDLWorkerreplay that BuzzHouse hit.Related: #113220
Version info
26.8.1.1260(included in26.8and later)