Skip to main content

Module recall_ctx

Module recall_ctx 

Source
Expand description

Persistent recall context: the reader plus every mutable layer state.

A single recall() used to open_reader plus load_or_init about twenty state objects on every call (~1.3 ms of file I/O inside a ~2.2 ms call). This module holds them once and reuses them across calls.

§Safety contract

The context is behaviour-preserving for a single-writer process: every call saves its mutations back (same durability as before), so each call starts from the previously saved state — exactly as if it had re-read it.

Two staleness guards make long-lived use safe:

  1. Generation check. SharedContext fingerprints meta.bin (byte length + mtime) plus the block count at open. Every access re-stats the file (~1 us); on mismatch the whole context is dropped and reopened. This catches rebuilds, which reassign block ids and would otherwise leave the mmap pointing at a replaced file.
  2. Layer guards. The text index validates block_count() on every use (full-scan fallback when stale); the append log validates its own (len, mtime) stamp per query. See reader.rs.

If another process rewrites the state files without changing meta.bin (in-place edits, which the build never does — it renames), the context keeps serving in-memory copies. The CLI opens a fresh context per invocation and is unaffected.

Structs§

RecallContext
All state one recall() call needs, loaded once.
SharedContext
A RecallContext plus its layout fingerprint, with reopen-on-stale.

Functions§

with_shared
Run f with the process-global shared recall context for config.