Repository navigation
Resolve the lazy-load table stand-in before the replica status request - #118152
Conversation
With `lazy_load_tables` the catalog holds a stand-in for a table until the table is first accessed. `TCPHandler::processTablesStatusRequest` casts the catalog object to `StorageReplicatedMergeTree` to fill in the replication delay, and the stand-in is not one, so the handler answered `is_replicated = false`. The initiator reads that as "not replicated, hence no delay, hence up to date", and `max_replica_delay_for_distributed_queries` never fires: a distributed query routed to a replica that had just restarted and had not started fetching yet silently returned the replica's cold local rows. Resolve the stand-in in the handler - the query this status request precedes is about to read the table anyway - and in `SYSTEM SYNC REPLICA`, which reported the same table as not replicated for the same reason. Closes: #117441 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [d91ea8b] Summary: ✅
AI ReviewSummaryThis PR makes lazy Final Verdict
|
|
TL;DR: the fix resolves the stand-in on the remote leg ( 1. The local-replica leg of the gate is skipped.
Scenario: same as this PR's test, except the 2. The miss is permanent, not a first-access race.
3. Same cast in the
4. Census of the remaining blind casts (monitoring/admin rather than query results, listed for completeness): Given how many sites cast the catalog object, resolving the proxy centrally (in the catalog or on materialization) may age better than per-site unwrapping. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units76 translation units recompiled, 791 s compile time in total, 76 of them have a recent master baseline. |
With `lazy_load_tables` the catalog holds a stand-in for a table until the table is first accessed, and a stand-in is not the engine it stands in for, so a `dynamic_cast` of the catalog object to `StorageReplicatedMergeTree` fails for it - silently, and for as long as the server runs, because `StorageTableProxy` caches the loaded table inside itself and the catalog entry is never swapped. `TCPHandler::processTablesStatusRequest` was fixed for this, but that is only the leg of the staleness gate a remote replica answers. Two more read the same catalog object: * `SelectStreamFactory::createForShard` takes the query to the local replica without consulting the replication delay at all when the cast fails. With `prefer_localhost_replica = 1` (the default) and the `Distributed` table on the lazy replica itself, no `TablesStatus` request is ever sent, so this leg served stale rows on its own, `fallback_to_stale_replicas_for_distributed_queries = 0` included. * `ReadFromRemote::addLazyPipe` reads the local delay once more for the fallback from a stale remote replica back to the local one, and reports anything that is not replicated as a `LOGICAL_ERROR` - which is what the fix above would have started running into. Both are resolved through a new `resolveLazyTable`, and `TCPHandler` is moved onto it. Its counterpart `resolveLazyTableIfLoaded` is for the callers that only inspect tables, added here for the commits that follow.
`SYSTEM SYNC REPLICA` was already fixed; `SYSTEM RESTORE REPLICA`, `SYSTEM RESTART REPLICA` and `SYSTEM DROP REPLICA` refused a lazily loaded table as not replicated for the very same reason. A command addressed to one table is an access to it, so it resolves the stand-in. `SYSTEM DROP REPLICA ... FROM ZKPATH` resolves stand-ins as well: its scan of the local tables is what keeps the drop from destroying the ZooKeeper metadata of a live local table, and a table that nothing has accessed holds no ZooKeeper session, so the `is_active` check does not catch it either - skipping it silently is the destructive outcome. `SYSTEM RESTART REPLICAS` instead resolves only the stand-ins that are already loaded: a table nothing has accessed has started no replication to restart, and loading the whole catalog to find that out is what `lazy_load_tables` exists to avoid.
A lazily loaded table was missing from `/replicas_status`, `system.replicas`, `system.replication_queue`, `system.part_moves_between_shards` and the replica-delay asynchronous metrics for as long as the server ran, loaded or not, because they all identify a replicated table by casting the catalog object. A load balancer reading `/replicas_status` with `min_absolute_delay_to_close` therefore kept routing to an arbitrarily stale replica - the HTTP sibling of the silent stale read on the query path. These callers only inspect tables, and the whole catalog at once, so they resolve the stand-in through `resolveLazyTableIfLoaded`: a table that some query has already loaded is reported, and one nothing has touched is left alone rather than being loaded by a monitoring request. `StatusRequestsPool` needs the same treatment for a different reason: it re-resolves the table from the catalog by UUID when the request reaches the pool, so that a dropped or renamed table is handled gracefully, and got the stand-in back even though the caller had enqueued the resolved storage - the row was then dropped as "replaced by an object of another type".
The integration test gains the topology where the `Distributed` table sits on the lazy replica itself, which is what the default `prefer_localhost_replica = 1` turns into a local read: one shard holding only that replica, so a stale verdict has nowhere to fall back to and surfaces as `ALL_REPLICAS_ARE_STALE`, and one shard that also holds the up-to-date replica, which takes the query through the delayed remote source instead. The new stateless test covers what does not need a second server: `SYSTEM SYNC REPLICA`, `SYSTEM DROP REPLICA` and `SYSTEM RESTART REPLICA` addressed to a stand-in, and a table appearing in `system.replicas` once it is loaded while an untouched one stays out of it. A stand-in only appears after the database is loaded, hence the `DETACH DATABASE` / `ATTACH DATABASE` round trip before each of them.
`SYSTEM DROP REPLICA` reaches server-wide state, so the style check requires the `no-parallel` tag, and the system table filters have to be written as `database = currentDatabase()`, which is what the `USE` of the lazy database gives them - the same shape `03823_lazy_load_tables` uses.
A loaded lazy table also stayed missing from `system.mutations`, `NumberOfPendingMutations` and `NumberOfDetachedParts`: they identify a `MergeTreeData` by casting the catalog object, and the stand-in keeps wrapping the table it stands in for after the table has been loaded. Resolve the stand-in in `StorageSystemMutations::fillData` and in `ServerAsynchronousMetrics::updateMutationAndDetachedPartsStats`, with `resolveLazyTableIfLoaded` as in the replica surfaces - inspecting tables must not be what loads them and defeats `lazy_load_tables`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @zlareb1 all four points are covered now.
On resolving centrally instead: Tests: |
…m.parts` Address review: the `MergeTree`-family `SYSTEM` commands and `StorageSystemPartsBase` still cast the catalog object directly to `MergeTreeData`, so with `lazy_load_tables` `SYSTEM WAIT LOADING PARTS`, `SCHEDULE MERGE`, `SYNC MERGES`, `LOAD`/`UNLOAD PRIMARY KEY` and `PREWARM MARK CACHE`/`PREWARM PRIMARY INDEX CACHE` refused a lazy table as not `MergeTree`, and a loaded lazy table stayed missing from `system.parts`, `system.parts_columns`, `system.projection_parts` and `system.projection_parts_columns` for as long as the server ran. A command addressed to a table resolves the stand-in through `resolveLazyTable` (loading the table is what the user asked for). The server-wide scans (`SYSTEM RESTART DISK`, the table-less `LOAD`/`UNLOAD PRIMARY KEY`) and `system.parts*` only inspect, so they use `resolveLazyTableIfLoaded` and skip untouched stand-ins. The mutations test is renumbered to 05227 because 05175 is taken on master. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ZE DRY RUN`, hypothetical objects and `CREATE ... AS` `StorageProxy` now forwards `supportsDelete`, `supportsLightweightDelete`, `supportsLightweightUpdate`, `checkMutationIsPossible` and `updateLightweight`, so `DELETE`, `UPDATE` and `ALTER ... DELETE/UPDATE` no longer refuse a `MergeTree` table of a database with `lazy_load_tables`. `InterpreterOptimizeQuery` (`DRY RUN`), `InterpreterHypotheticalObjectQuery`, `InterpreterCreateQuery` (`CREATE TABLE ... AS`, `CLONE AS`, and the `Alias` privilege check) and `REPLACE/ATTACH PARTITION ... FROM` resolve the stand-in with `resolveLazyTable` before casting it or reading its definition. For `CREATE ... AS` the lock is still taken on the catalog object. Test `05257_lazy_load_tables_mutations_optimize_create_as`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes ALTER mutation validation order, the SYSTEM DROP REPLICA guard, and how lazy-load tables forward calls to the table they wrap. None of that runs during the read-only ClickBench and TPC-H SELECTs. So the two flagged improvements (Q33 at -5.1%, Q34 at -6.6%) are downgraded to not sure, and the borderline slowdowns on Q16, Q18 and Q28 stay not sure. The deterministic suppression of Q16 and Q18 is consistent with the data: both PR medians fall inside master's recent range, and no changed code path explains them. No performance impact is expected from this change. clickbenchFlagged queries (5 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
First we will handle #118699 |
`DELETE FROM` took its metadata snapshot from the `lazy_load_tables` stand-in before the forwarded `supports*` probes loaded the table, so the snapshot had no projections and the `MergeTreeData` cast failed. As a result, `lightweight_mutation_projection_mode = 'throw'` was ignored on an untouched lazy table and the lightweight delete went ahead, dropping projections. Resolve the stand-in right after looking the table up, as `OPTIMIZE` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…atus-117441 Master introduced `castStorage` with `DeferredTable`, `resolveStorageProxy` and `resolveStorageProxyLoading`, which cover the same call sites as this PR's `resolveLazyTable` / `resolveLazyTableIfLoaded`. The conflicts are resolved in favor of master's helpers, and the PR's helpers are dropped. The only call site where the PR's semantics differ is kept: the server-wide guard of `SYSTEM DROP REPLICA ... FROM ZKPATH` loads lazily loaded tables (`DeferredTable::Load`) instead of skipping them.
|
🕵 Merged master and resolved the conflicts. Master gained |
…y the style check Co-Authored-By: Claude Opus 5.5 <[email protected]>
… lazy table In `runCommandSegments` the metadata snapshot of a mutation segment was taken before `checkMutationIsPossible`, which is what loads the nested table behind a `StorageTableProxy`. On an untouched stand-in the snapshot was then the columns-only metadata, so `MutationsInterpreter` saw no sorting key, partition key or projections, and e.g. a heavy `ALTER ... UPDATE` of a key column passed the upfront `Cannot UPDATE key column` check and failed later as an asynchronous mutation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118152&sha=bf9cc16af2c645086b0db2935ee60368ac0d8820&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 ( |
|
Acknowledged. I'm investigating why |
|
The cause is this PR's new test From the failing job's
The 16 reruns had no concurrent unload and passed. The master tests that use the server-wide form ( Since 05228 exists only on this branch, the fix belongs in this PR rather than a separate one: either add The 2026-09-29 failure on #106734 is a different shape (the index was already loaded after |
…allel` test The server-wide `SYSTEM UNLOAD PRIMARY KEY` in `05228_lazy_load_tables_merge_tree_commands_and_parts` unloaded the primary keys of concurrent tests, which broke `02993_lazy_index_loading`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118152&sha=bf9cc16af2c645086b0db2935ee60368ac0d8820&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 #118152 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ey_column` to satisfy the style check Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks @groeneai, good catch. Moved the server-wide |
…`SYSTEM DROP REPLICA ... FROM ZKPATH`
The guard that refuses to drop the replica of a live local table loaded every
lazily loaded table in every database to compare Keeper paths. That defeats
`lazy_load_tables` and lets one slow or broken table block cleanup of an
unrelated dead replica. A table that is not loaded yet now has its path,
replica name and Keeper name resolved from the stored `CREATE TABLE` query the
way loading it would (new `extractZnodeInfoFromReplicatedTableDef`), so it is
neither loaded nor silently skipped.
Adds a stateless test for the `FROM ZKPATH` branch, with an explicit path and
a path made of `{uuid}`, `{shard}` and `{replica}` macros.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in `registerStorageMergeTree.cpp`: master added the `validate_injected_defaults` argument to `extractZooKeeperPathAndReplicaNameFromEngineArgs`; kept the PR's `extractZnodeInfoFromReplicatedTableDef` and pass `false` for it there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/InterpreterAlterQuery.cpp
Master gained its own fixes for two things this PR also did: - ClickHouse#118135 finishes a pending conversion to `ReplicatedMergeTree` for a deferred table by materializing it in `restoreMetadataAfterConvertingToReplicated`. Drop this PR's `converting_to_replicated` set, which kept such tables eager for the same purpose, and its integration test, which `test_modify_engine_on_restart/test_lazy_load_tables.py` covers. - ClickHouse#118152 made `StorageProxy` forward `checkMutationIsPossible`, `supportsDelete`, `supportsLightweightDelete`, `supportsLightweightUpdate` and `updateLightweight`. Drop this PR's second copy of the same overrides, which no longer compiled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With
lazy_load_tablesthe catalog holds a stand-in (StorageTableProxy) for a table until the table is first accessed, and adynamic_castof the catalog object to a concrete engine fails for it. Most of the affected call sites (the replica status request inTCPHandler,SelectStreamFactory,ReadFromRemote, theSYSTEMreplica andMergeTreecommands, the system tables,/replicas_status, the asynchronous metrics,OPTIMIZE,CREATE TABLE ... AS, hypothetical objects,DELETE) have meanwhile been fixed on master bycastStorage<T>(storage, DeferredTable::Load/Skip),resolveStorageProxyandresolveStorageProxyLoading(#121332). This PR was reconciled with that: its own helpers are dropped, and what remains is:StorageProxyforwardssupportsDelete,supportsLightweightDelete,supportsLightweightUpdate,updateLightweightandcheckMutationIsPossible, soDELETE,UPDATEandALTER ... DELETE/UPDATEno longer refuse a lazily loadedMergeTreetable based on the stand-in's answers.SYSTEM DROP REPLICA ... FROM ZKPATHthat refuses to destroy the ZooKeeper metadata of a live local table no longer skips lazily loaded tables: a table nothing has accessed holds no ZooKeeper session, so theis_activecheck does not catch it either, and skipping it silently is the destructive outcome. Such a table is not loaded either: its path, replica name and Keeper name are resolved from the storedCREATE TABLEquery the way loading it would resolve them (extractZnodeInfoFromReplicatedTableDef).SYSTEM DROP REPLICA ... FROM ZKPATH), the mutation surfaces, theMergeTreecommands andsystem.parts,OPTIMIZE/CREATE ... AS,DELETEwithlightweight_mutation_projection_mode = 'throw', and an integration test for the distributed staleness gate with a lazy replica (remote and local legs).Closes: #117441
Related: #121332
Related: #118699
Related: #117972
Related: #118135
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
DELETE,UPDATEandALTER ... DELETE/UPDATEno longer refuse aMergeTreetable of a database withlazy_load_tablesthat has not been accessed yet, andSYSTEM DROP REPLICA ... FROM ZKPATHno longer skips such a table when checking that the replica being dropped is not a live local one.Workflow [PR]
Sync PR [sync-upstream/pr/118152]
Version info
26.10.1.2333-master(included in26.10and later)