Repository navigation
Let a table, that carries table_readonly, successfully load, and be taken out of it - #119224
Conversation
`table_readonly` is not supported for `ReplicatedMergeTree`, and the checks that say so trapped a table whose metadata carries it anyway - which the `convert_to_replicated` flag produced, since a converted table keeps the settings of the table it came from. A backup of that working table could not be restored (restore creates at `SECONDARY_CREATE`, which the `mode <= ATTACH` gate rejected), a detached table could not be re-attached, and `MODIFY SETTING table_readonly = 0` was refused too, although the setting's documentation promises it can always be toggled back. The constructor now rejects a `CREATE` only, so everything that loads an existing table keeps working; the alter gate rejects turning the setting on, not off; and the conversion leaves a readonly table alone and says so in the log rather than producing one, keeping the flag so that it runs once the setting is gone. `04062_table_readonly_replicated` asserted that the attach is refused, which is the trap this fixes, so that assertion now checks that it is not. Closes: #118509
|
Workflow [PR], commit [d233810] Summary: ✅
AI ReviewSummaryThis PR moves the Tests
Final Verdict
LLVM Coverage Report |
| # The UUID-form is required because `Atomic` rejects `ATTACH TABLE name (cols) ENGINE = ...` syntax | ||
| # before reaching the storage check. | ||
| $CLICKHOUSE_CLIENT --query=" | ||
| ATTACH TABLE t_readonly_repl UUID '$uuid' (x UInt64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/t_readonly_repl', 'r1') ORDER BY x SETTINGS table_readonly = 1; |
There was a problem hiding this comment.
This does not actually test the behavior the PR description promises.
At this point the other new test has already done MODIFY SETTING table_readonly = 0 and RESET SETTING table_readonly, so its short ATTACH TABLE t_readonly_replicated is reattaching a normal replicated table, not one whose stored metadata still carries table_readonly = 1. And this shell branch only asserts "the error is not NOT_IMPLEMENTED", so it would still pass on any other failure.
So we still do not have a focused regression for the real contract change: loading stored metadata (short ATTACH TABLE t / SECONDARY_CREATE during RESTORE) when the table definition still contains table_readonly = 1, and then clearing that setting successfully.
There was a problem hiding this comment.
🕵 Right on both counts. 04062 is back to what it asserted on master - that full-definition ATTACH is fresh user input and is refused - since the first blocker is fixed.
The contract this PR actually changes can no longer be reached through SQL at all now that every fresh entrypoint refuses the setting, so it is covered where a stored definition can be planted: tests/integration/test_modify_engine_on_restart/test_table_readonly.py writes table_readonly = 1 into the stored definition of a ReplicatedMergeTree with the server stopped, then checks that the table loads on startup, loads again through a short ATTACH TABLE t, serves its rows, and that ALTER TABLE ... RESET SETTING table_readonly takes it out of that state. The same file drives the convert_to_replicated flag end to end: skipped while the setting is on, flag kept, conversion on the next start once it is reset. Both tests pass locally.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units39 translation units recompiled, 317 s compile time in total, 39 of them have a recent master baseline. |
The refusals the test asserts are `ReplicatedMergeTree`'s own; an engine substituted for it accepts `table_readonly = 1`, so the expected `NOT_IMPLEMENTED` never came and the test failed. Tag it `no-shared-merge-tree`.
…e `ATTACH ... AS REPLICATED` Two gaps the bot review found in the previous gate: * A full-definition `ATTACH TABLE t UUID '...' (...) ENGINE = ReplicatedMergeTree ... SETTINGS table_readonly = 1` is fresh user input even though it runs under `LoadingStrictnessLevel::ATTACH`, so keying the veto on `mode == CREATE` let a user mint a brand new table in the unsupported state. The veto now lives in `registerStorageMergeTree`, next to the fresh-vs-replayed distinction the rest of `MergeTree` already uses (`isFreshTableDefinition` plus the DDL-replay, stored-definition and Shared Catalog markers), so only a replayed definition - short `ATTACH TABLE t`, `SECONDARY_CREATE`, the startup levels - loads with the setting. * `ATTACH TABLE ... AS REPLICATED` rewrites the engine of a stored `MergeTree` definition in place and so reached the same unsupported state through the manual conversion entrypoint. The precondition is now a shared helper, `DatabaseOrdinary::isTableReadonlyInDefinition`, which both conversion entrypoints call: the startup `convert_to_replicated` flag logs and leaves the table alone, while the query refuses outright before any of its side effects. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…adonly-gates-118509
… the closed gate asserts `04062` goes back to what it asserted on master: a full-definition `ATTACH TABLE t UUID '...' (...) SETTINGS table_readonly = 1` is fresh user input and is refused again, so the assertion that it succeeds - which the too-coarse `mode == CREATE` gate had made true - is wrong and is removed. The contract that is actually being changed - a definition that already carries the setting keeps loading, and can be taken out of that state - can no longer be reached through SQL at all now that every fresh entrypoint refuses it, so it is covered where a stored definition can be planted: `test_modify_engine_on_restart/test_table_readonly.py` writes `table_readonly = 1` into the stored definition of a `ReplicatedMergeTree` with the server stopped, and checks that the table loads on startup, loads again through a short `ATTACH TABLE t`, serves its rows, and that `ALTER TABLE ... RESET SETTING table_readonly` takes it out. The same test drives the `convert_to_replicated` flag end to end: the conversion is skipped while the setting is on, the flag is kept, and the conversion happens on the next start once the setting is reset. `05191` gains the manual conversion entrypoint: `ATTACH TABLE ... AS REPLICATED` of a table carrying the setting is refused, the refusal leaves the table untouched, and the conversion goes through once the setting is reset. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…se name of its own `system.tables.metadata_path` is reported relative to the server's data directory, so the planted definition has to be addressed from there, and the database was named after the setting the test checks for, which made the `RESET SETTING` assertion match the table's own name. Both tests pass now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: Upgrade check (amd_release) - |
|
Investigated: this PR is not implicated and no new fix is needed. The abort came from the previous release's server, not from this PR's build. The
The logical error is stamped 00:24:39 for query The signature is owned by #119385 (merged 2026-09-12 10:39Z, The CI side is already closed by your own #119768 ( One loose end: the engine fix is master-only, and the abort is reachable on 26.8 with |
…adonly-gates-118509 Conflict in `StorageReplicatedMergeTree::alter`: master (db31f04) started to reject `RESET SETTING table_readonly` (and its `MODIFY SETTING table_readonly = DEFAULT` spelling) on `ReplicatedMergeTree`, while this PR rejects only turning the setting on, because turning it off is the way out for a table whose metadata carries it. Resolved in the PR's direction: a reset is judged by the value it resets to, the server default from `getDefaultSettings`, so it is rejected exactly when that default is on (a `replicated_merge_tree` config section turning it on). `05183` is updated accordingly: with the default off the resets are accepted and apply what they carry along, and turning the setting on in the same `ALTER` is still refused. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rver defaults Both conversion entrypoints (the `convert_to_replicated` flag and `ATTACH TABLE ... AS REPLICATED`) only looked at the explicit `SETTINGS` of the stored definition, while `registerStorageMergeTree` resolves the settings of a `ReplicatedMergeTree` over the `merge_tree` / `replicated_merge_tree` config defaults. With `table_readonly = 1` coming from the config, a `MergeTree` without the setting passed the precondition and became a readonly replicated table, which the later non-fresh load then accepted. `DatabaseOrdinary::isTableReadonlyInDefinition` becomes `isTableReadonlyAsReplicated`: the definition's own value if it has one, otherwise `getReplicatedMergeTreeSettings`. The advice in the messages is now `MODIFY SETTING table_readonly = 0`, because a reset would fall back to that same default. The integration test gets a second node whose `replicated_merge_tree` section turns the setting on, covering both refusals, the explicit `0` that lets the conversion through, and the refused reset on the converted table. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…shadow `WithContext::context` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ion test In the `db disk` configuration the table metadata lives on the database disk rather than under `/var/lib/clickhouse`, so `sed` on the local file failed with `No such file or directory`. Use `replace_text_in_metadata` like the other metadata-editing tests, clear the disk metadata cache and restart with `kill=True`. Passed locally both plain and with `CLICKHOUSE_USE_DATABASE_DISK=1`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119224&sha=e538fc009a76d4921c7c7affeb0b2e8250ba1282&name_0=PR PR: #119224 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is not something that we wanted to fix. But ok.
Keep the release branch side and apply only the fix of #128995: check the `TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible` before the side effects of `ATTACH ... AS [NOT] REPLICATED`. The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated` (#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary` databases, none of which exist on 26.9, where the conversion supports `Atomic` only. Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
Keep the release branch side and apply only the fix of #128995: check the `TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible` before the side effects of `ATTACH ... AS [NOT] REPLICATED`. The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated` (#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary` databases, none of which exist on 26.8, where the conversion supports `Atomic` only. Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
Keep the release branch side and apply only the fix of #128995: check the `TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible` before the side effects of `ATTACH ... AS [NOT] REPLICATED`. The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated` (#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary` databases, none of which exist on 26.3, where the conversion supports `Atomic` only. Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
table_readonlyis not supported forReplicatedMergeTree, and the checks that enforce that trapped a table whose metadata carries it anyway - which the documentedconvert_to_replicatedflag produced, because a converted table keeps the settings of the table it was converted from. Such a table works, but:BACKUPof it succeeded while theRESTORErefused withNOT_IMPLEMENTED: restore creates the table atSECONDARY_CREATE, which the constructor'smode <= ATTACHgate rejected, contrary to what the comment on that gate believed;DETACH TABLEsucceeded andATTACH TABLEthen refused, so after a plain detach only a restart brought the table back, and afterDETACH TABLE ... PERMANENTLYnothing did;ALTER TABLE ... MODIFY SETTING table_readonly = 0was refused as well - the alter gate rejected the setting by name, whatever value was assigned - although the setting's own documentation promises it "can always be toggled back".Now the state is unrepresentable through every entrypoint that mints a table, while a definition that already carries the setting keeps loading:
MergeTreetells a fresh definition from a replayed one (isFreshTableDefinitioninregisterStorageMergeTree, plus the DDL-replay, stored-definition and Shared Catalog markers), so aCREATEand a full-definitionATTACH TABLE t UUID '...' (...) SETTINGS table_readonly = 1are both refused, while a shortATTACH TABLE t, aSECONDARY_CREATE(RESTORE,Replicated-database DDL) and the startup levels load the table;MODIFY SETTING table_readonly = 0- the way out of that state - works; aRESET SETTING(orMODIFY SETTING table_readonly = DEFAULT) is judged by the server default it falls back to, so it works unless thereplicated_merge_tree/merge_treeconfig sections turn the setting on;ReplicatedMergeTree- from its own definition or, when the definition does not set it, from themerge_tree/replicated_merge_treeconfig defaults, resolved likeregisterStorageMergeTreedoes - through one shared precondition: the startupconvert_to_replicatedflag leaves the table alone and says so in the log (throwing there would take the table down with the whole database load, and the setting could then not be changed at all), andATTACH TABLE ... AS REPLICATEDthrows before any of its side effects. Both point atMODIFY SETTING table_readonly = 0. The flag is kept, so the conversion runs on the next start once the setting is off.Since no entrypoint can introduce the setting anymore, the load path is covered where a stored definition can be planted:
test_modify_engine_on_restart/test_table_readonly.pywritestable_readonly = 1into the stored definition of aReplicatedMergeTreewith the server stopped and checks that the table loads on startup, loads again through a shortATTACH TABLE t, serves its rows, and is taken out of that state byRESET SETTING; the same test drives theconvert_to_replicatedflag end to end, and a second node whosereplicated_merge_treeconfig section turns the setting on checks that both conversion entrypoints refuse aMergeTreewithout the setting, that an explicittable_readonly = 0lets the conversion through, and that a reset on the converted table is refused. The planting goes through the database disk, so the test also runs in thedb diskconfiguration.Closes: #118509
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed a
ReplicatedMergeTreetable whose metadata carriestable_readonly = 1being unusable: its backup could not be restored, it could not be re-attached afterDETACH, andALTER TABLE ... MODIFY SETTING table_readonly = 0was refused. Converting a table with that setting to replicated is no longer done, by either theconvert_to_replicatedflag orATTACH TABLE ... AS REPLICATED.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119224]
Version info
26.10.1.705-master(included in26.10and later)