Repository navigation
Route every comment ALTER on a KeeperMap table in a Replicated database through replicated DDL - #118011
Conversation
…tabase
`DatabaseReplicated::shouldReplicateQuery` gated the replicated path for an
`ALTER` on a `KeeperMap` table on `ASTAlterQuery::isCommentAlter`, which
requires every command in the query to be the same single AST type. The
storage accepts a strictly larger set: `StorageKeeperMap` inherits the base
`alter`, so `IStorage::checkAlterIsPossible` accepts
`AlterCommand::isCommentAlter` per command, which also covers a comment-only
`MODIFY COLUMN`. Anything in that gap ran locally with no
`ZooKeeperMetadataTransaction` and still reached
`DatabaseReplicated::commitAlterTable`, whose first statement asserts a
transaction is present while the DDL worker is active.
Two user-reachable carriers, both against a `KeeperMap` table in a
`Replicated` database:
ALTER TABLE t MODIFY COMMENT 'a', COMMENT COLUMN c 'b';
ALTER TABLE t MODIFY COLUMN c COMMENT 'a';
The second is a single command, so the trigger is the type classification and
not the command count; a single-type comment `ALTER` was always routed
correctly.
`chassert` and `assertDigest` both compile away outside debug and sanitizer
builds, so on a release build the `ALTER` completes: local metadata and the
local digest advance while Keeper keeps the pre-`ALTER` `CREATE` statement and
digest. Other replicas therefore never receive the change, and at the next
start `local_digest != zk_digest` makes `DatabaseReplicatedWorker` declare the
replica lost (`check_consistency` defaults to true) and run
`recoverLostReplica`, which reverts the `ALTER`. Measured on a single-replica
database holding 50 rows, that recovery logged "Will DROP TABLE km, because it
does not store data on disk and can be safely dropped" and the table came back
empty with its Keeper data children going from 50 to 0, while a `MergeTree`
control table in the same database kept all 77 of its rows. That drop branch is
the pre-existing heuristic tracked in
ClickHouse#111957 and is unchanged here;
this commit removes one deterministic trigger of it.
The fix uses `ASTAlterQuery::isSettingsOrCommentAlter`, added in
ClickHouse#107142 for exactly this class and
already wired into `DDLWorker.cpp`, whose comment there names mixed batches
"that match neither single-type predicate". That routing site was fixed and
this one was missed. `isCommentAlter` implies `isSettingsOrCommentAlter`, so the
change can only widen the set of queries that take the replicated path: nothing
replicated before stops being replicated. The predicate also accepts
`MODIFY SETTING` and `RESET SETTING`, which `KeeperMap` has none of; those
still fail with an identical error code and message before and after, verified
by comparing both binaries, at the cost of one extra DDL log entry.
Found by the BuzzHouse fuzzer on the arm_asan_ubsan build:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117591&sha=1520bd2704e60296068431f9f1144b2112ec03ff&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29
ClickHouse#117591
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: 2 findings, 0 blockers
💡 💡 Also noticed, not changed: with this routing fix in place, the |
|
Workflow [PR], commit [735aabd] Summary: ✅
AI ReviewSummaryThis PR widens Missing context / blind spots
Final Verdict✅ No new OSS-side inline findings on the current head. LLVM Coverage Report |
|
cc @tuanpach @antonio2368, could you review this? |
…he storage's set `isSettingsOrCommentAlter` also admits `MODIFY`/`RESET SETTING`, which `KeeperMap` can never apply: it inherits `IStorage::checkAlterIsPossible`, and that rejects every non-comment command. The previous comment described only the narrower set, so it read as a characterization of the predicate. The direction is deliberate. Admitting an `ALTER` the storage rejects costs one replicated DDL log entry and the same error; excluding one the storage applies runs it locally without a metadata transaction and leaves the `CREATE` statement in Keeper stale. An AST-level mirror of `AlterCommand::isCommentAlter` here would keep that drift risk and diverge from the sibling routing site at `DDLWorker.cpp:842`, which uses the same helper.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
| if (is_keeper_map_table(query_ptr) && !alter->isCommentAlter()) | ||
| /// A `KeeperMap` `ALTER` the storage applies rewrites the `CREATE` statement kept in Keeper and | ||
| /// needs a metadata transaction, so this predicate is deliberately wider than the storage's set. | ||
| if (is_keeper_map_table(query_ptr) && !alter->isSettingsOrCommentAlter()) |
There was a problem hiding this comment.
MODIFY/RESET SETTING now enter the replicated path even though KeeperMap can never apply them, and they still fail with the same code and message — except on a replica that can't enqueue, which now gets the enqueue error rather than NOT_IMPLEMENTED. @groeneai can you add test cases for these?
There was a problem hiding this comment.
Added in db40ae0, in the test this PR already adds:
ALTER TABLE 05076_keepermap MODIFY SETTING some_setting = 1; -- { serverError NOT_IMPLEMENTED }
ALTER TABLE 05076_keepermap RESET SETTING some_setting; -- { serverError BAD_ARGUMENTS }
ALTER TABLE 05076_keepermap COMMENT COLUMN k 'col-4', MODIFY SETTING some_setting = 1; -- { serverError NOT_IMPLEMENTED }followed by the same local-vs-Keeper comment check the earlier arms use, so the mixed batch is pinned to leave both sides untouched as well (col-4 must not appear on either). The two codes differ because RESET SETTING is rejected in AlterCommands::validate ("Cannot alter settings, because table engine doesn't support settings changes") while MODIFY SETTING gets as far as IStorage::checkAlterIsPossible ("Alter of type 'MODIFY_SETTING' is not supported by storage KeeperMap"). Dropping the serverError annotations makes the test fail, so the arms are not vacuous, and 50 runs sequentially plus 50 at --jobs 8 are green.
I did not pin the cannot-enqueue half, and I would rather explain why than add an arm that flakes. The only stateless lever for it is database_replicated_initial_query_timeout_sec = 0, which does not force the error, it races the worker thread in DatabaseReplicatedDDLWorker::tryEnqueueAndExecuteEntry. Over 100 runs on an idle debug server I measured 99 UNFINISHED and 1 NOT_IMPLEMENTED, which puts the 50 runs of the flaky check at roughly a 40% chance of a red. Forcing it deterministically needs either the server-global SYSTEM STOP REPLICATED DDL QUERIES, which would make the test no-parallel and disturb concurrent tests, or an integration test that stops a replica. I am happy to add the integration test if you want that arm covered too.
…` database The widened routing predicate also admits pure `MODIFY SETTING` / `RESET SETTING` and comment-first mixed batches, none of which `KeeperMap` can apply. These arms pin what a reader of the diff otherwise has to take on trust: on a healthy replica the user-visible error is unchanged (`NOT_IMPLEMENTED` from `IStorage::checkAlterIsPossible`, `BAD_ARGUMENTS` from `AlterCommands::validate` for `RESET SETTING`), and a rejected batch leaves both the local metadata and the copy the database publishes in Keeper untouched, even though it now reaches the replicated DDL log. Requested in review of this PR. They are not vacuous: with the `serverError` annotations removed, the test fails. This also corrects an over-claim in the first commit of this PR, which said such queries "still fail with an identical error code and message before and after". That holds on a healthy replica only. A replica that cannot enqueue now answers the enqueue error instead of `NOT_IMPLEMENTED`, and that half is deliberately not pinned here. The only stateless lever for it is `database_replicated_initial_query_timeout_sec = 0`, which races the DDL worker in `DatabaseReplicatedDDLWorker::tryEnqueueAndExecuteEntry`: measured 99 `UNFINISHED` and 1 `NOT_IMPLEMENTED` over 100 runs, so across the 50 runs of the flaky check it would fail about 40% of the time. Deterministic coverage needs either the server-global `SYSTEM STOP REPLICATED DDL QUERIES`, which would force `no-parallel`, or an integration test. Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - db40ae0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260905-000000 |
|
Fixing PR for the |
…d-comment-alter-routing
Related: #111957
Related: #107142
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a comment
ALTERon aKeeperMaptable in aReplicateddatabase being applied only to the local replica. Keeper kept the pre-ALTERCREATEstatement and digest, so other replicas never saw the change and the next start declared the replica lost, reverting theALTERand, if no other table shared itsKeeperMappath, dropping its data.Description
DatabaseReplicated::shouldReplicateQuerygates the replicated path for aKeeperMapALTERonASTAlterQuery::isCommentAlter, which requires every command to be the same AST type. The storage accepts more:StorageKeeperMapinheritsIStorage::checkAlterIsPossible, which acceptsAlterCommand::isCommentAlterper command, covering a comment-onlyMODIFY COLUMNtoo. Anything in that gap runs locally with noZooKeeperMetadataTransactionand still reachesDatabaseReplicated::commitAlterTable. Both are ordinary SQL; the second is a single command, so the trigger is the classification, not the count:chassertandassertDigestcompile away outside debug and sanitizer builds, so a release build completes theALTER: local metadata and digest advance while Keeper keeps the old ones. At the next startlocal_digest != zk_digestmakesDatabaseReplicatedWorkerdeclare the replica lost (check_consistencydefaults totrue) and runrecoverLostReplica, which drops any table not storing data on disk. Measured on a single replica: theKeeperMaptable came back empty, 50 rows to 0, while aMergeTreecontrol kept all of its rows. The drop branch is the existing heuristic in #111957; this removes one of its triggers.The fix uses
ASTAlterQuery::isSettingsOrCommentAlter, added in #107142 for this class and already wired atDDLWorker.cpp:842; that site was fixed and this one missed.isCommentAlterimplies it, so the change only widens the replicated set. It also acceptsMODIFY/RESET SETTING, whichKeeperMapcan never apply (same base check); those still fail with the same code and message, except on a replica that cannot enqueue, which now gets the enqueue error rather thanNOT_IMPLEMENTED. The cloud-onlySharedDatabaseCatalog::shouldReplicateQuerymay need the same change.05076_keeper_map_mixed_comment_altercovers both carriers plus a single-type control; it aborts the server on master.Found by
BuzzHouse (arm_asan_ubsan), STID2508-2c1e: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117591&sha=1520bd2704e60296068431f9f1144b2112ec03ff&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29Workflow [PR]
Sync PR [sync-upstream/pr/118011]
Version info
26.9.1.865(included in26.9and later)