Skip to content

Prefix-scoped record enumeration in NameService for ledger-name lookups #1248

Closed

Description

@bplatz

Context

drop_ledger (and other call sites that need every branch of a single ledger) currently does:

let all = self.nameservice().all_records().await?;
let branches: Vec<NsRecord> = all.into_iter().filter(|r| r.name == ledger_name).collect();

That's a full nameservice scan followed by an in-memory filter. It's correct, but it grows with the total NS size rather than with the number of branches under the target ledger. On large deployments — DynamoDB nameservice in particular — this is wasteful, and the cost is paid per drop.

Surfaced in #1244 (comment).

Ask

Extend the NameService trait with a prefix-scoped variant — something like:

async fn list_records_for_ledger(&self, ledger_name: &str) -> Result<Vec<NsRecord>>;

…where backends that support a server-side filter implement it efficiently (DynamoDB Query on the partition key, storage_ns prefix scan, etc.) and others can fall back to the existing all_records().filter(...) path. Then swap the call site in drop_ledger (fluree-db-api/src/admin.rs:~392) to use it.

Scope notes

  • Trait change + impls across memory.rs, file.rs, storage_ns.rs, and the DynamoDB nameservice.
  • NotifyingNameService passthrough.
  • Audit other all_records() callers — any that filter by name should switch over too.
  • Not behavior-changing; just shifts the filter to the most efficient layer the backend supports.

Activity

  1. added
    P3
    area:storage
    on Aug 25, 2026
  2. bplatz commented on Nov 14, 2026

    @bplatz
    ContributorAuthor

    Closing as fixed by #2168. It added NameServiceLookup::branch_records, a per-ledger listing that each backend serves natively: a GSI1 prefix query on DynamoDB, a prefix LIST on storage-backed nameservices, and its own versions in the file and memory backends. GC, materialize, list_branches and the storage proxy now use it.

    Three admin paths still call all_records() on purpose: drop_ledger, purge_branch and hold_ledger_for_maintenance (fluree-db-api/src/admin.rs). They also have to find nested ledgers under the name/ prefix (nested_ledgers in gc/sweep.rs), which a per-ledger listing doesn't return. They are rare admin operations, so the full listing stays.

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

    P3area:storage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions