Skip to content

Recover from a missing or corrupt index automatically instead of failing the ledger load #1817

Open

Description

@bplatz

Problem

When a ledger's nameservice record names an index whose root or artifacts are missing or fail their content hash, the ledger cannot be loaded at all. LedgerState::load reads the index root with store.get(index_cid) (fluree-db-ledger/src/lib.rs, "Handle missing index") and returns the error. There is no fallback to an earlier index, no replay from commits, and no automatic reindex. The ledger stays unavailable until an operator resets the index pointer or runs a reindex by hand.

Index artifacts are deliberately written at page-cache durability: they are rebuildable from the commit chain and are written at far higher volume than commits, so flushing them per object would put the cost on the busiest path. The index pointer is a nameservice write and is flushed. That asymmetry is fine as long as the system can recover when the two disagree, and today it cannot.

How the disagreement arises

  • A power loss or kernel panic between an index publication and the OS writing back the artifacts. A pending change flushes artifacts once at the end of each build, before the pointer is published, which closes this window for builds, branch copies and imports.
  • Bit rot, an accidental deletion, an index artifact reclaimed by mistake, or a storage root restored from a copy taken before the index was built. None of these are closed by the flush above.

Content is hash-addressed, so both absence and corruption are detectable at read time. What is missing is what happens next.

Proposed behavior

  1. At load, if the index root or any artifact the load needs is missing or fails its hash: log it at error level with the ledger and the CID, load from commits as if the ledger were unindexed, and schedule a reindex. The ledger stays available at the cost of replaying novelty from genesis until the rebuild lands. For a large ledger that replay is slow, so the log line should say a rebuild is in progress and why.
  2. During a query, a leaf or branch read that misses or fails its hash should mark the index bad and trigger the same rebuild rather than failing every query that touches that leaf.
  3. Observability: a counter or log event for "index rebuilt after detected loss", so operators learn it happened even though nothing failed.
  4. Keep the existing admin reindex as the manual override.

Current workaround

Reset the ledger's index pointer, or run a reindex against the ledger. Both require an operator to notice the load failure first.

Out of scope

Preventing the disagreement in the first place. That is the flush-before-publish change above, which is separate.

Activity

  1. added
    enhancement
    P2
    area:storage
    on Sep 9, 2026
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

    P2area:storageenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions