Repository navigation
Keeper: index uncommitted nodes by parent so RemoveRecursive preprocessing does not scan all uncommitted nodes - #117778
Conversation
…cessing does not scan all uncommitted nodes Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [e05536b] Summary: ✅
AI ReviewSummaryThis PR replaces the Missing context / blind spots
Final VerdictNo blocking issues found in the current diff. LLVM Coverage ReportMeasured on commit e05536b.
Changed lines: Changed C/C++ lines covered: 191/193 (98.96%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units12 translation units recompiled, 44 s compile time in total, 12 of them have a recent master baseline. |
…-remove-recursive-uncommitted-index
…o `RemoveRecursive` preprocessing does not scan all uncommitted nodes
Backport #117778 to 26.8: Keeper: index uncommitted nodes by parent so `RemoveRecursive` preprocessing does not scan all uncommitted nodes
As suggested in review, exclude the timing assertion of TestRemoveRecursivePreprocessWithUncommittedBacklog from ASan, TSan and MSan builds instead of switching its clock, and restore the wall clock. Both failures of the bound so far were one-off stalls of about 80-110 ms in Unit tests (tsan), with a normal baseline and the /LSMT arm of the same process unaffected. A thread CPU clock removes host preemption, but still counts any sanitizer runtime work done on the measured thread. The bound keeps running in Unit tests (amd_llvm_coverage), the unit-test job built without a sanitizer, on PRs and master. There /Mem measures 121-139 us without backlog and 221-264 us with it, against the 20 ms floor. With the pre-ClickHouse#117778 storage code restored (0ddbd00 and 4f8f8f5 reverse-applied to KeeperMemNodesStorage only) the test still fails in a non-sanitizer Debug build, at 318624 us against a 142 us baseline. The rest of the test, including its functional assertions, still runs under sanitizers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…caling guard Storage/CoordinationTest.TestRemoveRecursivePreprocessWithUncommittedBacklog/Mem failed once in Unit tests (tsan) at 108883 us against its max(base_us * 10, 20000) allowance, the first failure since the guard landed in ClickHouse#117778 seventeen days earlier. The product code is not at fault. Seven sibling Unit tests (tsan) runs that morning measured 813-944 us to 1046-1232 us, a ratio of 1.17x to 1.53x, and the /LSMT arm inside the failing process itself measured 1.2x while its neighbouring tests took the same milliseconds as in a passing run: one sample moved and nothing else did. The by-parent index added by ClickHouse#117778 still covers the exercised path, and nothing reachable from preprocessRequest here is linear in the uncommitted set. The observed rate is one failure in 27022 rows over 30 days. The assertion bounds the wall time the host granted a single unrepeated ~1 ms window, while the property it guards is the work the algorithm performs. A stall the algorithm did not cause, such as thread preemption on a loaded runner, a ThreadSanitizer stop-the-world shadow flush or kernel reclaim, adds its full duration to a wall-clock sample and can never subtract from it, so roughly 107 ms of stall crossed the 20 ms floor. Constructing the two Stopwatch objects with CLOCK_THREAD_CPUTIME_ID makes the guard bound the quantity it actually claims. The allowance, the EXPECT_LE message, the subtree sets, the 100000-node backlog and every functional assertion are unchanged. Raising the threshold was rejected: surviving a 107 ms stall would need a floor above 110 ms, and this batch cost hundreds of milliseconds before ClickHouse#117778, so such a floor would leave the guard almost no detection margin. Validated in a Debug build. Reverse-applying 0ddbd00 and 4f8f8f5 on KeeperMemNodesStorage only makes the fixed test fail at 323253 us of CPU time, 16x over the floor, so the guard still catches the regression it exists for. A 150 ms sleep_for injected into the measured window fails on wall clock (150451 us) and passes on the new clock (587 us), while a 150 ms CPU spin fails on both, so the new clock filters the observed failure class without going blind. Fifty consecutive runs are 100/100 green with backlog samples of 233-840 us, against 236-495 us on wall clock before the change, and the maximum base_us of 565 us keeps base_us * 10 below the 20 ms floor, so the effective bound is unchanged. Related: ClickHouse#117778 Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Keeper: preprocessing of a
RemoveRecursiverequest no longer scans all uncommitted nodes. With a large uncommitted backlog, many concurrentRemoveRecursiverequests could saturate the request processing thread and raise request latency above the client operation timeout.Problem
KeeperMemNodesStorage::visitUncommittedRecursivecollected the uncommitted children of the removed subtree by iterating the wholeuncommitted_nodesmap once perRemoveRecursiverequest. The cost of one request was therefore proportional to the number of uncommitted nodes in flight, not to the size of the removed subtree.Normally the uncommitted set is small. It becomes large when
Multirequests with tens of thousands of subrequests are in flight or when the commit backlog grows to hundreds of log entries. In that state a workload that sends several thousand smallRemoveRecursiverequests per second makes each of them scan tens of thousands of entries. On followers this work happens inpre_commiton the Raft append path, so their acknowledgements slow down and the leader's commit rate collapses. The effect feeds itself: slower preprocessing grows the backlog, and a larger backlog makes each request slower. The preprocessing thread was observed at close to 100 percent utilization while CPU, memory and disk on the Keeper nodes were far from their limits, and request latency reached tens of seconds with sessions expiring on the client operation timeout.The scan has existed since
RemoveRecursivewas added (#69332, 2024-09). #86789 (2025-09) reduced it from one pass per visited node to one pass per request, which is the form fixed here.Fix
KeeperMemNodesStoragekeeps a new indexuncommitted_children_by_parent, a map from a parent path to the set ofuncommitted_nodesiterators of its children. Two helpers,addUncommittedNodeanderaseUncommittedNode, are now the only code that inserts into or erases fromuncommitted_nodes; they replace the five former direct call sites and keep the index in sync, including cleanup after commit and after rollback.visitUncommittedRecursivelooks the uncommitted children of each visited node up by that node's path instead of scanning, and sorts them by path so the visit order stays deterministic across replicas.The cost of a
RemoveRecursiverequest is now proportional to the subtree it removes.KeeperLSMTNodesStoragealready lists uncommitted children per node and is not changed.Tests
Two tests in
gtest_coordination_storage.cpp, parametrized over both storages.TestRemoveRecursivePreprocessWithUncommittedBacklogpreprocesses oneMultiof 50RemoveRecursiverequests on small committed subtrees, first with no backlog and then with 100,000 uncommittedCreaterequests in flight, commits everything and checks the result. It asserts that the second preprocessing takes at most ten times the first or 20 ms. RelWithDebInfo measurements:TestRemoveRecursiveSeesUncommittedChildrenUntilRollbackchecks that an uncommitted child still counts towardremove_nodes_limitand stops counting after the request that created it is rolled back.The full
*Coordination*unit test suite passes.Workflow [PR]
Sync PR [sync-upstream/pr/117778]
Version info
26.9.1.669(included in26.9and later)26.8.3.30