Skip to content

Add startup state snapshots for fast storage initialization with lazy filesystem backfill#339

Draft
albe with Copilot wants to merge 6 commits into
mainfrom
copilot/implement-persist-and-restore-state
Draft

Add startup state snapshots for fast storage initialization with lazy filesystem backfill#339
albe with Copilot wants to merge 6 commits into
mainfrom
copilot/implement-persist-and-restore-state

Conversation

Copilot AI commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

PR #338 attempted to optimize startup by reusing known partitions/indexes instead of fully rescanning on every open. This change reintroduces that optimization from scratch with a best-effort snapshot model: restore fast when possible, then reconcile lazily with current filesystem state.

  • Startup snapshot model

    • Added persisted startup-state file: .<storage>.startup-state.json in indexDirectory.
    • Snapshot contains known partition file names and secondary index names (versioned payload).
  • Fast restore on open + lazy reconciliation

    • ReadableStorage.open() now attempts snapshot load first.
    • When snapshot is present/valid, storage opens immediately from known state and kicks off scanFiles() in background to discover drift/new files.
    • When snapshot is missing/invalid, startup falls back to full scan behavior.
  • Known-state tracking

    • Added explicit tracking for known secondary indexes (knownIndexes) and unified registration path (registerKnownIndex).
    • Partition/index discovery paths now funnel through known-state update hooks.
  • Writable-only persistence

    • Added onKnownStateChanged() hook; WritableStorage overrides it to debounce snapshot writes.
    • Snapshot persistence is best-effort and runs on state changes and close.
    • ReadOnlyStorage does not persist startup state (read-only remains non-mutating).
  • Race hardening for lazy scans

    • Background scan callbacks guard against close-time races and rename/delete windows while reconciling filesystem state.
const storage = new Storage('storage', { dataDirectory, indexDirectory });

storage.open(); // restores known partitions/indexes from .storage.startup-state.json when available
// Full filesystem reconciliation continues lazily in background.

Comment thread src/Storage/ReadableStorage.js Outdated
Copilot finished work on behalf of albe July 19, 2026 21:06
Copilot AI requested a review from albe July 19, 2026 21:06
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.215% (-0.08%) from 98.299% — copilot/implement-persist-and-restore-state into main

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants