pub struct Store { /* private fields */ }Expand description
An embedded, persistent knowledge-graph store.
Implementations§
Source§impl Store
impl Store
Sourcepub fn create(dir: impl AsRef<Path>, cfg: Config) -> Result<Self>
pub fn create(dir: impl AsRef<Path>, cfg: Config) -> Result<Self>
Create a fresh store in dir (created if absent; must not already
contain a store) and open it read-write.
Sourcepub fn open(dir: impl AsRef<Path>) -> Result<Self>
pub fn open(dir: impl AsRef<Path>) -> Result<Self>
Open an existing store read-write. Takes the exclusive writer lock
(Error::Locked if another process holds it) and repairs a torn WAL
tail by truncating to the last intact frame.
Sourcepub fn open_cfg(dir: impl AsRef<Path>, cfg: Config) -> Result<Self>
pub fn open_cfg(dir: impl AsRef<Path>, cfg: Config) -> Result<Self>
Open with an explicit configuration.
Sourcepub fn open_read_only(dir: impl AsRef<Path>) -> Result<Self>
pub fn open_read_only(dir: impl AsRef<Path>) -> Result<Self>
Open read-only: no lock taken, no repair performed; replay simply
stops at a torn tail. Use Store::reload_if_stale to observe
another process’s commits and compactions.
Sourcepub fn open_image(base: Bytes, wal: &[u8]) -> Result<Self>
pub fn open_image(base: Bytes, wal: &[u8]) -> Result<Self>
Serve a store straight from memory: base is a graph.base image and
wal a graph.wal image (possibly empty), e.g. objects fetched from a
bucket. The base is read in place — no copy, no file, no mapping — and
fully validated exactly like Store::open. The store is read-only
and has no directory (Store::dir is empty); keep it current with
Store::reload_image.
Sourcepub fn reload_image(&self, base: Option<Bytes>, wal: &[u8]) -> Result<bool>
pub fn reload_image(&self, base: Option<Bytes>, wal: &[u8]) -> Result<bool>
Keep an image store current. Pass the new base when the generation
changed (a compaction), else None and the current log image: frames
not yet visible are published. Returns true when anything new
became visible. Works on file-backed read-only stores too.
Sourcepub fn is_image(&self) -> bool
pub fn is_image(&self) -> bool
True for a store served from memory (Store::open_image).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of live (non-tombstoned, non-stub) documents in the current snapshot view.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
The generation currently served (advances by one per compaction, or
when Store::reload_if_stale installs a newer one).
Sourcepub fn set_compact_inline(&self, inline: bool)
pub fn set_compact_inline(&self, inline: bool)
Whether Writer::commit compacts inline once the configured
thresholds are reached (the default, and the 0.2 behaviour). Services
that must keep commit latency flat turn it off and call
Store::compact off the hot path whenever Store::compaction_due
says so.
Sourcepub fn compaction_due(&self) -> bool
pub fn compaction_due(&self) -> bool
True when a threshold was reached while inline compaction was off and no compaction has run since.
Sourcepub fn snapshot(&self) -> Snapshot<'_>
pub fn snapshot(&self) -> Snapshot<'_>
Pin the current generation and return a read view. Never blocks in steady state; spins only across a writer’s slot-install window.
Sourcepub fn writer(&self) -> Result<Writer<'_>>
pub fn writer(&self) -> Result<Writer<'_>>
Acquire the single writer. Error::ReadOnly on read-only stores.
Blocks while another thread holds a Writer on this handle. A second
handle on the same directory cannot exist at all — Store::open would
have been refused with Error::Locked — so this mutex is the only
contention a caller can encounter.
Sourcepub fn compact(&self) -> Result<CompactStats>
pub fn compact(&self) -> Result<CompactStats>
Fold the WAL into a new base generation now. Also triggered
automatically by Writer::commit past the configured thresholds.
Sourcepub fn reload_if_stale(&self) -> Result<bool>
pub fn reload_if_stale(&self) -> Result<bool>
For read-only stores: pick up commits/compactions made by the writing
process. Returns true when anything new became visible.
Cheap when nothing changed: two stat calls, no mapping, no reads.
When only the log grew, only the appended bytes are read. Reloads on
one handle run one at a time; snapshots are never blocked. On a
writable handle this is a no-op (Ok(false)): its own view is always
current.