Repository navigation
perf!: borrow the pending batch when building delete operations - #995
Conversation
delete_operation_for_delete_internal and delete_operations_for_delete_up_tree_while_empty took the operations already pending in the batch as a slice and an owned Vec. A caller that keeps its batch in its own operation type had to copy the whole batch for every delete it built, so building k deletes into one batch cost O(k^2) copies, although GroveDB reads none of them unless the deleted element is a tree, and then only those at that tree's own path. Both now take the pending operations by reference as an IntoIterator of &QualifiedGroveDbOp (also Clone for the up-tree builder, whose levels each read them). The single-delete builder reads them in one pass and only in the tree branch. The operations built and their costs are unchanged. add_delete_operations_for_delete_up_tree_while_empty keeps its signature. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughDelete-operation APIs now accept borrowed pending-operation iterators. Tree deletion scans operations at the target path once. Recursive up-tree deletion carries generated deletes separately. Tests compare borrowed inputs with slice and mutable-vector forms. ChangesDelete operation generation
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Merge Risk: ⚪ Minimal · up to The reviewed delete-generation changes preserve the examined behavior, with no identified issue requiring a fix before merge. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The reviewed delete paths retain their tree-emptiness checks and operation-application boundary, and no introduced security failure was established. Risk remains because the change also affects backward-reference handling across batch operations, whose end-to-end behavior was not fully covered. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🕓 Queued for automated review — 4th in line, estimated start in ~25 min (commit c70dadd)
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #995 +/- ##
=========================================
Coverage 93.09% 93.10%
=========================================
Files 332 336 +4
Lines 105213 105421 +208
=========================================
+ Hits 97950 98153 +203
- Misses 7263 7268 +5
🚀 New features to boost your workflow:
|
…ending batch
Review follow-ups on the pending-batch borrow.
The delete builder counted a pending DeleteTree with
SubelementsDeletionBehavior::Skip as removing its child. The apply path
drops such a delete when the child is not empty, so a parent emptied only
by it was built as DeleteTree(DontCheckWithNoCleanup) and deleted without
cleanup over the child it kept, orphaning the child and its contents with
verify_grovedb reporting nothing. From GROVE_V4 (slot
delete.delete_operation_for_delete_internal = 1) the builder counts only
the deletes GroveOp::always_removes_its_key accepts, the rule the batch
pre-scan now shares through QualifiedGroveDbOp::key_always_removed_at.
The builder moves to delete_operation_for_delete_internal/{mod,v0,v1}.rs;
v0 keeps the old rule for GROVE_V1..V3.
The builders take `impl PendingOperations` and ask it for the operations
at one path, the deleted tree's own. Every IntoIterator<Item =
&QualifiedGroveDbOp> + Clone implements it by scanning, as before, and a
caller with a large batch can implement it over an index by path so a
question costs only the operations there. The up-tree chain passes each
level the key the level below deleted instead of re-reading all of its
deletes, collects its deletes once, and
add_delete_operations_for_delete_up_tree_while_empty appends them to the
caller's Vec only when every level is built. Deleted keys are collected
only for Merk trees.
Operations and costs are unchanged apart from the V4 rule: the tests pin
the costs develop charges, at GROVE_V3 and the latest version, and cover
an index by path, non-Merk trees, the Skip rule on both versions, a write
higher up stopping the climb, and the Vec left as it was on an error.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
GroveDB dashpay/grovedb#995 lets delete_operation_for_delete_internal and delete_operations_for_delete_up_tree_while_empty borrow the pending operations and ask only for those at the deleted tree's own path. Bump GroveDB to dce8252f and pass the batch's grove operations as they are, dropping Drive's copy of GroveDB's selection rules. The operations built and their costs are unchanged. The old-copy comparison tests keep batch_delete, the up-tree chain and batch_remove_raw; batch_move and the path-query helpers changed the same way as batch_delete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Issue being fixed or feature implemented
delete_operation_for_delete_internalanddelete_operations_for_delete_up_tree_while_emptytake the operations already pending in the batch being built, so a delete can account for them: a tree whose children the batch already deletes counts as empty, and a tree the batch writes into does not. They took those operations as&[QualifiedGroveDbOp]and an ownedVec<QualifiedGroveDbOp>.A caller that keeps its batch in its own operation type has no such slice to hand over, so it has to copy the whole pending batch, element values included, on every delete it builds. Building k deletes into one batch then costs O(k^2) copies, although GroveDB reads none of them unless the deleted element is a tree, and then only those at that tree's own path. Dash Platform's Drive keeps its batch as
LowLevelDriveOperations and did exactly this: building about 400 deletes into one batch took 21 ms and about 4,000 took 1.9 s, almost all of it copying. dashpay/platform#5004 works around it on the Drive side by copying only the operations it knows GroveDB reads, which means Drive has to mirror GroveDB's selection rules.Review of this PR also found that the builder counts a pending
DeleteTreewithSubelementsDeletionBehavior::Skipas removing its child. The apply path drops such a delete when the child is not empty, so a parent emptied only by it is built asDeleteTree(DontCheckWithNoCleanup)and deleted without cleanup over the child it keeps. Reproduced: the parent element is gone, its Merk still holdschild,childstill holds its item, andverify_grovedbreports nothing.What was done?
Pending operations are asked for by path. Both builders take
current_batch_operations: impl PendingOperations<'a>, a new trait with one method,at_path(&self, path) -> impl Iterator<Item = &'a QualifiedGroveDbOp>. A builder asks it only when the deleted element is a tree, and only for that tree's own path; an up-tree chain asks once per tree it climbs through.IntoIterator<Item = &QualifiedGroveDbOp> + Cloneimplements it by scanning: a slice,&Vec,ops.iter(), or an adapter over the caller's own operation type (ops.iter().filter_map(CallerOp::grove_op)).Up-tree chain. Each level gets the key the level below deleted, the only one of the chain's own deletes at that tree's path, instead of re-reading all of them. The chain collects its deletes once.
add_delete_operations_for_delete_up_tree_while_emptykeeps its signature and appends the chain's deletes to the caller'sVeconce every level is built. On an error it leaves theVecas it was; before, it kept the deletes built below the failing level.Skipdeletes, gated toGROVE_V4. The builder moves tooperations/delete/delete_operation_for_delete_internal/{mod.rs,v0.rs,v1.rs}(slotdelete.delete_operation_for_delete_internal, V4 = 1).GroveOp::always_removes_its_keyaccepts, so a pendingSkipdelete leaves its child counted as present.QualifiedGroveDbOp::key_always_removed_at. The refactor leaves their behaviour unchanged.GROVE_V1..V3. Excluding theSkipkey changes theis_empty_tree_exceptwalk and so the cost, which is why it is gated.Also: deleted keys are collected only for Merk trees, and the builder re-checks each returned operation's path, so an index that returns more than it was asked cannot change the result.
How Has This Been Tested?
grovedb/src/tests/delete_pending_operations_tests.rs, every test at bothGROVE_V3and the latest version. Each result is built three ways (slice, adapter over a caller's own op type, index by path), and for the up-tree builder a fourth way through the&mut Vecform. All must agree.Skipdelete of a non-empty child is counted on V3 (the old build and cost are pinned) and not on V4, where the result and cost match having nothing pending. A pendingErrordelete counts on both.Vecunchanged.Skipdeletes in v1; appending to theVecon error.cargo test -p grovedb --all-features(3,547 unit tests, the integration tests and doctests, all passing) andcargo test -p grovedb-version.cargo clippy --workspace --exclude grovedb-bincode --exclude grovedb-bincode-derive --all-features --no-deps -- -D warnings, pluscargo clippy -p grovedb --all-features --all-targetswith no lints in the files this touches.cargo check --workspace --exclude grovedb-bincode --exclude grovedb-bincode-derive --all-features --all-targets,cargo check -p grovedb --no-default-features --features verify,cargo doc -p grovedb --all-features --no-deps(no warnings in touched files),cargo fmt --all -- --check.Breaking Changes
impl PendingOperations<'a>.&[],&opsfor aVecor sliceops,ops.iter(),vec![], and adapters over the caller's own operations.&mut Vec,&&Vec,&Box<[_]>or&Arc<Vec<_>>is passed asops.iter().Vec<QualifiedGroveDbOp>for the up-tree builder is passed as&opsorops.iter().GROVE_V4only. A pendingDeleteTreewithSubelementsDeletionBehavior::Skipno longer counts as removing its child, which changes the result and the cost of the emptiness check for such batches.GROVE_V1..V3are unchanged.add_delete_operations_for_delete_up_tree_while_emptyleaves the caller'sVecas it was on an error.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
c70dadd/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit