Repository navigation
fix(delete)!: keep draining pending drops past a record that cannot be resolved - #1045
Conversation
… resolved `GroveDb::flush_pending_prefix_drops` returned the first error its liveness check hit, so one record stopped every record after it from being reclaimed, on that call and on every later one. A record whose parent key came to hold an element that is not a tree made the check fail with `CorruptedPath`. Nothing resolves below such an element, so the record is now reclaimed; the parent's element is read to confirm it is a non-tree. A record whose check fails any other way is left in place, counted in `PendingPrefixDropsReport::unresolved_records` (first error in `first_unresolved_error`) and checked again by the next call, while the records after it are reclaimed. A path that resolves to a live element is still never tombstoned. No root hash or cost changes: the drain only reads, and writes only to storage that no element reaches. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
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. |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit e11b547) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
The PR correctly isolates unresolved liveness checks, preserves those records, and continues reclaiming later records. One in-scope correctness gap remains: the new non-tree handling only checks the immediate parent, so a non-tree higher ancestor can leave safely reclaimable records unresolved indefinitely. No code checks have failed; several CI checks are still queued.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.1-sol(effort low) — This is a contained but behavior-changing storage-reclamation and error-handling fix with substantial tests, and it does not directly alter a critical surface listed for the critical tier. - Phase 1 reviewers: not run (disabled for this repository)
- Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `grovedb/src/operations/delete/flat_drop.rs`:
- [SUGGESTION] grovedb/src/operations/delete/flat_drop.rs:469-490: Walk higher ancestors before treating CorruptedPath as absence
The `CorruptedPath` branch only calls `holds_a_non_tree_element` for the immediate parent path. For a dropped path such as `[a, b, c, dropped]`, if `[a, b]` has been replaced by an item, reading `[a, b, c]` correctly returns `CorruptedPath`, but checking `[a, b, c]` itself requires opening that same invalid descendant path and therefore also fails. The helper returns false, so the record is classified as unresolved even though the live graph proves that no element can exist below the non-tree ancestor `[a, b]`; its storage and pending record are never reclaimed. Walk the path prefixes from the root, or otherwise identify the first successfully readable non-tree ancestor, and return `Ok(false)` only after that proof while retaining unresolved handling for genuine read failures.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Log unresolved pending-drop records in rs-drive-abci — The current
rs-drive-abcifinalization and startup callers only treat reclaimed or live-skipped records as report-worthy. A pass containing onlyunresolved_recordstherefore returns successfully without logging the new diagnostic fields, leavingfirst_unresolved_errorunused in the current integration.- Follow-up: Update rs-drive-abci after the next GroveDB pin to include
unresolved_recordsandfirst_unresolved_errorin pending-drop finalization and startup-flush logging.
- Follow-up: Update rs-drive-abci after the next GroveDB pin to include
| Err(Error::CorruptedPath(_)) | ||
| if self.holds_a_non_tree_element(parent_segments, grove_version) => | ||
| { | ||
| Ok(false) | ||
| } | ||
| Err(e) => Err(e), | ||
| } | ||
| } | ||
|
|
||
| /// Whether the committed state holds, at `path`, an element that is | ||
| /// not a tree. `false` for the root, for an absent element, for any | ||
| /// tree and when the read fails. | ||
| fn holds_a_non_tree_element(&self, path: &[Vec<u8>], grove_version: &GroveVersion) -> bool { | ||
| let Some((key, parent_segments)) = path.split_last() else { | ||
| return false; | ||
| }; | ||
| let parent_path: SubtreePath<Vec<u8>> = parent_segments.into(); | ||
| matches!( | ||
| self.get_raw(parent_path, key, None, grove_version).unwrap(), | ||
| Ok(element) if element.root_key_and_tree_type().is_none() | ||
| ) | ||
| } |
There was a problem hiding this comment.
✅ Resolved at
e11b5473; see the replies below.
🟡 Suggestion: Walk higher ancestors before treating CorruptedPath as absence
The CorruptedPath branch only calls holds_a_non_tree_element for the immediate parent path. For a dropped path such as [a, b, c, dropped], if [a, b] has been replaced by an item, reading [a, b, c] correctly returns CorruptedPath, but checking [a, b, c] itself requires opening that same invalid descendant path and therefore also fails. The helper returns false, so the record is classified as unresolved even though the live graph proves that no element can exist below the non-tree ancestor [a, b]; its storage and pending record are never reclaimed. Walk the path prefixes from the root, or otherwise identify the first successfully readable non-tree ancestor, and return Ok(false) only after that proof while retaining unresolved handling for genuine read failures.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)
There was a problem hiding this comment.
Resolved (re-reviewed at e11b5473): The new path_stops_before_its_end helper walks every ancestor from the root and only treats CorruptedPath as proof of absence after confirming that an ancestor is missing or no longer a tree. This addresses the previous immediate-parent-only check.
|
Bots are done — your move: post |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1045 +/- ##
===========================================
- Coverage 93.32% 93.22% -0.10%
===========================================
Files 366 366
Lines 112843 112274 -569
===========================================
- Hits 105308 104666 -642
- Misses 7535 7608 +73
🚀 New features to boost your workflow:
|
…a tree The drain treated `CorruptedPath` as "not live" only when the dropped path's immediate parent could be read as a non-tree element. When the layer above that parent was no longer a tree either (it was flat-dropped in turn, so its storage still showed the parent as an item), that read failed the same way and the record stayed unresolved on every pass. The path above the dropped key is now read from the root down, each layer inside a tree the step before found. The record is reclaimed when a layer is absent from its parent tree or holds an element that is not a tree. Any other read failure still leaves the record unresolved. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
The stable clippy that CI now installs reports `needless_bool` on the
`if .. { return true; } false` form. Same change as on the sibling pull
requests, so the branches merge without a conflict.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw ✓. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)
The higher-ancestor liveness check now correctly prevents unsafe reclamation, and the prior finding is fixed. One operational integration gap remains: existing rs-drive-abci callers only treat Err as a failed flush, so a pass containing only unresolved records can be silently ignored despite the new report fields. CI build, test, formatting, and lint checks are successful.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.1-sol(effort low) — The change modifies pending-drop storage reclamation and error-handling logic across production code and extensive tests, making it an ordinary but nontrivial correctness-sensitive change without meeting the defined critical-surface criteria. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `grovedb/src/operations/delete/flat_drop.rs`:
- [SUGGESTION] grovedb/src/operations/delete/flat_drop.rs:424-431: Propagate unresolved flush reports to host callers
This change intentionally converts a per-record liveness-check failure into Ok(report) and records it in unresolved_records and first_unresolved_error. The existing rs-drive-abci callers still only handle Err: finalize_block logs a successful report only when reclaimed_records or skipped_live is nonzero, and the startup path warns only on Err. Consequently, a flush containing only unresolved records is silently ignored even though it may indicate persistent storage corruption or a read fault. Update the rs-drive-abci block-finalization and startup callers to emit a warning or metric when unresolved_records > 0 and include first_unresolved_error.
| Err(e) => { | ||
| report.unresolved_records += 1; | ||
| if report.first_unresolved_error.is_none() { | ||
| report.first_unresolved_error = Some(format!( | ||
| "dropped path {:?}: {e}", | ||
| DebugByteVectors(record.path) | ||
| )); | ||
| } |
There was a problem hiding this comment.
⏸️ Needs a tracking issue (not yet deferred) at
e11b5473; see the replies below.
🟡 Suggestion: Propagate unresolved flush reports to host callers
This change intentionally converts a per-record liveness-check failure into Ok(report) and records it in unresolved_records and first_unresolved_error. The existing rs-drive-abci callers still only handle Err: finalize_block logs a successful report only when reclaimed_records or skipped_live is nonzero, and the startup path warns only on Err. Consequently, a flush containing only unresolved records is silently ignored even though it may indicate persistent storage corruption or a read fault. Update the rs-drive-abci block-finalization and startup callers to emit a warning or metric when unresolved_records > 0 and include first_unresolved_error.
source: gpt-6.1-sol (phase2-reviewer: architecture-layering)
There was a problem hiding this comment.
Agreed. Both callers are in Platform, which pins a GroveDB revision without these fields, so the warning goes in with Platform's next GroveDB pin bump.
There was a problem hiding this comment.
That deferral is reasonable because both callers are in Platform and will be updated with its next GroveDB pin. Before I mark this deferred, it needs a tracking issue in dashpay/platform; please link one or say so and I’ll file it.
Not deferred yet: a deferral needs a tracking issue for the follow-up; until then the finding stands.
|
Bots are done — your move: post |
Basic explanation
What this does: A flat drop removes a tree in one step and leaves a small record saying "this tree's storage can be reclaimed".
GroveDb::flush_pending_prefix_dropslater walks those records and reclaims the storage. Before reclaiming, it checks that nothing lives at the dropped path any more. If that check failed for one record, the whole call stopped with the error, and since the record stayed in the queue, every later call stopped at the same place. The records after it were never reclaimed. Now each record is handled on its own: one that cannot be checked is counted and left for the next call, and the rest are reclaimed.Value: One record can no longer hold up reclamation for the whole database. Disk space of unrelated dropped trees is freed as intended, and the caller gets a count (and the first error) of the records that could not be checked, instead of a bare failure.
Risks: Low. The rule that protects live data is unchanged: storage is reclaimed only when the check proves that the dropped path resolves to nothing. No root hash, proof or cost can change (see below). The report struct gains two fields and loses
Copy, which is a source-level break only for code that builds the struct by hand.Issue being fixed or feature implemented
flush_pending_prefix_dropsloops over the pending records in key order. For each it callsget_raw(parent_path, key)to see whether the dropped path is live again. Four errors mean "absent" (PathKeyNotFound,PathNotFound,PathParentLayerNotFound,InvalidParentLayerPath). Any other error didreturn Err(e)in the middle of the loop.One ordinary sequence produces such an error:
[a, parent, nested]inside a caller transaction, so its record waits for a flush.[a, parent]and insert an item at the same key.[a, parent]finds an item where a tree should be and returnsCorruptedPath("cannot open a subtree as parent exists but is not a tree").That record is never removed, so every flush from then on returns the same error at the same record, and the records after it in key order stay in the queue with their storage.
What was done?
In
grovedb/src/operations/delete/flat_drop.rs:dropped_path_is_live, which returnsOk(true)(live),Ok(false)(proved absent) orErr(no answer).CorruptedPathalone is not taken as that proof, because the variant carries free text and is raised in other places of the crate. Whenget_rawreturns it, the path above the dropped key is read again from the root down, each layer inside a tree that the step before found. The record is reclaimed only if that walk finds a layer that is absent from its parent tree or holds an element that is not a tree. Anything else is "no answer". Reading from the root matters when a higher layer was flat-dropped in turn: its storage is still there and can show the parent as an item, while the layer itself can no longer be opened.unresolved_records, the first such error is kept infirst_unresolved_error, and the loop goes on. The next call checks the record again.Err: listing the records, writing a range tombstone (delete_prefix_ranges) or removing a record (remove_pending_prefix_drop_record). These are faults of the storage layer, not of one record's check, and are likely to repeat for every record. Records reclaimed earlier in that call stay reclaimed, as before.Before and after
Four pending records, visited in this order:
[a, parent, nested], then three unrelated trees under[a].[a, parent]was replaced by an item before the flush.Err(CorruptedPath("cannot open a subtree as parent exists but is not a tree")), on every callOk(report)reclaimed_recordsunresolved_recordsThe same four records, but the check of the first one fails with a read error (in the test, the parent Merk's root node does not decode):
Err(..)on every callOk(report)reclaimed_recordsunresolved_recordsfirst_unresolved_error: Some("dropped path [..]: ..")Err(..)Ok, 0 reclaimed, 1 unresolvedOk, 1 reclaimed, 0 unresolvedWhy no root hash or cost can change
The function stays ungated, as its doc says, and this change keeps the reasons true:
get_rawand discards the read costs. It returns noOperationCost, and nothing it does is added to any operation's cost.GROVE_V4, so underGROVE_V1..GROVE_V3there are no records and the function is a no-op, before and after.Public interface changes
grovedb::PendingPrefixDropsReport(also atgrovedb::operations::delete::PendingPrefixDropsReport)unresolved_records: u64: records left in the queue because their liveness check gave no answer. Their storage is untouched.first_unresolved_error: Option<String>: the dropped path and the error text of the first unresolved record of that call, meant for a log line.Nonewhenunresolved_recordsis 0. It is aStringbecausegrovedb::Erroris neitherClonenorPartialEq, and the report keeps both.Copy(it holds aString).Debug,Default,Clone,PartialEqandEqstay..clone(). Reading fields is unaffected.GroveDb::flush_pending_prefix_dropsfn flush_pending_prefix_drops(&self, grove_version: &GroveVersion) -> Result<PendingPrefixDropsReport, Error>.Ok. A caller that treatedErras "some record could not be checked" should look atunresolved_recordsinstead.Errnow means only that the drain itself failed (records could not be listed, or a tombstone or record removal could not be written).reclaimed_records. Before, it made the call fail.What stays the same:
drop_flat_subtree, the batchDropFlatbehaviour, the record format,skipped_liveand the rule behind it (a dropped path that resolves to an element is skipped on every call and never tombstoned), the internal best-effort flush after a drop that owns its transaction, and everyGroveVersiontable.For Dash Platform:
rs-drive-abcicalls the function after finalizing a block and when the platform is opened, and readsreclaimed_recordsandskipped_livefrom the result.rs-drivenames the type in two test helpers. Nothing builds, destructures or copies the report, so the current code compiles unchanged against this. With the next GroveDB pin, the log line after a block can also printunresolved_recordsandfirst_unresolved_error.How Has This Been Tested?
New tests in
grovedb/src/tests/flat_drop_tests.rs:should_reclaim_unrelated_drops_when_an_ancestor_of_a_dropped_path_holds_an_item: the sequence above, with the affected record first in drain order. Fails ondevelopwith theCorruptedPatherror; now all four records are reclaimed, the item is untouched andverify_grovedbis clean.should_reclaim_a_record_when_a_higher_ancestor_of_its_path_holds_an_item: the trees above the dropped one are emptied and removed, and an item takes the key two layers up. The record is reclaimed.should_reclaim_a_record_below_an_item_when_a_dropped_ancestor_holds_an_item_tooandshould_reclaim_a_record_below_an_item_when_a_dropped_ancestor_is_gone: the parent holds an item and the layer above it was flat-dropped as well, then replaced by an item or left absent. With a check of the immediate parent only, the record stayed unresolved on every call; read from the root, it is reclaimed.should_count_a_record_whose_liveness_check_fails_and_keep_draining: the first record's check hits a read error. It is counted as unresolved and keeps its record and storage, the three later records are reclaimed, a second call reports it again, and once the fault is repaired the next call reclaims it.should_skip_a_recreated_path_as_live_while_other_records_drain: a re-created path is skipped as live on every call and its data survives, while a record below an item and an ordinary record are reclaimed in the same call.should_reclaim_an_ordinary_drop_and_report_nothing_unresolved: the plain case, with the full report compared.Run:
cargo test -p grovedb --lib flat_drop(27 tests pass, the 20 existing ones included) andcargo clippy -p grovedb --all-targets(no warnings in the touched files). The full workspace suite was not run locally.Breaking Changes
PendingPrefixDropsReporthas two new public fields and no longer implementsCopy. Code that only reads its fields, which is every known caller, compiles unchanged. No stored data, root hash, proof or cost changes.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
e11b547/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.