Repository navigation
Properly handle table_readonly setting in DDLWorker and replicated engines - #105109
Conversation
`TABLE_IS_READ_ONLY` was overloaded for both transient (`ReplicatedMergeTree` in temporary read-only state due to ZooKeeper disconnect) and permanent (`table_readonly` setting, static storage) cases. `DDLWorker` retries it indefinitely, which is correct for the transient case but caused `OPTIMIZE TABLE ON CLUSTER` to hang when `table_readonly = 1`. Replace the kludge in `DDLWorker::tryExecuteQuery` (which classified by resolving the storage and probing `supportsReplication`) with a clean split: `TABLE_IS_READ_ONLY` stays retriable; `TABLE_IS_PERMANENTLY_READ_ONLY` is non-retriable and is thrown by `assertNotReadonly` and `isStaticStorage` sites in `StorageMergeTree`, `StorageReplicatedMergeTree`, and the four DML interpreters (`ALTER`, `DELETE`, `UPDATE`, `DROP TRUNCATE`). Updates the existing tests that exercised these throw sites (`s3_plain`, `readonly` disk, `table_disk`, `table_readonly`) to expect the new error code. Addresses review feedback on #100950.
|
Workflow [PR], commit [28c7d21] Summary: ✅
AI ReviewSummaryThis PR separates permanent read-only failures from transient replicated read-only failures by adding Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required action: exempt metadata replay / restore from the new |
After switching the throws in these files to `TABLE_IS_PERMANENTLY_READ_ONLY`, the `extern const int TABLE_IS_READ_ONLY;` declarations were left behind and flagged by `Style check/cpp`: > ErrorCodes::TABLE_IS_READ_ONLY is defined but not used in file ... CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/105109/dede4362a1e76008cd6b83bafe266fbb8dcfe2a1/result_pr.json (PR #105109)
…MergeTree` The previous `mode < LoadingStrictnessLevel::ATTACH` check only rejected `CREATE` and `SECONDARY_CREATE`, so user-initiated `ATTACH TABLE ... ENGINE = ReplicatedMergeTree(...) SETTINGS table_readonly = 1` slipped through. Switch to `mode <= LoadingStrictnessLevel::ATTACH` so the check also fires for explicit `ATTACH` queries, while still letting `FORCE_ATTACH` and `FORCE_RESTORE` (server startup, restore from backup) load tables whose metadata may carry the setting from before this check. Add a regression case to `04062_table_readonly_replicated`.
The `ATTACH TABLE` regression case in `04062_table_readonly_replicated` used the `ATTACH TABLE name (cols) ENGINE = ...` form, which `Atomic` rejects with `INCORRECT_QUERY` before reaching the storage layer, so the test never exercised the new `mode <= LoadingStrictnessLevel::ATTACH` guard in `StorageReplicatedMergeTree`. Switch to the UUID-form so the query passes the `Atomic` check and reaches the storage guard, then correctly throws `NOT_IMPLEMENTED`. Also move the `table_readonly` guard in `StorageReplicatedMergeTree::alter` out of the `commands.isSettingsAlter()` branch. Previously a mixed `ALTER TABLE ... MODIFY COLUMN ..., MODIFY SETTING table_readonly = 1` would skip the pure-settings branch and apply the unsupported setting via the metadata path. The check now fires for any `MODIFY SETTING table_readonly` regardless of the surrounding command shape, with a regression case added to `04062_table_readonly_replicated`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When a `ReplicatedMergeTree` is attached on a static disk (e.g. `s3_plain`), both `is_readonly` and `isStaticStorage` are true. The previous order reported `TABLE_IS_READ_ONLY` (transient), which masks the permanent state and trips up callers like `DDLWorker` that need to distinguish retriable from non-retriable conditions. Fixes `02980_s3_plain_DROP_TABLE_ReplicatedMergeTree` expecting `TABLE_IS_PERMANENTLY_READ_ONLY` from `optimize table ... final` and `system sync replica ...` on `s3_plain` storage. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105109 PR: #105109
…per run The `.sql` form pinned a hardcoded UUID for the `ATTACH TABLE ... UUID ...` case, which collides under the flaky check when the same test runs more than once on the same server (failure: `TABLE_ALREADY_EXISTS` instead of `NOT_IMPLEMENTED`). Generate the UUID via `generateUUIDv4` in the shell wrapper so every run gets a distinct one, and verify each rejected statement by grepping the client output for `NOT_IMPLEMENTED`. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105109 PR: #105109
The previous test used `grep -F NOT_IMPLEMENTED -c` and expected `1` for each failing query. With `--send_logs_level=warning` (the default), the server-side log message of the rejection is also forwarded to the client, so the error string appears twice in stderr, making `grep -c` return `2`. Switch to `grep -F -q ... && echo 1 || echo 0`, which is the standard robust pattern used elsewhere in `tests/queries/0_stateless/*.sh`. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105109&sha=9498418a3be35d35b82edb6b21e516b58fe94e30&name_0=PR&name_1=Fast%20test PR: #105109
| /// Reject user-initiated `CREATE`/`ATTACH` queries with `table_readonly = 1` for | ||
| /// `ReplicatedMergeTree`, while still allowing `FORCE_ATTACH`/`FORCE_RESTORE` (server startup, | ||
| /// restore from backup) to load tables whose metadata may carry the setting from before this check. | ||
| if (mode <= LoadingStrictnessLevel::ATTACH && (*getSettings())[MergeTreeSetting::table_readonly]) |
There was a problem hiding this comment.
This guard is broader than “user-initiated CREATE/ATTACH”: mode <= LoadingStrictnessLevel::ATTACH also includes SECONDARY_CREATE.
That hits at least two metadata-replay paths:
RESTOREtable creation (InterpreterCreateQuerysetsmodeviagetLoadingStrictnessLevel(create.attach, ..., is_secondary_query || is_restore_from_backup)), so restore queries are usuallyATTACH/SECONDARY_CREATE, notFORCE_ATTACH/FORCE_RESTORE.- non-initial
DatabaseReplicatedDDL replay (SECONDARY_CREATE).
So backups / replicated metadata that already contain SETTINGS table_readonly = 1 can now fail to load with NOT_IMPLEMENTED, despite the comment saying restore-from-backup metadata should still load.
Can we narrow this check to true user DDL only, or thread an explicit metadata-origin / restore flag here and exempt replay paths?
There was a problem hiding this comment.
Good catch. Addressed in 3eb33448df5 by narrowing the condition to mode == LoadingStrictnessLevel::CREATE || mode == LoadingStrictnessLevel::ATTACH, which leaves both SECONDARY_CREATE (RESTORE and DatabaseReplicated DDL replay) and the FORCE_* modes (server startup) unaffected.
There was a problem hiding this comment.
Reverted in cd5bd8e9c41. On second look, pre-PR (d3f6b376eaf) already used mode < ATTACH, which itself rejected SECONDARY_CREATE, so the current mode <= ATTACH is not a regression for replay paths — it just additionally rejects explicit ATTACH. Leaving the bot thread open for @alexey-milovidov to decide.
The constructor guard introduced for `ReplicatedMergeTree` used `mode <= LoadingStrictnessLevel::ATTACH`, which is too broad: it also catches `SECONDARY_CREATE`, the mode used by `RESTORE` from backup and non-initial `DatabaseReplicated` DDL replay. The comment claimed restore metadata would still load, but the check actually rejected it. Narrow the condition to the two strictly user-initiated modes (`CREATE` and `ATTACH`) so that replay/restore paths can load tables whose metadata may carry the setting from before this check. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…jection" This reverts commit 3eb3344.
# Conflicts: # src/Common/ErrorCodes.cpp
The test verifies that the `table_readonly` setting is rejected with `NOT_IMPLEMENTED` for `ReplicatedMergeTree` — the check lives in the `StorageReplicatedMergeTree` constructor. When the engine is substituted with `SharedMergeTree` (the CH Inc sync CI runs stateless tests with `--replace-replicated-with-shared`), the first `CREATE` succeeds instead of being rejected, and the rest of the test fails with `TABLE_ALREADY_EXISTS`. The test is specific to `ReplicatedMergeTree`, so exclude it from shared merge tree runs. Co-Authored-By: Claude Fable 5 <[email protected]>
|
The |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 52/56 (92.86%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 26 line(s) · Uncovered code |
After ClickHouse#105109 merged, `StorageReplicatedMergeTree::alter` rejects `ALTER TABLE ... MODIFY SETTING table_readonly` with `NOT_IMPLEMENTED`, because the `table_readonly` setting is only supported for `StorageMergeTree`. `SystemLog::prepareTable` issued the readonly `ALTER` on the renamed old table whenever `old_table->isMergeTree()` was true, which also holds for `ReplicatedMergeTree`. A system log configured with a replicated engine via a custom `<engine>` would therefore make the `ALTER` throw right after the rename. The exception is caught in `flushImpl`, which logs the error and still confirms the batch, so the current batch of log entries is lost and an error is logged on every rotation. Restrict the readonly marking to non-replicated `MergeTree` tables by also checking `!supportsReplication()`. For replicated system log tables the marking is simply skipped, which matches the engine-level guarantee established by ClickHouse#105109. The rejection on the replicated path is already covered by `04062_table_readonly_replicated.sh`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After ClickHouse#105109 merged, `StorageReplicatedMergeTree::alter` rejects `ALTER TABLE ... MODIFY SETTING table_readonly` with `NOT_IMPLEMENTED`, because the `table_readonly` setting is only supported for `StorageMergeTree`. `SystemLog::prepareTable` issued the readonly `ALTER` on the renamed old table whenever `old_table->isMergeTree()` was true, which also holds for `ReplicatedMergeTree`. A system log configured with a replicated engine via a custom `<engine>` would therefore make the `ALTER` throw right after the rename. The exception is caught in `flushImpl`, which logs the error and still confirms the batch, so the current batch of log entries is lost and an error is logged on every rotation. Restrict the readonly marking to non-replicated `MergeTree` tables by also checking `!supportsReplication()`. For replicated system log tables the marking is simply skipped, which matches the engine-level guarantee established by ClickHouse#105109. The rejection on the replicated path is already covered by `04062_table_readonly_replicated.sh`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
OPTIMIZE TABLE ... ON CLUSTERand other DDL no longer hang when the target table hastable_readonly = 1. The setting now throws a new dedicated error codeTABLE_IS_PERMANENTLY_READ_ONLY, whichDDLWorkertreats as non-retriable (distinct from the transientTABLE_IS_READ_ONLYthat arises during temporaryReplicatedMergeTreeZooKeeper disconnects). Thetable_readonlysetting is also now explicitly rejected forReplicatedMergeTree, both at creation and viaALTER MODIFY SETTING. Follow-up to #97652. Supersedes #100950.Documentation entry for user-facing changes
Version info
26.6.1.726