Repository navigation
fix(api): a ledger drop takes a legacy branch with it, and a sweep keeps a nested ledger's - #2157
Conversation
A branch an earlier release let take a name the ledger-id grammar now refuses, such as one beginning with `/`, is still listed under that id. The nameservice addresses no such id: it refuses publishing, looking up and dropping it, and keeps the older record where it is. `drop_ledger` walked the listed branches and, for each, deleted its files and then dropped its record. For such a branch the files went first, the record drop was refused, and the drop failed with the record pointing at files that no longer existed. The error said a retry was safe, and a retry failed the same way. Soft mode stopped the same way, partway through the branches. The drop now checks every listed branch's id before it touches anything, and refuses the drop when one doesn't parse, naming the branch. The branch's record and files, and the rest of the ledger, stay as they were.
nbtribe
left a comment
There was a problem hiding this comment.
Approving — the premise is right and the fix does what the title says. I checked it by reverting the guard and re-running your test: without it, drop_ledger("slashed", Hard) deletes the legacy branch's commit file and then fails on the nameservice, leaving exactly the orphan record you're describing. With it, nothing gets touched.
The ordering claim holds too. The check sits after all_records() and nested_ledgers() — both read-only — and before sort_leaf_first, indexing cancellation, drop_artifacts, drop_branch/retract, cache disconnect and drop_shared_artifacts. No partial-delete window on that path.
I also went looking for false positives and couldn't find one: LedgerId::parse and LedgerId::from_persisted_parts only diverge on @/# and a leading-/ branch, and validate_branch_name already rejects /, @ and # outright, so no branch anyone can create today can trip this.
Four things to fix. Please don't merge on this approval until the first one is sorted — it's a data-loss path, and this PR is otherwise green and mergeable.
1. Nested ledgers still get wiped — fluree-db-api/src/admin.rs:658
The guard only covers branches whose name equals the ledger. A legacy branch on a nested ledger isn't caught, so a parent drop still hard-deletes it and returns Ok.
Repro: with nested a/main/index/child:/old, drop_ledger("a", Hard) returns Ok(24) and wipes the child's files while its nameservice record survives — the exact orphan state this PR exists to prevent.
Root cause is a double-slash mismatch between nested_prefixes/path_prefix() and the storage-normalized list_prefix output. sweep_index_storage shares the same bug.
As it stands the PR closes the hole at the top level and leaves it open one level down.
2. Wrong status code — admin.rs:662
ApiError::Drop maps to HTTP 500 / INTERNAL, which makes this permanent precondition failure look identical to the retryable mid-drop abort that uses the same variant. A caller can't tell "this will never work" from "try again". The file already uses ApiError::Http { status: 400 } for drop refusals elsewhere.
3. No way to clean up a refused ledger — admin.rs:653
Once the guard refuses there's no remediation path. drop_branch("slashed", "/old") also fails (lookup → split_ledger_id → parse), and the @/# forms fail earlier still. Soft mode is blocked too, even though it deletes nothing. The message doesn't offer a next step, so whoever hits this is stuck with a ledger they can't drop and can't repair.
4. The test passes for the wrong reason — fluree-db-api/tests/it_drop_ledger.rs:966
The [Soft, Hard] loop asserts the error string before it checks file state. Pre-fix it panics at line 972 on the Soft message and never reaches the Hard path's "files stay" assertions — so the part that actually proves no data was deleted isn't being exercised. Swapping the order fixes it.
It also only covers the leading-/ form, and asserts nothing about @shared/dicts/.
…outer ledger
A branch an earlier release let begin with `/` has the path prefix
`{name}//{branch}`, which file storage lists as `{name}/{branch}`. The
nested-ledger exclusion compared against the first spelling only, so a
sweep or a hard drop of the outer ledger took the branch's commits and
index for its own. Both spellings are now excluded.
The drop refusal for a ledger holding such a branch answers 409 rather
than 500, and its test checks the files and records before the message,
hard drop first, across the `/`, `@` and `#` forms.
A branch an earlier release let begin with `/`, or hold `@` or `#`, is listed but no request can name it, and the drop refused a ledger that held one. A whole-ledger drop reads its branches from the listing, so retract and drop_branch now read the id under the stored-record grammar and remove that record like any other. Publish and lookup still refuse the name.
Brings in #2157, #2226, #2297, #2314 and #2331. Conflicts: - eval/helpers.rs (#2226): the filter verdict cache key takes main's store instance id and next's u32 graph id, and main's test builds its stores with next's `BinaryIndexStore::empty()`. - grp_transact.rs lists both sides' test modules. - #2157 changed `retract` and `drop_branch` on every nameservice backend, and the nested-ledger prefixes a sweep excludes. next replaced those operations with the fenced record store, so the nameservice, sweep and drop-test hunks take next's side here. The next commit carries the fix to next's operations.
…rop takes the branch with it #2157 for next's nameservice. A branch an earlier release let begin with `/` is no ledger address, so no request can name it, but it is a branch of its ledger: the migration binds it and the binding lists it. The record store's operations (`raw_record`, `insert_record`, `adopt_record`, `freeze_record`, `delete_record`) parsed its id as a request's and refused it. So `migrate_legacy` returned `InvalidId` for a store holding such a branch, a drop of its ledger failed at the freeze, and a restore at the insert. Those operations now read the id under the stored-record grammar (`LedgerId::parse_persisted`) on every backend: memory, file, object storage, DynamoDB and Raft, and in the notifying wrapper. They take ids from a binding or a listing, never from a request. Lookup and publish still refuse the name, and `create_branch` still validates a new one. `nested_prefixes` owns both spellings of such a branch's prefix, `{root}//{branch}` as a verbatim backend lists it and `{root}/{branch}` as a filesystem does, so a sweep or a hard drop of the ledger a nested ledger sits under leaves that branch's files alone. A branch holding `@` or `#` needs nothing here: the upgrade refuses or quarantines it, and it is never bound. Tests, each failing without its part of the change: - conformance `a_ledger_drop_takes_a_legacy_branch_with_it`, on every backend: migrate, soft drop, restore, hard drop. - `it_drop_ledger`: `a_ledger_drop_takes_a_legacy_branch_with_it` and `a_nested_ledgers_legacy_branch_survives_a_sweep_and_a_drop_of_the_outer_ledger`, main's tests on a ledger from before name bindings. - file nameservice: `a_branch_beginning_with_a_slash_is_refused_but_its_record_can_be_dropped`.
Follow-up to #2007, which made a branch beginning with
/no ledger address. A branch an earlier release left under such a name (one beginning with/, or holding@or#) stays listed, but no request can name it.Dropping a ledger that holds one.
drop_ledgerlists the ledger's branches and, for each, deletes its files and then drops its record. For a legacy branch the files went first and the record drop was refused, so the drop failed with the record still listed and pointing at files that were gone; a retry failed the same way.A ledger drop now takes the branch with the rest.
retractanddrop_branchon every nameservice backend read the id under the stored-record grammar (LedgerId::parse_persisted), so a record the listing returns can be removed. Publish and lookup still refuse the name, and requests are still parsed strictly at the edge, so nothing new can address such a branch.(This PR first refused the drop before touching anything. Review pointed out that left the ledger with no way to be dropped at all.)
A nested ledger's legacy branch. A branch
/oldhas the storage prefix{name}//old, which file storage lists as{name}/old. The nested-ledger exclusion compared against the first spelling only, so a sweep or a hard drop of the outer ledger (a, for a ledger nameda/main/index/child) deleted that branch's commits and index.nested_prefixesnow excludes both spellings.Tests
a_ledger_drop_takes_a_legacy_branch_with_it(it_drop_ledger): for/old,v@1andv#1, a soft drop retracts every record and keeps every file; a hard drop leaves no record and no file, shared dictionaries included.a_nested_ledgers_legacy_branch_survives_a_sweep_and_a_drop_of_the_outer_ledger: fails without thenested_prefixeschange, at the sweep.a_branch_beginning_with_a_slash_is_refused_but_its_record_can_be_dropped(file nameservice): publish and lookup refused, retract and drop succeed.