Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

An embedded, persistent knowledge-graph store.

Implementations§

Source§

impl Store

Source

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.

Source

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.

Source

pub fn open_cfg(dir: impl AsRef<Path>, cfg: Config) -> Result<Self>

Open with an explicit configuration.

Source

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.

Source

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.

Source

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.

Source

pub fn is_image(&self) -> bool

True for a store served from memory (Store::open_image).

Source

pub fn len(&self) -> usize

Number of live (non-tombstoned, non-stub) documents in the current snapshot view.

Source

pub fn is_empty(&self) -> bool

True when the store holds no live documents.

Source

pub fn dir(&self) -> &Path

The directory this store lives in.

Source

pub fn generation(&self) -> u64

The generation currently served (advances by one per compaction, or when Store::reload_if_stale installs a newer one).

Source

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.

Source

pub fn compaction_due(&self) -> bool

True when a threshold was reached while inline compaction was off and no compaction has run since.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.