Skip to content

Resolve the lazy-load table stand-in before the replica status request - #118152

Merged
alexey-milovidov merged 25 commits into
masterfrom
lazy-load-tables-status-117441
Oct 13, 2026
Merged

alexey-milovidov merged 25 commits into
masterfrom
lazy-load-tables-status-117441

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

With lazy_load_tables the catalog holds a stand-in (StorageTableProxy) for a table until the table is first accessed, and a dynamic_cast of the catalog object to a concrete engine fails for it. Most of the affected call sites (the replica status request in TCPHandler, SelectStreamFactory, ReadFromRemote, the SYSTEM replica and MergeTree commands, the system tables, /replicas_status, the asynchronous metrics, OPTIMIZE, CREATE TABLE ... AS, hypothetical objects, DELETE) have meanwhile been fixed on master by castStorage<T>(storage, DeferredTable::Load/Skip), resolveStorageProxy and resolveStorageProxyLoading (#121332). This PR was reconciled with that: its own helpers are dropped, and what remains is:

  • StorageProxy forwards supportsDelete, supportsLightweightDelete, supportsLightweightUpdate, updateLightweight and checkMutationIsPossible, so DELETE, UPDATE and ALTER ... DELETE/UPDATE no longer refuse a lazily loaded MergeTree table based on the stand-in's answers.
  • The guard in SYSTEM DROP REPLICA ... FROM ZKPATH that 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 the is_active check 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 stored CREATE TABLE query the way loading it would resolve them (extractZnodeInfoFromReplicatedTableDef).
  • Tests: the stateless tests for the replica commands (including SYSTEM DROP REPLICA ... FROM ZKPATH), the mutation surfaces, the MergeTree commands and system.parts, OPTIMIZE/CREATE ... AS, DELETE with lightweight_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):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

DELETE, UPDATE and ALTER ... DELETE/UPDATE no longer refuse a MergeTree table of a database with lazy_load_tables that has not been accessed yet, and SYSTEM DROP REPLICA ... FROM ZKPATH no 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

  • Merged into: 26.10.1.2333-master (included in 26.10 and later)

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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d91ea8b]

Summary: ✅


AI Review

Summary

This PR makes lazy StorageTableProxy tables transparent in the remaining mutation entrypoints and hardens SYSTEM DROP REPLICA ... FROM ZKPATH so an untouched lazy local replica is still recognized without materializing every lazy table. I read the current diff, the current code, the top-level PR discussion, and every inline review thread; I do not see a remaining contract violation in the current version.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 4, 2026
Comment thread src/Server/TCPHandler.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. label Sep 4, 2026
@zlareb1

zlareb1 commented Sep 4, 2026

Copy link
Copy Markdown
Member

TL;DR: the fix resolves the stand-in on the remote leg (TablesStatus), but the initiator-local leg of the same staleness gate has the identical cast and stays broken: with prefer_localhost_replica = 1 (the default) and the Distributed table co-located with a lazy replica, max_replica_delay_for_distributed_queries is never consulted and the stale local rows are served silently. The /replicas_status handler has the same blind cast. Both are permanent, not first-access-only.

1. The local-replica leg of the gate is skipped.

SelectStreamFactory::createForShard fetches the local storage from the catalog and casts it (src/Interpreters/ClusterProxy/SelectStreamFactory.cpp:238, :267). For a table in a lazy_load_tables database the catalog returns the stand-in, the cast fails, and the !replicated_storage branch comments "Table is not replicated, use local server" and calls emplace_local_stream (:269-273) — skipping the max_replica_delay_for_distributed_queries check, fallback_to_stale_replicas_for_distributed_queries, and the ALL_REPLICAS_ARE_STALE exception entirely.

Scenario: same as this PR's test, except the Distributed table lives on the lazy replica itself (a very common topology) instead of a separate initiator. The query then never sends a TablesStatus request — it takes the local branch, and the fixed handler is not involved. The read goes through the stand-in to the cold local table.

2. The miss is permanent, not a first-access race.

StorageTableProxy::getNested caches the nested storage inside the proxy and the catalog entry is never swapped (src/Storages/StorageTableProxy.h:55-69), so every dynamic_cast to StorageReplicatedMergeTree on a catalog-obtained pointer keeps failing for the whole process lifetime, even long after the table has materialized and is actively lagging.

3. Same cast in the /replicas_status handler.

