Skip to content

Fix 03823_lazy_load_tables failing when the database metadata is on a remote disk - #122047

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-03823-lazy-load-remote-database-disk
Sep 26, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-03823-lazy-load-remote-database-disk

Conversation

@groeneai

@groeneai groeneai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121703
Related: #113389

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Test-only change, no changelog entry required.

Description

03823_lazy_load_tables has never passed in Stateless tests (..., db disk, ...): 0 OK / 15 FAIL over
30 days on three PRs with code-disjoint diffs, always this line:

-t3_renamed	MergeTree
+t3_renamed	TableProxy

Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/35995830215/job/107645147776

RENAME TABLE does not load a lazy table, but creating the convenience symlink does:
DatabaseAtomic::renameTable calls tryCreateSymlink, which returns early at
!db_disk->isSymlinkSupported() one statement before table->getDataPaths(), and that call forces
getNested(). DiskLocal is the only disk answering true (DiskEncrypted forwards), so the rename
materializes the table on a local database disk but not on an object-storage one, whatever its backend.
The reference asserted a loaded engine the test never forced.

So I re-attach the database after the rename (an idiom this file already uses) and assert the engine
after the ALTER. Moving the assertion alone would fix this flavour, but where the symlink materializes
the table the ALTER stays pre-loaded and its comment asserts nothing in the flavours that pass today. A
name-only listing before the re-attach keeps the rename oracled: one row, same on either disk, and it
does not load the table.

Validation: in that check this branch is 50/50 green; the three carriers are 5/5 red. Locally, one
binary: unmodified it is 0/10 on an object-storage database disk and passes on a local one, isolating
isSymlinkSupported(); moving that listing one statement earlier reds it; logs show the load following
the ALTER, not the listing, on both disks.

The alternative is to stop tryCreateSymlink materializing the table. I did not: its target needs the
nested storage, and skipping the symlink would change the on-disk layout of every Atomic rename. Your
call.

#113389 also edits this test and would make the line disk-independent on its own, but it is a 118-file
change still in review; this patch applies cleanly either way.


Workflow [PR]
Sync PR [sync-upstream/pr/122047]

Version info

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

… remote disk

The test has never passed in the "db disk" stateless flavour: 0 OK / 10 FAIL over
30 days, on two independent PRs whose diffs are code-disjoint, always the same
single reference line:

    -t3_renamed MergeTree
    +t3_renamed TableProxy

RENAME TABLE does not load a lazy table. Creating the convenience symlink does,
and only on a metadata disk that has symlinks.

DatabaseAtomic::renameTable's attach lambda calls tryCreateSymlink for any table
whose storesDataOnDisk() is true (src/Databases/DatabaseAtomic.cpp:305-313), and
that is hardcoded true on the lazy stand-in (src/Storages/StorageTableProxy.h:70).
tryCreateSymlink opens with `if (!db_disk->isSymlinkSupported()) return;`
(src/Databases/DatabaseAtomic.cpp:648), and the very next statement is
`if (table->getDataPaths().empty()) return;` (:651). StorageProxy::getDataPaths
is `return getNested()->getDataPaths();` (src/Storages/StorageProxy.h:179), and
StorageTableProxy::getNested() constructs the real storage, starts it up and
renames it in memory, after which getName() reports the nested engine.

DiskLocal::isSymlinkSupported() (src/Disks/DiskLocal.h:113) is the only override
returning true in all of src/; IDisk's default is false (src/Disks/IDisk.h:410)
and DiskEncrypted delegates to its wrapped disk. DiskObjectStorage does not
override it. So on a local metadata disk the rename materializes the table as a
side effect of building the symlink target, while on the object-storage database
disk that the "db disk" flavour installs
(tests/config/config.d/remote_database_disk.xml) the early return fires first and
the table stays unloaded. The reference line pinned that side effect, so the test
asserted a loaded engine that it never forced.

Nothing in the lazy-load design makes RENAME load a table:
StorageTableProxy::renameInMemory deliberately renames the stand-in without
loading it. The "db disk" output is correct behaviour and the assertion is the
defect.

So re-attach the database after the rename, and assert the engine after the ALTER
that follows. DETACH/ATTACH DATABASE is the idiom this same file already uses four
times, and it makes the ALTER the first access to the renamed table in every
flavour, which is what that block's own comment has always claimed.
StorageProxy::alter (src/Storages/StorageProxy.h:117-122) opens with
getNested()->alter(...), which materializes and caches the nested storage without
going near tryCreateSymlink, so the engine the next query reports no longer
depends on the database disk. Only two statements in the block emit, in the same
order as before, so .reference is byte-identical.

