Skip to main content

Module ledger_integrity

Module ledger_integrity 

Source
Expand description

Ledger integrity across the three places an entry lives.

  • cache — asd_ledger_cache in SQLite. Written by every append_entry and never deleted from, so it holds every entry ever acknowledged. Readers serve from it first.
  • ASG — /asd/v1/ledger/<symbol>/<entry>, the authoritative store and the only thing asd sync exports.
  • sidecar — .asd/v1/ledger/<symbol>/<entry>.json, what asd sync wrote and what asd hydrate restores from.

Before ASG compare-and-swapped its refs, concurrent writers and asd index speculation commits discarded ledger commits from ASG after the cache had recorded them (1,684 of 12,085 on one store). Every surface kept working because reads come from the cache, so the loss was invisible until a hydrate came back short. This module makes the three counts visible and restores cache-only entries into ASG.

Structs§

LedgerCounts
Ledger entry counts in each store, plus the gaps between them.
LedgerRestoreReport
Outcome of restore_missing_ledger_entries.

Functions§

asg_ledger_entry_ids
Every entry id in the ASG ledger tree, across all symbols.
ledger_counts
Count ledger entries in the cache, ASG and (when sidecar_root is given and has one) the sidecar, and the gaps between them.
missing_ledger_entries
Cached ledger entries whose entry_id appears nowhere in the ASG ledger tree. Matching by id rather than path means an entry moved by ledger rebind (whose cache row follows it to the new symbol) is never mistaken for a lost one.
restore_missing_ledger_entries
Write every cache-only ledger entry back into ASG, with its reverse-index record, exactly as the cache holds it. Each restore is its own commit so the audit trail says what was recovered and from where.
sidecar_ledger_entry_ids
Every entry id under <root>/.asd/v1/ledger/, or None when the sidecar has no ledger directory.