Repository navigation
clean orphans from keeper snapshots - #95761
Conversation
|
Workflow [PR], commit [188c668] Summary: ✅
AI ReviewSummaryThis PR adds startup-time orphan detection and optional cleanup for corrupt Keeper snapshots, then verifies the local log tail before startup continues so repaired replicas do not silently diverge. Most of that flow is now consistent, but the remaining Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 188c668.
Changed lines: Changed C/C++ lines covered: 418/481 (86.90%) · Uncovered code |
antonio2368
left a comment
There was a problem hiding this comment.
It cannot be done like that because those orhpaned nodes are taken into account for digest calculation.
If you do it like this, digest will go completely out of sync between the nodes leading to inconsistent state.
|
back to the drawing board then, thanks for the feedback! |
I've added the safe guards, it will be removed only if remove_orphaned_nodes_on_startup is set to true and digest_enabled is set to false. |
843a9f8 to
2a4f030
Compare
groeneai
left a comment
There was a problem hiding this comment.
This PR adds detection and optional removal of orphaned znodes (nodes whose parent is absent from the container) during Keeper snapshot deserialization for the in-memory storage path. A new config option keeper_server.remove_orphaned_nodes_on_startup (default false) gates the feature; removal also requires digest_enabled=false. When orphans are detected but removal is not allowed, the code throws an actionable exception replacing the previous cryptic crash from updateValue on a missing parent key. The three-pass algorithm (detect orphan roots, expand to descendants, build children for non-orphans) is correct.
The feature is well-motivated and the default behavior is safe. However, I noticed the recovery path has a correctness gap with stale numChildren on surviving ancestors, an unnecessary performance regression on every normal startup, and insufficient deletion logging.
General findings:
-
Missing test:
remove_enabled=true+digest_enabled=truerejection path. Thecan_removelogic at line 599 checks both conditions, but the digest-safety rejection branch is never exercised by any test. I'd suggest adding a test that setsremove_orphaned_nodes_on_startup=trueanddigest_enabled=true, inserts an orphan, and asserts that deserialization throws with the "digest is enabled" reason string. -
Missing test: orphan under existing ancestor with stale serialized
numChildren. The existing tests insert orphans viainsertOrReplace()directly, which doesn't update any ancestor'snumChildren. A realistic corruption scenario where an intermediate node is lost would leave the surviving ancestor with a stale count. A test should create/awithnumChildrenreflecting a child/a/missing, then have/a/missing/childas an orphan, and verify correctnumChildrenon/aafter removal. -
RocksDB scope limitation. The feature only applies to in-memory storage (
!use_rocksdb). Tests correctly skip RocksDB. This limitation should be explicit in any release note or config documentation.
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
e4ad6b9 to
7455115
Compare
|
The flaky check failure is fixed in #102148, let's update the branch. |
Review — PR #95761 (clean orphans from keeper snapshots)SummaryThe PR replaces an opaque Re: the clickhouse-gh bot's backward-compat concernThe bot wrote "before this PR they were cleaned automatically during load". That's a misreading of the old code. The old loop storage.container.updateValue(parent_path, [path = itr.key](auto & v) { v.addChild(...); });throws on a missing key:
So the pre-PR behavior on a snapshot with orphans was Keeper fails to start with a cryptic ClickHouse Rules
Majors
Nits
Tests — additional cases worth considering
Final VerdictApprove with suggestions. Majors should be addressed or explicitly acknowledged; Nits are optional. The bot's backward-compat concern is based on a misreading of the prior behavior — the default path still refuses to load orphan snapshots (same outcome as before, clearer error). Net: this is a clean improvement that turns a mysterious startup exception into a documented, opt-in recovery path. Reviewed via |
|
📊 Cloud Performance Report
This PR only changes ClickHouse Keeper: it adds opt-in removal of orphaned nodes when a corrupt snapshot is loaded at startup, plus a check of log entries above the snapshot, docs and a unit test. None of that code runs during ClickBench or TPC-H query execution. Neither flagged query shows a performance effect from this PR. ClickBench Q23 (-45.7%) is inconclusive because master's own timings for it shifted around 2026-09-28, and Q31 (+10.7%, CPU time unchanged) falls inside master's recent range. Both stay not_sure, which is consistent with the diff. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
PR ClickHouse#117521 added the ListWithOptions op to Keeper. The forEachRequestPath switch in the orphan-cleanup verifier was missing a case for it, causing -Werror,-Wswitch build failures when merged with current master. ListWithOptions supports both direct and recursive listing via its options, so the kind is determined dynamically: Subtree when options.recursive is set, NodeAndChildren otherwise.
…phan log-tail verifier `Check`/`CheckNotExists` and the data/child/exist lists of `SetWatches`/`SetWatches2` only observe a node's existence, ACL, `version`, `mzxid` and `pzxid`, none of which orphan cleanup changes on the repaired direct parent of a removed subtree. They now use a new `RequestPathKind::NodeOnly` that conflicts only inside the removed region. The persistent watch lists of `SetWatches2` are registered without consulting the tree, like `AddWatch`, so they are no longer checked at all. `CheckStat` stays broader because it can compare `numChildren`/`cversion`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed
Local run: 488 |
…eck; sync setting docs `RemoveRecursive` of `/` or of the internal Keeper path, and a `ListWithOptions` with an unsupported options version or recursive with a watch, are rejected by their handlers before the tree is consulted, identically on every replica. The verifier reported them as `Subtree` conflicts and refused a harmless tail. Also sync the `remove_orphaned_nodes_on_startup` row in the Keeper settings table with the implemented contract (direct parent only, higher ancestors only for whole-subtree walks) and mention that it is rejected with `use_lsmt_storage`. Addresses review threads on ClickHouse#95761 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…questsInLogTail` The first entry is at index 1 and is covered by the snapshot, so the valid recursive `ListWithOptions` is the fifth entry. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…hildren-sensitive fields `checkNodeStat` compares only the fields of `stat_to_check` that are not `-1`. Orphan cleanup changes only `numChildren` (and the children set) of the repaired direct parent, so a `CheckStat` comparing neither `numChildren` nor `cversion` replays identically and must not block recovery. Added a positive test for a version-only `CheckStat` on the repaired parent. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…lock orphan recovery Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`Set` and `SetACL` check the node's existence, ACL and `version`/`aversion` and rewrite only the node's own data or ACL (plus the parent's `cversion` for `Set`, which orphan cleanup never changes). They never read the children set or `numChildren`, the only things cleanup repairs on the removed root's direct parent, so classify them as `RequestPathKind::NodeOnly` instead of `NodeAndChildren`. Add a regression test replaying both on the repaired parent. Addresses review: ClickHouse#95761 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CreateIfNotExists of an already-existing node, TryRemove of a non-existent node, and Remove of a non-existent node are all no-ops that return before touching the parent's stats. The unconditional ParentStats edge in forEachRequestPath made findOrphanConflictInLogTail reject startup for these harmless tail entries, which in a single-node Keeper (or quorum-loss scenario) could deadlock recovery: the log cannot advance without a leader, and startup is blocked. The fix checks the committed snapshot state when a ParentStats conflict is detected for these ops. An earlier tail entry that flips the node's existence would itself be a create/remove under the repaired parent and would have already been reported, so reaching this point means the snapshot state is authoritative. Tests: OrphanRemovalAllowsNoopCreateIfNotExistsUnderRepairedParent, OrphanRemovalAllowsNoopTryRemoveUnderRepairedParent, OrphanRemovalRefusesEffectiveCreateIfNotExistsUnderRepairedParent.
8ed4339
A non-permanent `DETACH` keeps the table's definition in `DatabaseMemory::create_queries` (a short `ATTACH` rebuilds the table from it) and its dependency edges in `DatabaseCatalog`. `DatabaseMemory` did not implement `IDatabase::checkMetadataFilenameAvailability`, which is documented to throw when the name is taken in any state, and `DatabaseMemory::createTable` did not refuse a full-definition `ATTACH` over a detached name either. So `CREATE`, `CREATE OR REPLACE` and a full `ATTACH` of a detached name were accepted: `create_queries.emplace` kept the old definition, the new object's dependencies were merged into the old ones, `SHOW CREATE TABLE` printed the detached object, and a later `ALTER` cloned the stale definition and failed in `applyMetadataChangesToCreateQuery` (`IAST::replace` of `refresh_strategy` or `select`, which the stale definition does not have) with the exception `Logical error: 'AST subtree not found in children'`. Now `DatabaseMemory` refuses these statements with `TABLE_ALREADY_EXISTS`, as the on-disk engines do: `checkMetadataFilenameAvailability` refuses a `CREATE` before its storage is built (`IF NOT EXISTS` stays a no-op), and `createTable` refuses a full-definition `ATTACH`, for which the interpreter does not call the hook. Only a short `ATTACH` can reuse the name, and it keeps the stored definition. Found by `BuzzHouse (amd_debug)` (STID 1403-2c69) in the CI of an unrelated PR. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=95761&sha=1360c0e9939437424c044f7dc9ec24a5d799ea49&name_0=PR&name_1=BuzzHouse%20%28amd_debug%29 Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36374880353/job/108805418720 PR: ClickHouse#95761 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This change makes ClickHouse Keeper able to recover from snapshots that contain orphaned nodes — nodes whose parent is absent from the snapshot.
Before this change, such a snapshot made Keeper fail to start with an opaque internal error thrown by
updateValue("Could not find key"). This pull request replaces that with a clear, opt-in recovery path:keeper_server.remove_orphaned_nodes_on_startup=false), Keeper still refuses to load a snapshot with orphaned nodes, but now throws an actionableCORRUPTED_DATAexception that reports the number of orphaned nodes and how to enable recovery.keeper_server.remove_orphaned_nodes_on_startup=trueandkeeper_server.digest_enabled=false, the orphaned nodes and all of their descendants are removed during startup, ACL usage counters and ephemeral bookkeeping are updated, and stalenumChildrencounters on surviving nodes are corrected, so Keeper can load the snapshot.Cleanup is strictly a startup recovery operation. A snapshot deserialized while the server is already running — for example, a follower applying a leader snapshot in
KeeperStateMachine::apply_snapshot— is applied as-is and is never modified, so a follower cannot diverge from the rest of the cluster.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ClickHouse Keeper now throws an actionable
CORRUPTED_DATAerror reporting the number of orphaned nodes (nodes whose parent is missing) when loading a snapshot that contains them, instead of failing with an opaque internal error. With the new settingkeeper_server.remove_orphaned_nodes_on_startupset totrueandkeeper_server.digest_enabledset tofalse, such orphaned nodes (and their descendants) are removed during startup so Keeper can load the snapshot. The cleanup is performed only on startup, never while the server is running.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/95761]
Version info
26.10.1.1039-master(included in26.10and later)