Skip to content

Delete semantics: soft drop reserves the alias forever and cannot be undone #1670

Closed

Description

@bplatz

Summary

A soft drop — the default for DELETE /ledger — permanently reserves the ledger alias, and there is no supported way to reclaim it or to recover the ledger. The only escape is a hard drop, which destroys the data the soft drop existed to preserve.

This surfaced as a report from an application on the DynamoDB nameservice that deletes ledgers and then recreates them under the same name, and gets Ledger already exists on every recreate.

Reproduction

Verified on both the file backend and real DynamoDB (LocalStack):

[dynamo soft] init → retract → init  →  Err(LedgerAlreadyExists("soft/db:main"))
[dynamo hard] init → purge   → init  →  Ok(())
[file soft] drop -> Ok((Dropped, 0 artifacts))
[file soft] RECREATE FAILED: Ledger already exists: app/db:main
[file hard] RECREATE OK

Mechanism

  1. DELETE /ledger without "hard": true maps to DropMode::Soft (fluree-db-server/src/routes/ledger.rs:298) — the default.
  2. Soft mode calls LedgerLifecycle::retract, not drop_branch (fluree-db-api/src/admin.rs:657).
  3. retract marks the meta row retracted = true and leaves every row in place (e.g. fluree-db-storage-aws/src/dynamodb/mod.rs:1235).
  4. Recreating calls init, whose DynamoDB TransactWriteItems are conditioned on attribute_not_exists(pk) — the surviving rows cancel the transaction, which maps to LedgerAlreadyExists (dynamodb/mod.rs:1225).

Not backend-specific: the trait contract states it directly — "Returns an error if a record already exists (including retracted records)" (fluree-db-nameservice/src/lib.rs).

The actual defect

Soft drop is a one-way door. Nothing in the codebase sets retracted back to false — there is no un-retract, undrop, or reinstate path anywhere (restore_ledger in commit_transfer.rs is the unrelated .flpack restore). So the mode documented as "the default and safest option… all data files remain on disk for potential recovery":

  • permanently burns the alias, and
  • provides no recovery mechanism that would justify having reserved it.

docs/api/endpoints.md:1750 states the reservation but not that it is irreversible.

Either half would be defensible alone. Together they are a trap: the safe-sounding default is the one with no way back, and callers reach it by simply not passing a flag.

Ruled out

Leftover storage artifacts are not the cause, which was the first hypothesis. Removing only the nameservice records while deliberately leaving 23 artifact files (commits, index, dicts) on disk:

[orphan] RECREATE OK
[orphan] query after recreate -> []

The recreated ledger is clean and empty — the ns record is the authority for a ledger's contents, so orphaned artifacts waste space but cannot corrupt a recreate. Worth knowing on its own.

What to decide

  1. Should init reclaim a retracted record? (purge-then-init when retracted == true.) Makes delete-then-recreate work as callers expect. Cost: gives up alias reservation, which nothing currently redeems.
  2. Or should soft drop become genuinely recoverable? — add an un-retract / undrop path, and keep init strict so reservation means something.
  3. Either way, the error should name the situation and the exits. Ledger already exists on an alias the caller just deleted is actively misleading.

Doing neither (1) nor (2) leaves the default mode of a destructive operation with no route back.

Related but distinct

#1668's review raised retraction semantics on the read side: proxy get_ref/heads resolve head refs for branches a raft-backed remote would tombstone, and raft is the only backend that tombstones at all — file, DynamoDB and memory all resolve them. That is a separate failure (a read returning data it shouldn't) from this one (a write refused by a tombstone); fixing either leaves the other. The common theme — retraction is not applied consistently across backends or across the read/write surfaces — is what ties them together and probably wants settling once, deliberately.

Activity

  1. aaj3f commented on Aug 25, 2026

    @aaj3f
    Contributor

    Folding #1464 into this issue (closing it as the duplicate — same core defect, and this issue has the fresher repros and the decision framing). Five items from #1464 that belong in the record here so they don't get lost:

    1. The nameservice implementations genuinely diverge on reclaim: storage_ns re-init reclaims a retracted alias (storage_ns.rs:805-827) while file/memory/dynamo reject it (file.rs:833-836, memory.rs:231-235). Whatever semantics we decide, that divergence is the first thing to collapse.
    2. The default purge path falls back to retract (lib.rs:633-634), so "hard" intent degrades to exactly the reservation trap this issue describes.
    3. restore_ledger rolls back via a Soft drop (commit_transfer.rs:1654) — a failed restore can strand the alias the same way.
    4. import.rs:3590 currently relies on re-init reclaim working, so a reject-semantics decision needs that call-site accounted for.
    5. A sweep cross-check worth noting: Dropping a vector graph source never reclaims its index blobs, and DropMode::Hard silently degrades to Soft #1596's Hard→Soft silent degrade (drop_branch retracts instead of purging when record.branches > 0, admin.rs:767-770) produces exactly the retracted record that triggers this trap — and the CLI always sends hard:true (drop.rs:50). And materialize gate-fail drop is name-scoped (DropMode::Hard hits every branch); no branch-scoped hard purge #1592's missing branch-scoped hard purge is the shared primitive underneath both. I think one short design note on delete semantics (init-reclaims vs reject, un-retract path or not, branch-scoped purge) settles this issue, Dropping a vector graph source never reclaims its index blobs, and DropMode::Hard silently degrades to Soft #1596, and materialize gate-fail drop is name-scoped (DropMode::Hard hits every branch); no branch-scoped hard purge #1592 together — they shouldn't be fixed piecemeal.
  2. added
    triage:needs-decision
    P1
    bug
    area:storage
    on Aug 25, 2026
  3. aaj3f commented on Aug 28, 2026

    @aaj3f
    Contributor

    A concrete symptom for this issue's ledger, now live on main after #1716/#1739 settled the exists half: exists and create contradict each other after a soft drop, on both backends.

    call answer
    ledger_exists("x:main") false
    create_ledger("x:main") LedgerAlreadyExists
    • raft: retract_ledger inserts into state.retracted but doesn't remove the branch from ledger.branches, and create_ledger rejects on branches.contains(&branch).
    • file: init uses storage.insert (create-if-absent) and the retracted file is still there.

    So a user is told the ledger doesn't exist and simultaneously can't create it — reachable from the CLI, not only raft. That's the sharpest version of the reservation trap this issue describes, and it's the shape a design note has to resolve: either re-init reclaims (the create side moves to match exists), or the record is genuinely reserved (and exists's new answer needs a companion story for "why can't I create it, then").

    Worth recording alongside: the exists sub-question is now decided — #1716 made a retracted ledger read as not-found on the query path (43d758610), and #1739 pinned it. The remaining open decisions here are init-reclaims vs reject, whether an un-retract path exists, and branch-scoped hard purge.

    Credit to @bplatz for the contradiction table and both mechanism traces, from the #1739 review.

  4. added this to the 5.0.0 milestone on Nov 14, 2026
  5. bplatz commented on Nov 14, 2026

    @bplatz
    ContributorAuthor

    Fixed on next by #1980 (merged 2026-10-13): name bindings, restorable drops and fenced writers. A drop no longer reserves the alias forever, and it can be undone. It ships in 5.0.0. Its closing reference didn't fire because the PR targeted next. The remaining edges are tracked in #2104, #2105 and #2106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1area:storagebugtriage:needs-decision

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions