Repository navigation
Fix zero initiator version in the table listing of Remote and Cluster databases - #122661
PedroTadim merged 1 commit into
Conversation
… databases `DatabaseRemote::fetchTablesList` sends `SELECT name FROM system.tables ...` to a remote replica with a copy of its caller's context. When the server lists a remote-only database by itself (the shutdown drain, `reloadDisksTask`, the `Merge` metadata checks and the `Alias` target lookup under their own global context, the metadata loader's dependency check), that context is the global one, whose client version is 0.0.0, and the zero-version fence in `RemoteQueryExecutor::sendQueryUnlocked` throws `LOGICAL_ERROR`. Debug and sanitizer builds abort. Release builds either swallow it in `getTablesIterator` (an empty listing, so a trivial `count()` through `merge` returns 0) or propagate it from `isTableExist` (a server whose dictionary reads such a table fails to start). Fill a zero client version with this server's own version on the listing query's context, the same guard `getStructureOfRemoteTable` applies to the `DESC TABLE` of the same tables. User queries always carry a version, so they are forwarded unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; 1 full pass).
Own review (no blocker or major): the shutdown drain and Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20260928-102100 |
|
Workflow [PR], commit [13be46f] Summary: ✅
AI ReviewSummaryThis PR backfills the initiator version for Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit 13be46f.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
|
||
| /// The server lists the tables on its own under the global context (e.g. at shutdown), which has | ||
| /// no client version, and `RemoteQueryExecutor` refuses to send a query without one. | ||
| const auto & client_info = query_context->getClientInfo(); |
There was a problem hiding this comment.
🕵️
@groeneai This is the third site to need this exact guard: distributed INSERT replay (ef79cb1, 4f78c0c), DESC TABLE in getStructureOfRemoteTable.cpp:105-108 (#113675), and now fetchTablesList. Each was found the same way, by the #109408 fence firing in production.
Filling the version at the fence itself would defeat it, since its job is catching contexts that lost their version. But three verbatim copies want one helper, e.g. setInitiatorVersionIfUnset(context), plus a comment at the fence pointing to it, so the next internal caller built from the global context has something to reach for. Not a blocker here — fine as a follow-up.
There was a problem hiding this comment.
Agreed. It is more than three copies: master already has the same fill in Context::makeQueryContext, Session::makeQueryContextImpl, StorageMaterializedView::createRefreshContext, the scalar subquery context in ExecuteScalarSubqueriesVisitor, getStructureOfRemoteTable, and DistributedAsyncInsertHeader::read (on a bare ClientInfo), so this is the seventh. I will keep this PR to the one site, since the bug also reaches 26.8 and 26.9 and a one-site fix keeps a backport small, and send a follow-up PR that replaces all seven with one helper and adds a comment at the fence pointing to it.
There was a problem hiding this comment.
Follow-up: #122766. It moves the six copies on master to ClientInfo::setInitiatorVersionIfUnset (with a one-line Context forwarder) and adds the pointer comment at the fence. The copy added here moves to the helper once this PR merges: in #122766 if that one is still open, otherwise in a one-line follow-up.
|
After this gets merged, I am going to update #122766 |
…rough the helper ClickHouse#122661 added a seventh copy of the fill, in `DatabaseRemote::fetchTablesList`. It now calls `setInitiatorVersionIfUnset` like the other six, and the two includes it needed only for `VERSION_*` and `DBMS_TCP_PROTOCOL_VERSION` are removed. No behavior change. Requested in ClickHouse#122766 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Six places open-coded the same fill of a zero client version with this server's version: `Context::makeQueryContext`, `Session::makeQueryContextImpl`, `StorageMaterializedView::createRefreshContext`, the scalar subquery context in `ExecuteScalarSubqueriesVisitor`, `getStructureOfRemoteTableInShard` and `DistributedAsyncInsertHeader::read` (on a bare `ClientInfo`). Each copy was added after the zero-version check in `RemoteQueryExecutor::sendQueryUnlocked` (ClickHouse#109408) fired for another server-built context, and each repeated the same rationale in its comment. Move the logic into `ClientInfo::setInitiatorVersionIfUnset` (next to its sibling `setClientVersionFromConnectionIfUnknown`), add a one-line `Context::setInitiatorVersionIfUnset` forwarder for the context sites, and keep only the site-specific sentence at each call site. The protocol version is still set unconditionally together with the three version fields, exactly as every copy did, so there is no behavior change. The check in `RemoteQueryExecutor` still throws. Its comment now points to the helper and says not to fill the version there, because the check exists to catch a context that lost it. The stale "whether to enable the analyzer" example is dropped: the old analyzer is gone. Not converted on purpose: `DDLTask` sets the version unconditionally (this host re-initiates the DDL), and `setClientVersionFromConnectionIfUnknown` fills from the connection hello, a different source. The same fill in `DatabaseRemote::fetchTablesList` comes with ClickHouse#122661, which is not merged yet, and moves to the helper once it is. Includes that the original fills added only for `VERSION_*` and `DBMS_TCP_PROTOCOL_VERSION` are removed. Requested in ClickHouse#122661 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #122612
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
RemoteorClusterdatabase without a local shard makingSELECT count()through themergetable function return 0, and making the server fail to start when a dictionary reads one of its tables. The server now sends its own version when it lists the tables of such a database by itself, which also removes theLOGICAL_ERRORlogged at shutdown. Closes #122612.Description
On 26.9.4.3, with a
Remotedatabase whose only shard is remote,SELECT count() FROM merge('<db>', '^t$')returns 0 instead of the row count (26.8.10.6 too), and a server with a dictionary reading a table of that database fails to start (Caught exception while loading metadata: Code: 49 ... LOGICAL_ERROR). This is the report from #122612, not a CI failure.DatabaseRemote::fetchTablesList(shared byRemote,RemoteSecureandCluster) sends itssystem.tablesquery with a copy of the caller's context. When the server lists such a database by itself, that is the global context, whose client version is 0.0.0, and the fence from #109408 inRemoteQueryExecutorrefuses to send the query. Release builds mostly swallow the error and see an empty list (hence the 0),isTableExistpropagates it (hence the failed start), and debug and sanitizer builds abort.The fix fills a zero version with the server's own, the guard
getStructureOfRemoteTablealready applies to theDESC TABLEof the same tables (#113675). It is one site, the onlyRemoteQueryExecutorinDatabaseRemote, so it also coversDatabaseRemote::empty(the issue's open risk; nothing calls it for this engine today). User queries always carry a version and are unchanged.Routes measured on a master debug build, before and after: shutdown (abort, then clean),
SYSTEM RELOAD CONFIGadding a disk to a policy (server abort, then alive), name hints for anAliaswhose target was dropped (server abort, thenUNKNOWN_TABLE),merge()(abort, then the right count), a dictionary dependency at startup (abort, then starts), andmerge()plus shutdown through aClusterdatabase. These routes now finish the listing they had already connected for, e.g. shutdown sends one listing and oneDESC TABLEper table.The new test fails on master (debug: exit code 134; 26.9.4.3: count 0) and passes with the fix, 50/50 runs.
Workflow [PR]
Sync PR [sync-upstream/pr/122661]
Version info
26.10.1.1008-master(included in26.10and later)