Repository navigation
Do not list every key node when dropping a KeeperMap table - #129440
Conversation
`StorageKeeperMap::dropTableData` removed the keys with `ZooKeeper::removeChildrenRecursive`, which calls `getChildren` on every child before removing it. KeeperMap keys are always leaf nodes (`data/<url-safe base64 key>`), so a drop of N keys cost N empty `List` round trips plus N/100 multi requests, serialized on one session. Use `tryRemoveChildrenRecursive(path, /*probably_flat=*/ true)`, which TRUNCATE already uses for the same `data/` node: one `List` of `data/`, then removals in batches of 100. If a batch fails with a user error it falls back to per-node removal and removes a non-empty child recursively; hardware errors still throw. The final multi that removes `data/` and the metadata still reports leftovers as before. The drop runs in the background drop task, and server shutdown waits for it, so a large KeeperMap drop in flight held shutdown: La Casa Del Dolor (amd_tsan) force-killed the server after 30 s while a dropped table's keys were still being walked, ~1000 batches of 100 into the drop (Keeper commit log of PR ClickHouse#129287's run). Measured on a debug build with the embedded Keeper, 200000 keys: DROP TABLE ... SYNC 133.6/141.4/176.0 s -> 11.3/11.3/11.3 s; SIGTERM right after a non-SYNC DROP until exit 194.3/161.5/153.8 s -> 13.8/14.4/13.9 s; per-key List requests 200000 -> 0. 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; 0 findings) plus my own cold review (nits only, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261105-054300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261105-043600 |
|
cc @PedroTadim @Michicosun, could you review this and add the |
|
Workflow [PR], commit [39d5550] Summary: ✅
AI ReviewSummary
Missing context / blind spots
Final Verdict✅ Approve — no new actionable findings. The prior bot-authored compatibility thread has been resolved. |
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, 18 s compile time in total, 7 of them have a recent master baseline. |
|
@groeneai why not use |
| throw zkutil::KeeperException(Coordination::Error::ZOPERATIONTIMEOUT, "Manually triggered operation timeout"); | ||
| }); | ||
| zookeeper->removeChildrenRecursive(zk_data_path_); | ||
| zookeeper->tryRemoveChildrenRecursive(zk_data_path_, /*probably_flat=*/ true); |
There was a problem hiding this comment.
@groeneai are you sure this won't ever leak nodes? Check if other places also need this improvement such as truncating a KeeperMap table?
There was a problem hiding this comment.
Yes. It lists data/ once and removes every listed child in multis of 100 (ZooKeeper.cpp:1126-1198). If a multi fails, the children of that batch are removed one by one: ZNONODE is skipped, ZNOTEMPTY (a key with children, which KeeperMap does not create: keys are base64url leaves) removes that child's subtree, and any other error throws, as the old code did. A node still there afterwards, e.g. one created after the listing, is caught by the final multi, which removes data/ together with the metadata (StorageKeeperMap.cpp:1091): a non-empty data/ fails it with ZNOTEMPTY (:1114), the dropped marker stays, and the next table created on that path removes the leftovers (:597, :637). That part is unchanged; the old removeChildrenRecursive also listed data/ only once. The test checks that the table's root node is gone after the drop.
Other places: TRUNCATE already makes this exact call on the same node (StorageKeeperMap.cpp:994), I took it from there. Every drop path (drop(), dropTableFromZooKeeper, the leftover cleanup in the constructor) goes through the line changed here, and DELETE removes the matching keys by path (:1801) without a listing. Outside ZooKeeper.cpp, nothing calls removeChildrenRecursive after this PR.
With the default With a limit that covers the table it is much faster, though. Local debug server, embedded Keeper, request counts from Keeper's
So I can switch |
|
@groeneai it's fine if it fallbacks to non RemoveRecursive option but it's worth trying in case the table is small. |
Per review: `dropTableData` now removes `data/` with `tryRemoveRecursive`, so a table whose `data/` subtree fits in `remove_nodes_limit` (1000 nodes, root included) is removed with one `RemoveRecursive` request. Bigger tables, or a Keeper without the `REMOVE_RECURSIVE` feature flag, fall back to the flat `tryRemoveChildrenRecursive` path from the previous commit: `tryRemoveRecursive` gets a `probably_flat` argument that it passes to the fallback. `data/` is now removed before the final multi rather than in it, so the multi no longer removes `data/`; the removal of the root node still fails with `ZNOTEMPTY` while anything is left under it, keeping the leftover detection. Any other error of the removal is thrown, as before. A drop interrupted between the two steps leaves `data/` already gone, which the leftover cleanup on the next `CREATE` handles (checked by hand: it removes the remaining nodes and creates the table). Debug build, embedded Keeper: dropping 999 keys 80-88 ms -> 28-32 ms; 200000 keys (fallback) 11.29 s -> 10.95 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Done in a153247: The test now drops 999 keys (one |
The previous commit removed data/ with a standalone RemoveRecursive request before the multi that removes the table metadata. A drop interrupted between the two leaves metadata/dropped without data/, and the leftover cleanup of servers without this change starts with removeChildrenRecursive(data/), which throws ZNONODE, so a CREATE on such a server fails on every retry (measured with a master binary sharing the Keeper: "No node, path .../data"; same code on 26.3, 26.8, 26.9, 26.10). Put RemoveRecursive of data/ into the metadata multi instead. When Keeper does not support it, or the multi fails with ZNOTEMPTY (the 1000-node limit), remove the keys with the flat tryRemoveChildrenRecursive path first and remove data/ with a plain Remove in the multi, as before. An interrupted drop now always leaves data/ in place. The tryRemoveRecursive signature change is no longer needed and is reverted. The test now requires the RemoveRecursive to be in the same multi request as the removal of metadata/, and no removal of data/ in any other request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@antonio2368, you finish the review. The PR became too large for my threshold 😄 |
Related: #129287
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
DROP TABLEof aKeeperMaptable no longer sends a KeeperListrequest for every key before removing it, and removes the keys of a table with fewer than 1000 keys in the same Keeper request as its metadata when Keeper supportsRemoveRecursive. Dropping a table with 200000 keys is more than 10 times faster, and so is a server shutdown that waits for such a drop.Description
StorageKeeperMap::dropTableDataremoved the keys withZooKeeper::removeChildrenRecursive, which callsgetChildrenon every key node. KeeperMap keys are leaf nodes, so dropping N keys cost N emptyListround trips.Server shutdown waits for a KeeperMap drop in the background drop task: in La Casa Del Dolor (amd_tsan) on #129287 the server was force-killed after its 30 s stop window while the drop was still in
removeChildrenRecursive->getChildren.The drop now removes
data/with aRemoveRecursiveoperation inside the multi request that removes the table metadata, when Keeper supports it. Without that support, or whendata/has more than 1000 nodes (the operation's limit), the keys are first removed with the flattryRemoveChildrenRecursivepath thatTRUNCATEalready uses (oneListofdata/, then batched removes), anddata/is removed with the metadata as before. So an interrupted drop still leavesdata/in place, which the leftover cleanup of older servers needs on the nextCREATE.Measured on a debug build with the embedded Keeper, 3 runs, before -> after (200000 keys unless noted):
DROP TABLE ... SYNC: 133.6 / 141.4 / 176.0 s -> 11.2 / 11.1 / 11.1 s; per-keyListrequests 200000 -> 0.SIGTERMright after a non-SYNCDROP, until the server exits: 194.3 / 161.5 / 153.8 s -> 13.4 / 14.4 / 14.1 s.DROP TABLE ... SYNC: 956-999 ms -> 24-31 ms.The test drops a 999-key and a 1000-key table (the two sides of the limit) and counts requests in
system.zookeeper_log: master sends oneListper key and noRemoveRecursive; with the change, oneRemoveRecursiveper table in the same multi request as the metadata removal, no per-keyList, and no per-key request at all for the small table.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129440]
Version info
26.11.1.1768-master(included in26.11and later)