src/Server/ReplicasStatusHandler.cpp:75-78 skips any table whose cast fails, so a lazy replicated table never contributes its delay — before or after materialization. The comment above it ("If they have some lag it will be reflected as soon as they are load") is written for async_load_databases and does not hold for stand-ins. A load balancer using min_absolute_delay_to_close keeps routing to an arbitrarily stale lazy replica — the same silent-stale-read outcome through the HTTP sibling of the surface this PR fixes on TCP.

4. Census of the remaining blind casts (monitoring/admin rather than query results, listed for completeness): tryRestartReplica and the SYSTEM RESTART REPLICAS filter, dropStorageReplica including the DROP REPLICA ... FROM ZKPATH safety scan that protects live local tables, system.replicas, system.replication_queue, system.part_moves_between_shards.

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.

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d91ea8b09 with master b137629d5 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

76 translation units recompiled, 791 s compile time in total, 76 of them have a recent master baseline.

Job report

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.
alexey-milovidov and others added 2 commits September 10, 2026 23:56
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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @zlareb1 all four points are covered now.

  1. The initiator-local leg of the staleness gate: SelectStreamFactory::createForShard resolves the stand-in before the cast, so with prefer_localhost_replica = 1 a co-located lazy replica goes through max_replica_delay_for_distributed_queries, fallback_to_stale_replicas_for_distributed_queries and ALL_REPLICAS_ARE_STALE like any other replica. ReadFromRemote does the same on its leg.
  2. The permanence of the miss: that is why every inspecting surface resolves the stand-in rather than relying on a first-access race. resolveLazyTableIfLoaded returns the loaded table and nullptr for one that is still untouched, so inspecting never loads the catalog.
  3. /replicas_status: the handler resolves the stand-in too, so a loaded lazy replicated table contributes its delay to min_absolute_delay_to_close.
  4. The census: tryRestartReplica, the SYSTEM RESTART REPLICAS filter, dropStorageReplica including the DROP REPLICA ... FROM ZKPATH safety scan, system.replicas, system.replication_queue and system.part_moves_between_shards all resolve the stand-in - the admin commands with the loading resolveLazyTable (an explicit command on a named table is an access to it), the inspecting surfaces with resolveLazyTableIfLoaded. The mutation surfaces (system.mutations, NumberOfPendingMutations, NumberOfDetachedParts) were the remaining hole and are fixed in 41110ef.

On resolving centrally instead: StorageTableProxy deliberately keeps wrapping the table, because the catalog entry is what DETACH/ATTACH/DROP and the metadata operations hold, so swapping it on materialization is a much larger change than this bug fix. The two helpers in StorageTableProxy.h at least make the choice explicit at each site: load, or see only what is loaded.

Tests: 05076_lazy_load_tables_replicated_commands, 05175_lazy_load_tables_mutations_visibility and the integration test test_lazy_load_tables_replica_status, which covers the distributed staleness gate on both legs.

alexey-milovidov and others added 2 commits September 18, 2026 08:30
…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]>
Comment thread src/Storages/StorageTableProxy.h Resolved
Comment thread src/Storages/StorageTableProxy.h Resolved
Comment thread src/Storages/StorageTableProxy.h Resolved
Comment thread src/Storages/StorageTableProxy.h Resolved
alexey-milovidov and others added 2 commits September 25, 2026 14:49
…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]>
@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. and removed comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. labels Sep 25, 2026
Comment thread src/Storages/StorageProxy.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

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.

clickbench

⚠️ 5 inconclusive

