Repository navigation
Fix 03823_lazy_load_tables failing when the database metadata is on a remote disk - #122047
Conversation
… 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]>
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
💡 What moved in coverage. The engine assertion now sits after the 💡 Noted, not blocking. The re-attach's own effect is not asserted at its site; three existing Also verified: all 14 reference lines classified, and the 13 this patch does not touch are |
|
Workflow [PR], commit [c0378c6] Summary: ✅ AI ReviewSummaryThis PR makes Final VerdictStatus: ✅ 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.
Related: #121703
Related: #113389
Changelog category (leave one):
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_tableshas never passed inStateless tests (..., db disk, ...): 0 OK / 15 FAIL over30 days on three PRs with code-disjoint diffs, always this line:
Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/35995830215/job/107645147776
RENAME TABLEdoes not load a lazy table, but creating the convenience symlink does:DatabaseAtomic::renameTablecallstryCreateSymlink, which returns early at!db_disk->isSymlinkSupported()one statement beforetable->getDataPaths(), and that call forcesgetNested().DiskLocalis the only disk answeringtrue(DiskEncryptedforwards), so the renamematerializes 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 materializesthe table the
ALTERstays pre-loaded and its comment asserts nothing in the flavours that pass today. Aname-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 followingthe
ALTER, not the listing, on both disks.The alternative is to stop
tryCreateSymlinkmaterializing the table. I did not: its target needs thenested storage, and skipping the symlink would change the on-disk layout of every
Atomicrename. Yourcall.
#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
26.10.1.733-master(included in26.10and later)