The re-attach also restores coverage that a local metadata disk silently lost: the
rename's symlink used to load the table before the ALTER ever ran, so the ALTER
asserted nothing about loading there. It does now.

Validated on one binary, since the change is test-only. With the database disk on
object storage the unmodified test is 0 OK / 10 FAIL and the patched one is
50 OK / 0 FAIL; on a local database disk the patched test is also 50 OK / 0 FAIL
and the unmodified one still passes. That type=local control at the same path
isolates isSymlinkSupported() specifically rather than "any configured database
disk", plain_rewritable, object storage as such, or settings randomization.

The server log confirms the mechanism on both disks. On the object-storage disk
there are zero symlink attempts, nothing loads between the RENAME and the ALTER,
and the "Loading lazy table on first access" line lands 253 us after the ALTER
starts. On the local disk the rename still loads the pre-re-attach object 197 us
after the RENAME, and then a fresh stand-in for the renamed table is loaded 259 us
after the ALTER.

The asserted line comes from 03312e2, not from 088f3f5, which added
only the Alias line and passes in this flavour.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 blocker found and fixed, 2 rounds)

Two independent cold reviews per round, plus a re-derivation of the mechanism from source.

❌ Blocker, found and fixed before publishing. The first draft read t3_renamed immediately before
the engine assertion, which materializes the stand-in permanently and would have left
-- ALTER on a lazy proxy triggers loading. passing even if ALTER stopped loading unloaded proxies;
the shipped fix re-attaches the database after the RENAME instead, so the ALTER is the first access
in every flavour.

⚠️ One inaccurate scope in the description, corrected before publishing. The discriminator is
isSymlinkSupported(), not local versus remote: DiskLocal is the only disk answering true
(DiskEncrypted forwards), and the repro used a local-backed object storage disk, with no S3.

💡 What moved in coverage. The engine assertion now sits after the ALTER and so oracles
ALTER-triggered loading, which had no engine oracle at all before; the rename's symlink path is still
exercised by the RENAME, just no longer asserted on.

💡 Noted, not blocking. The re-attach's own effect is not asserted at its site; three existing
reference lines of this file (t1, t2, src reporting TableProxy right after a re-attach) already
pin that behaviour and are observed passing in the failing flavour.

Also verified: all 14 reference lines classified, and the 13 this patch does not touch are
observed-passing context lines in the failing flavour; the 13 sibling tests mentioning lazy loading are
0 FAIL in any db disk flavour over 30 days.

@clickhouse-gh clickhouse-gh Bot closed this Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0378c6]

Summary: ✅


AI Review

Summary

This PR makes 03823_lazy_load_tables stop depending on whether the database metadata disk supports symlinks by checking the rename through a name-only system.tables listing, then re-attaching the database so the subsequent ALTER is the first materializing access in every flavor. I did not find any remaining correctness, coverage, or PR-metadata issues in the current patch.

Final Verdict

Status: ✅ Approve

Re-attaching the database after the RENAME makes the ALTER the first access to
the renamed table, which is what removes the dependency on the metadata disk,
but it also left the live rename path unobserved. The re-attach rebuilds the
catalog from the metadata file, so a rename that updated the file and left the
in-memory entry stale would still pass that block.

So list the names before the re-attach. One row covers both halves of the
rename (the new name is there, the old one is gone), it reads the same on
either database disk, and it does not load the table: system.tables opens the
storage object but reads name and engine straight off the lazy stand-in, which
is why the reference already shows TableProxy for three unloaded tables.

Verified on one binary. Patched: 50/50 on an object-storage database disk,
50/50 on the default one, and it passes on a local database disk too.
Evaluating the listing one statement earlier reds it with -t3_renamed /
+t3, so the assertion is live. Server logs show no load between the RENAME and
the DETACH on either disk, and the load of t3_renamed still lands ~250 us after
the ALTER, so the block below it keeps asserting what its comment claims.
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 24, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 26, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 26, 2026
Merged via the queue into ClickHouse:master with commit c39afa1 Sep 26, 2026
172 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 26, 2026
@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci 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.

3 participants