Repository navigation
Keep KeeperMap data when a Replicated database replica recovers - #122917
antonio2368 merged 4 commits into
Conversation
`DatabaseReplicated::recoverLostReplica` drops every diverged local table that does not store data on disk, then re-creates it from the metadata in Keeper. `StorageKeeperMap` does not store data on disk, but its data lives in Keeper: `StorageKeeperMap::drop` removes the table's registration and, when no other table is registered on the same path (a single-replica database, or the last registrant), the whole data tree. The table then came back empty. One real trigger is a server killed between the Keeper commit and the local metadata rename of `ALTER TABLE ... MODIFY COMMENT`: the digest check declares the replica lost on restart. Measured on 26.8.10.6 with an strace-injected SIGKILL: 50 rows before, 0 after. Recovery already has the right class for tables whose data is shared Keeper state: replicated MergeTree tables are matched by UUID, kept or renamed in place, and an unmatched one is moved to `<database>_broken_replicated_tables`, an `Atomic` database that keeps the UUID. Put `KeeperMap` tables into that class: - `getTableUUIDIfReplicated` also returns the UUID of a `KeeperMap` definition (Keeper side); - the local reconciliation loop matches a local `KeeperMap` table by UUID; - the drop/move branch never drops a `KeeperMap` table (unless `database_replicated_drop_broken_tables` is set) and moves an unmatched one to `<database>_broken_replicated_tables`. Both identification sides must agree: with only one of them, the moved copy and the re-created table collide on the UUID and recovery fails on every retry. A UUID identifies a `KeeperMap` table because only its comments can be altered. Moving it to `<database>_broken_tables` instead does not work: that database is `Ordinary` and `KeeperMap` refuses a table without a UUID, so recovery would fail on every attempt. A kept table keeps its local comments, as a replicated MergeTree table keeps its local metadata. The test forces recovery of three tables whose Keeper definitions were altered, renamed and dropped, and checks that each keeps its 50 rows. Closes ClickHouse#111957 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review of the same head.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260929-160200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260929-141300 |
|
Workflow [PR], commit [5f2c1b4] Summary: ✅
AI ReviewSummaryThis PR changes Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 5f2c1b4.
Changed lines: Changed C/C++ lines covered: 22/22 (100.00%) · Uncovered code |
…es its path Moving an unmatched `KeeperMap` table to `<database>_broken_replicated_tables` does not isolate it: `StorageKeeperMap::rename` keeps the table's registration on its Keeper path. When another table is registered on the same path (the table another replica re-created there after the DROP this replica missed, or the new table of a `CREATE OR REPLACE` interrupted by a crash), the moved copy stays a second live handle on that table's data. Writes through it change the live table, and a later `DROP` of the live table keeps the data in Keeper, so a table re-created on that path gets the old rows back. Measured on the previous head: an `INSERT` into the moved copy showed up in the other table (50 -> 51 rows); after that table was dropped, 51 data nodes stayed in Keeper and a new table on the path read 51 rows. In that case the drop loses nothing: `StorageKeeperMap::drop` only removes this table's registration and leaves the data to the other table. So recovery now moves an unmatched `KeeperMap` table only when no other table is registered on its path (dropping it would delete the data), and drops it otherwise. `StorageKeeperMap::isPathUsedByAnotherTable` reads the registrations. The test gets an arm for this: `km_shared` is dropped in Keeper while `km_twin` uses the same Keeper path. Recovery drops `km_shared`, and `km_twin` keeps its 50 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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, 16 s compile time in total, 7 of them have a recent master baseline. |
…table A registration on a `KeeperMap` path is the table UUID followed by the server UUID, so another replica of the same table also has one. Counting it made two lagging replicas of a table dropped in Keeper both see "another table" and both drop their copy; the last drop then deleted the data and no replica kept a copy in `<database>_broken_replicated_tables`. Only a registration with a different table UUID now counts: every replica of a dropped table keeps its own copy, and a table another replica re-created on the path still makes the drop keep the data. The test gets a `km_replica` arm with a registration of the same UUID from another server: the table is moved with its 50 rows (with the previous commit it was dropped). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A moved `KeeperMap` table keeps its registration on its Keeper path (`StorageKeeperMap::rename` only changes the `StorageID`), and a new `KeeperMap` table on an existing path shares the data registered there. So a copy in `<database>_broken_replicated_tables` cannot be isolated from a table created later on the same path, for example when the user re-creates the table that was dropped: that table gets the old rows back, writes through the copy change it, and its `DROP` keeps the data in Keeper. Checking the registrations during recovery (the previous two commits) covers only a table that already exists at that moment. Measured on the previous head: the table re-created on the path after recovery read 50 rows, 51 after an `INSERT` into the moved copy, and still 51 after it was dropped and created once more. On master it reads 0. A `KeeperMap` table whose UUID is not in Keeper was dropped there, so recovery drops it too, as master does. `StorageKeeperMap::drop` deletes the data only when no other table is registered on the path. Tables are still matched by UUID, so one that was altered or renamed in Keeper keeps its data. The test keeps the altered and renamed arms, and the dropped arm now checks that a table re-created on the Keeper path of the dropped one starts empty. The `km_replica`, `km_shared` and `km_twin` arms covered the removed branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #111957
Related: #118011
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed replica recovery of a
Replicateddatabase deleting the data of aKeeperMaptable, for example after the server was killed during anALTERof that table. AKeeperMaptable that still exists in Keeper is now kept or renamed with its data, instead of being dropped and re-created empty. Closes #111957.Description
On 26.8.10.6 and 26.3.33.24, a recovering replica of a
Replicateddatabase drops aKeeperMaptable whose definition differs from the one in Keeper, and re-creates it. When it is the last table registered on its Keeper path (a single-replica database), the drop deletes the data and the table comes back empty: 50 rows to 0.recoverLostReplicadrops every diverged table that does not store data on disk, and aKeeperMaptable keeps its data in Keeper. One real trigger: a server killed between the Keeper commit and the local metadata rename ofALTER TABLE ... MODIFY COMMENTis declared lost on restart. Measured on 26.8.10.6 (SIGKILL injected withstrace): 0 of 50 rows left.Recovery already avoids re-creating replicated MergeTree tables: it matches them by UUID and keeps or renames them. This PR matches
KeeperMaptables by UUID too, on both sides (Keeper metadata and local tables). A UUID identifies aKeeperMaptable: its columns and engine arguments cannot be altered, only its comments. AKeeperMaptable whose UUID is not in Keeper was dropped there, and recovery still drops it: a copy moved to<database>_broken_replicated_tableswould stay registered on its Keeper path and give its rows to any table created there later. The issue's<database>_broken_tablesisOrdinary, whichKeeperMaprejects.A kept table keeps its local comments, like a replicated MergeTree table. Not changed here:
S3QueueandAzureQueue(also keeping state in Keeper) and theMaterializedViewinner table case (#111935).05293_keeper_map_replica_recovery_keeps_datarecovers three tables: altered, renamed and dropped in Keeper. Master drops all three and deletes their data. The fix keeps the 50 rows of the first two (40/40 randomized runs, also after thestracecrash) and drops the third, so a table re-created on its Keeper path starts empty.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122917]
Version info
26.10.1.1044-master(included in26.10and later)