Flagged queries (5 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 16 not_sure 529 584 +10.3% <0.0001 The PR median of 583.5 ms falls inside master's recent range, and the diff only changes ALTER, SYSTEM DROP REPLICA and lazy-load table code, which this SELECT does not run.
⚠️ 18 not_sure 844 967 +14.6% 0.0058 The PR median of 967 ms falls inside master's recent range, and this query has a noisy history. No changed code path runs in a plain ClickBench SELECT.
⚠️ 28 not_sure 1001 1094 +9.3% <0.0001 The +9.3% shift is borderline: the two tests disagree and the measurements were noisy on both sides. The diff does not touch the SELECT execution path.
⚠️ 33 not_sure 1127 1070 -5.1% <0.0001 aggregation: The -5.1% gain and lower CPU cannot come from this diff, which only changes mutation checks, SYSTEM DROP REPLICA and lazy-load table forwarding. This query has a noisy history on master.
⚠️ 34 not_sure 1123 1049 -6.6% <0.0001 aggregation: The -6.6% gain sits next to the similar Q33 change, but neither query runs any changed code. The shared shift is run-to-run variance on a query with a noisy history.

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
  • StressHouse run: a508c2a3-5803-4bdf-a861-f596fbc943c8
  • MIRAI run: 5be17f1c-d603-4463-b0b9-05024924d4d5
  • PR check IDs:
    • clickbench_25415_1791923866
    • clickbench_25633_1791923892
    • clickbench_25756_1791923971
    • tpch_adapted_1_official_25860_1791923975
    • tpch_adapted_1_official_25887_1791923976
    • tpch_adapted_1_official_26081_1791923981

@alexey-milovidov

Copy link
Copy Markdown
Member Author

First we will handle #118699

alexey-milovidov and others added 2 commits October 3, 2026 21:15
`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.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and resolved the conflicts. Master gained castStorage / DeferredTable / resolveStorageProxyLoading (#121332), which covers the same call sites as this PR's resolveLazyTable / resolveLazyTableIfLoaded, so the conflicts took master's side and the PR's helpers were dropped. What remains is the StorageProxy mutation forwarders, DeferredTable::Load in the server-wide guard of SYSTEM DROP REPLICA ... FROM ZKPATH (master skips unloaded tables there), and the tests. The build passes, and the PR's stateless tests pass locally. The description is updated to match.

Comment thread src/Storages/StorageProxy.h Resolved
alexey-milovidov and others added 2 commits October 6, 2026 19:03
… 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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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 (02993_lazy_index_loading: primary key memory reported as 0 instead of ~10 million; it also failed on master-based PR #106734 on 2026-09-29 and does not touch the lazy table loading this PR changes) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged. I'm investigating why 02993_lazy_index_loading reports 0 primary key bytes after the PK read on a local disk (there is no fix in progress yet); I'll follow up here with a PR (or my findings) shortly.

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

The cause is this PR's new test 05228_lazy_load_tables_merge_tree_commands_and_parts.sql: line 26 runs the server-wide SYSTEM UNLOAD PRIMARY KEY;, which unloads the primary key of every MergeTree table on the server, and the test is not no-parallel.

From the failing job's query_log:

  • 04:37:36.754 to 04:37:40.957: 02993 runs the PK read (WHERE s < '9999999999'), which loads the index.
  • 04:37:37.320 to 04:37:40.857: 05228 runs SYSTEM UNLOAD PRIMARY KEY; (it walks every test database, hence 3.5 s).
  • 04:37:40.959: 02993's check reads 0.

The 16 reruns had no concurrent unload and passed. The master tests that use the server-wide form (03128_system_unload_primary_key, 03202_system_load_primary_key) are no-parallel for this reason.

Since 05228 exists only on this branch, the fix belongs in this PR rather than a separate one: either add no-parallel to 05228's tags, or move the server-wide SYSTEM UNLOAD PRIMARY KEY check into a small separate no-parallel test so the rest of 05228 keeps running in parallel.

The 2026-09-29 failure on #106734 is a different shape (the index was already loaded after ATTACH: 10081008 instead of 0), caused by that PR's new randomization of primary_key_lazy_load (the runner minimized it to primary_key_lazy_load = False, 217 of 217 reruns failed).

alexey-milovidov and others added 2 commits October 7, 2026 06:50
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai, good catch. Moved the server-wide SYSTEM UNLOAD PRIMARY KEY check out of 05228_lazy_load_tables_merge_tree_commands_and_parts into a small no-parallel test 05332_lazy_load_tables_unload_primary_key_server_wide, so the rest of 05228 keeps running in parallel (f1a272d). Also fixed the style check in 05331_lazy_load_tables_heavy_update_key_column (it now filters by currentDatabase()). All three tests pass locally.

alexey-milovidov and others added 3 commits October 7, 2026 23:06
…`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

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 13, 2026
Merged via the queue into master with commit a9b0feb Oct 13, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the lazy-load-tables-status-117441 branch October 13, 2026 22:40
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
alexey-milovidov added a commit to evillique/ClickHouse that referenced this pull request Nov 2, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy-loaded (lazy_load_tables=1) ReplicatedMergeTree replica misreports as up-to-date, causing silent stale distributed reads after a restart

4 participants