Repository navigation
Finish the conversion to ReplicatedMergeTree under lazy_load_tables - #118135
Conversation
The second phase of the `convert_to_replicated` migration casts the catalog's storage object to `StorageReplicatedMergeTree`. With `lazy_load_tables` that object is a stand-in whose `startup` does nothing, so the cast returned null and the whole restore was skipped before any log line: the table came up as replicated with no metadata in ZooKeeper - read-only forever - and the flag was never removed, so no further restart could finish the conversion either. The documented recovery `SYSTEM RESTORE REPLICA` inspected the same stand-in and answered "Table is not replicated". The flag file is now looked up before the storage is touched (from the database's own disk when the table has no storage policy yet, i.e. is a stand-in), and only a table that is really being converted is materialized. `SYSTEM RESTORE REPLICA` resolves the stand-in too. Closes: #117413
|
TL;DR: the reordered second phase looks for the conversion flag only on the database disk when the table is a stand-in, but the first phase resolves the table's 1. The two phases resolve the flag disk differently. Phase one, Phase two after this PR: for a stand-in, 2. Resulting state.
Repro shape: 3. A fix that keeps the lazy-loading guarantee. The comment in the diff is right that materializing every deferred table just to ask for its disks would defeat Unrelated to this PR but adjacent: |
…cond phase The `convert_to_replicated` flag is looked up on the first disk of the table's storage policy. The first phase resolves that policy from the `CREATE TABLE` query, but the second phase asked the storage object - and a lazily loaded stand-in returns no policy at all, so a table with a non-default `storage_policy` fell back to the database disk, the flag was missed, the table stayed read-only and the flag was never removed. Both phases now share `getStoragePolicyFromCreateQuery`, so they look at the same disk. Added an integration test for a lazy table on a `jbod` policy. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…o-replicated-117413 # Conflicts: # src/Databases/DatabaseOrdinary.cpp # src/Databases/DatabaseOrdinary.h
|
🕵 Good catch, and adopted: the second phase now resolves the storage policy the same way the first phase does, from the
Added an integration test for the reported shape: a On the adjacent note: agreed that |
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [ffd1922] Summary: ✅
AI ReviewSummaryThis PR fixes the lazy-proxy blind spot behind PR Metadata
Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit ffd1922.
Changed lines: Changed C/C++ lines covered: 59/69 (85.51%) · Uncovered code |
…o-replicated-117413
…ingToReplicated` The second phase of the conversion resolved the table's storage policy via `tryGetCreateTableQuery`, which goes through `tryGetTable` and then `waitTableStarted` on the very table whose startup job is executing. The `AsyncLoader` reported the self-dependency as a logical error (`Load job 'startup table db.t' waits for dependent load job 'startup table db.t'`), failing `ATTACH DATABASE` for every table and aborting the server in the fast test. Use `getCreateQueryFromMetadata`, which parses the `.sql` file directly without touching the catalog, so `lazy_load_tables` is still honored and no job waits on itself. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118135&sha=d7ab7bc0b80469bd0b1371798c222f300bba2692&name_0=PR&name_1=Fast%20test PR: #118135 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
`DatabaseOrdinary::getStoragePolicyFromCreateQuery` only looked at `storage_policy`, while `MergeTreeData::getStoragePolicy` gives `disk` precedence. A table created with `SETTINGS disk = ...` had its flag looked up on the default-policy disk. Mirror the `disk`-first resolution (including custom `disk(...)` definitions), and add integration tests for the `disk` form and for `SYSTEM RESTORE REPLICA` on a lazily loaded table. Addresses review comments on #118135 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…o-replicated-117413
…ing the metadata scan `getStoragePolicyFromCreateQuery` runs for every `MergeTree` table before the `convert_to_replicated` flag is known to exist. Resolving an inline `disk(...)` setting there created the custom disk, so under `lazy_load_tables` a table that should stay deferred could fail `ATTACH DATABASE` or server startup (e.g. an unavailable `include` or `from_zk`). Keep the lookup limited to named disks and storage policies; tables on inline disk definitions are skipped by both phases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o-replicated-117413 Master introduced `castStorage` with `DeferredTable`. In `restoreMetadataAfterConvertingToReplicated`, keep the PR's flag-first logic and materialize the stand-in with `castStorage<StorageReplicatedMergeTree>(table, DeferredTable::Load)` instead of the manual `StorageProxy` unwrap. Drop the PR's manual unwrap in `InterpreterSystemQuery::restoreReplica`: master's `castStorage(..., DeferredTable::Load)` already loads the stand-in there.
…sk(...)` tables Without `lazy_load_tables` the table is loaded right after the metadata scan, which creates its custom disk anyway, so the first phase now resolves the inline `disk(...)` definition and looks for the flag on that disk. Only with `lazy_load_tables` is the custom disk still not instantiated during the scan. The second phase now logs a warning when it finds the flag on a table that was not converted, instead of ignoring it silently. Add a regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on-converting tables at startup The metadata scan resolved an inline `disk(...)` definition without `for_system_database`. Custom disks are cached by their definition, so the real load of a `system` table then reused the disk created without the `s3_allow_server_credentials_for_system_table_disks` exemption, which went anonymous and failed the server start in `test_storage_s3/test.py::test_system_table_s3_disk_uses_server_credentials_with_server_setting`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118135&sha=latest&name_0=PR&name_1=Integration%20tests%20(amd_llvm_coverage%2C%203%2F8) Address review: `restoreMetadataAfterConvertingToReplicated` reparsed the metadata of every table without a storage policy (views, dictionaries, `Log`, any lazy table) and checked the flag for it. The metadata scan now remembers the CREATE query of the `Replicated*MergeTree` tables of a database with `lazy_load_tables`, and only those stand-ins resolve the policy at startup; eagerly loaded tables keep the old fast path of skipping anything that is not a `StorageReplicatedMergeTree`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is borderline harmful, as the original issue is pointless. However, I've read all the code and found it acceptable.
…Needed` uses its policy After merging `master`, `DatabaseOrdinary::getStoragePolicyFromCreateQuery` (from #118135) resolved an inline `disk(...)` with `MergeTreeSettings::resolveDiskSetting` and dropped the returned registration. The disk was unregistered right away, so `getStoragePolicyFromDisk` threw `UNKNOWN_DISK` and `ATTACH DATABASE` of a database with such a table failed (`05136_custom_disk_released_on_detach`). The registration is now handed to the caller and kept while the policy is in use. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stem-tables-117420 Conflict resolution: - `DatabaseOrdinary`: master (#118135) finishes the `convert_to_replicated` conversion of a lazily loaded table by materializing the stand-in in the second phase, so this branch's own fix (do not defer such a table, `hasConvertToReplicatedFlag`) is dropped in favor of master's. - `StorageProxy.h`: master now forwards `supportsDelete`, `supportsLightweightDelete`, `supportsLightweightUpdate`, `checkMutationIsPossible` and `updateLightweight` itself; the duplicate overrides from this branch are removed. - `InterpreterAlterQuery`: keep resolving the mutation target to the real storage before taking the metadata snapshot, which subsumes master's reordering of `checkMutationIsPossible`.
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]>
The second phase of the
convert_to_replicatedmigration (DatabaseOrdinary::restoreMetadataAfterConvertingToReplicated) casts the catalog's storage object toStorageReplicatedMergeTree. Withlazy_load_tablesthat object is a stand-in whosestartupdoes nothing, so the cast returned null and the whole restore was skipped before any log line:.sqlalready saidReplicatedMergeTree(phase one wrote it durably), so the table came up replicated with no metadata in ZooKeeper - read-only forever;convert_to_replicatedflag was never removed, and every later restart deferred the table again, so the conversion could not self-heal;SYSTEM RESTORE REPLICAinspected the same stand-in and answered "Table ... is not replicated".The flag file is now looked up before the storage is touched, and only a table that is really being converted is materialized, so a deferred table that is not being converted is still not loaded.
SYSTEM RESTORE REPLICAresolves the stand-in as well.The flag lives on the first disk of the table's storage policy, and a stand-in has no storage policy of its own (
StorageTableProxy::getStoragePolicyreturnsnullptrby design). Both phases therefore resolve the policy identically, from theCREATE TABLEquery, via the sharedgetStoragePolicyFromCreateQuery(which, likeMergeTreeData::getStoragePolicy, gives adisksetting precedence overstorage_policy) - so a table on a non-defaultstorage_policyordiskis converted too, and no table has to be loaded just to be asked for its disks.The new integration tests live next to the other
convert_to_replicatedtests: lazy tables on the default policy, on ajbodpolicy and onSETTINGS disk = 'jbod1', plusSYSTEM RESTORE REPLICAon a lazy table whose ZooKeeper metadata was removed.Closes: #117413
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed the automatic
MergeTreetoReplicatedMergeTreeconversion silently not finishing for a table in a database withlazy_load_tables, which left the table read-only with no metadata in ZooKeeper and the conversion flag in place.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/118135]
Version info
26.10.1.2343-master(included in26.10and later)