Skip to content

fix: Make hard ledger drop fully clean up on S3 + DynamoDB - #1243

Merged
bplatz merged 3 commits into
mainfrom
fix/s3-ledger-drop
May 16, 2026
Merged

bplatz merged 3 commits into
mainfrom
fix/s3-ledger-drop

Conversation

@bplatz

@bplatz bplatz commented May 15, 2026

Copy link
Copy Markdown
Contributor

Hard-dropping a ledger on the AWS stack (S3 storage + DynamoDB nameservice) was silently behaving like a soft drop: the alias remained unreusable in DynamoDB and 0 artifacts were deleted in S3. This PR fixes four cooperating bugs so drop_ledger(.., DropMode::Hard) actually clears the ledger end-to-end.

Bugs fixed

1. DynamoDbNameService::purge was missing — fell back to retract

Publisher::purge has a default impl that delegates to retract(), which only flips meta.retracted = true. DynamoDbNameService never overrode it, so head / index / config / status rows were left behind and publish_ledger_init (which uses attribute_not_exists(pk) per row) couldn't recreate the alias.

Fix: Override purge() to delete every row under pk. Factored a delete_all_rows_for_pk helper that's also reused by drop_branch. The helper always sweeps non-meta rows regardless of the conditional-meta-delete outcome, so a purge that crashed mid-sweep is recovered on the next call.

2. S3Storage::list_prefix* didn't parse fluree addresses

Reads, writes, and deletes route through address_to_key (which strips fluree:s3://). The list APIs didn't, so a caller passing fluree:s3://ledger/main/ ended up querying S3 with fluree-data/fluree:s3://ledger/main/ — a literal substring that never matches real keys. Result: list returned 0 → fast-path drop deleted nothing.

Fix: New build_list_prefix helper that runs the same parse_fluree_address path. Applied to all four list entry points (StorageRead::list_prefix, StorageList::list_prefix, list_prefix_paginated, list_prefix_with_metadata). Six unit tests covering scheme stripping, trailing-slash preservation, empty input, and bucket-prefix trimming.

3. TieredStorage routing missed entire tiers on a ledger-root list

TieredStorage::list_prefix routes by substring: /commit/ or /txn/ → commit tier; everything else → index tier. A ledger-root prefix like fluree:s3://ledger/main/ contains neither, so a single root-level list misses the whole commit bucket in split commit/index deployments. The original drop_artifacts also missed {prefix}/config/ (where ContentKind::LedgerConfig blobs — config + default-context — are written).

Fix: drop_artifacts now enumerates per-subprefix: commit/, txn/, index/, config/, and conditionally {ledger}/@shared/dicts/. Each list call routes to the correct tier.

4. Partial list failures were silently treated as success

The original "if any subprefix listed OK, declare success" branch could purge the nameservice while leaving an entire artifact class behind if one tier returned an error.

Fix: Failures are collected as warnings on the DropReport. When any subprefix errors, a CID-walk cleanup pass runs after the fast path (release is idempotent on already-deleted CIDs). The nameservice is only purged once drop_artifacts has had its best shot.

Branch safety

  • Cross-branch @shared/dicts/ is only wiped when is_last_live_branch returns true (uses NameService::list_branches to confirm no sibling branches remain). Branch-scoped drop_branch / purge_branch always pass false.
  • drop_ledger's doc-comment now calls out that hard-dropping a parent branch while child branches are still alive will delete commit/index artifacts the children may resolve through the branched content store. Drop child branches first.

bplatz added 3 commits May 15, 2026 07:26
DynamoDbNameService now overrides Publisher::purge with a real
delete-all-rows sweep (factored helper shared with drop_branch). The
sweep runs regardless of the conditional meta-delete outcome so a
half-completed purge is recovered on replay.

S3Storage list_prefix variants now parse `fluree:s3://...` through the
same path used by reads/writes/deletes, so callers can pass fluree
addresses and have the configured bucket prefix correctly applied.

drop_artifacts enumerates per-subprefix (commit/, txn/, index/, config/,
and optionally @shared/dicts/) so TieredStorage routes commit/txn lists
to the commit tier and index/config lists to the index tier. Cross-
branch @shared/dicts/ is only wiped when no other non-retracted branches
remain. Partial list failures now surface as warnings and trigger a
CID-walk cleanup pass instead of being silently treated as success.

Adds a LocalStack integration test that writes commits, hard-drops, and
asserts artifacts are gone, the NS record is purged, and the alias can
be re-initialized.
Set a default context so the bucket also has `config/` artifacts before
the drop, and assert their absence afterward. Extend the post-drop
straggler filter to include `config/` and `@shared/dicts/` so the test
fails fast if any enumerated subprefix is missed in the future.

Updated the test header to list the full subprefix set drop_artifacts
enumerates.

@zonotope zonotope left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛅

@bplatz
bplatz merged commit d955274 into main May 16, 2026
14 checks passed
@bplatz
bplatz deleted the fix/s3-ledger-drop branch May 16, 2026 21:51
@bplatz bplatz mentioned this pull request May 21, 2026
@bplatz bplatz added the bug Something isn't working as expected label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants