Skip to main content

SnapshotStore

Trait SnapshotStore 

Source
pub trait SnapshotStore: Send + Sync {
    // Required methods
    async fn save(&self, snapshot: &Snapshot) -> Result<(), EngineError>;
    async fn load(
        &self,
        stream_id: &StreamId,
    ) -> Result<Option<Snapshot>, EngineError>;
}
Expand description

Storage contract for aggregate snapshots.

Implementations live in separate backend crates (mako-event-store-slatedb, mako-event-store-redb, etc.). NoopSnapshotStore is provided here for tests and deployments that do not need snapshotting.

§Contract

  • save must persist the snapshot durably before returning Ok.
  • load must return the most recent snapshot for stream_id, or None if no snapshot exists.
  • A snapshot must never be returned for a stream_id if its state_schema_version is not recognised by the caller — implementations are encouraged to store schema version in a queryable column/key so callers can filter by it.

§Blanket Arc implementation

Arc<S> implements SnapshotStore whenever S: SnapshotStore, so Process<W, Arc<MyEventStore>> can accept Arc<MySnapshotStore> without any extra wrapper.

Required Methods§

Source

async fn save(&self, snapshot: &Snapshot) -> Result<(), EngineError>

Persist snapshot, replacing any previous snapshot for the same stream.

§Errors

Returns EngineError::Snapshot on storage failure.

Source

async fn load( &self, stream_id: &StreamId, ) -> Result<Option<Snapshot>, EngineError>

Load the most recent snapshot for stream_id.

Returns None when no snapshot exists (full replay required).

§Errors

Returns EngineError::Snapshot on storage failure.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S: SnapshotStore> SnapshotStore for Arc<S>

Source§

async fn save(&self, snapshot: &Snapshot) -> Result<(), EngineError>

Source§

async fn load( &self, stream_id: &StreamId, ) -> Result<Option<Snapshot>, EngineError>

Implementors§