Skip to main content

RunStore

Trait RunStore 

Source
pub trait RunStore:
    Send
    + Sync
    + Debug {
Show 14 methods // Required methods fn create(&self, record: RunRecord) -> BoxFuture<'_, StoreResult<()>>; fn put(&self, record: RunRecord) -> BoxFuture<'_, StoreResult<()>>; fn put_if( &self, record: RunRecord, expected_epoch: u64, ) -> BoxFuture<'_, StoreResult<()>>; fn get<'a>( &'a self, run_id: &'a str, ) -> BoxFuture<'a, StoreResult<Option<RunRecord>>>; fn list(&self, filter: RunFilter) -> BoxFuture<'_, StoreResult<RunPage>>; fn delete<'a>(&'a self, run_id: &'a str) -> BoxFuture<'a, StoreResult<bool>>; fn append_events<'a>( &'a self, run_id: &'a str, first_index: u64, events: &'a [StoredEvent], ) -> BoxFuture<'a, StoreResult<u64>>; fn events<'a>( &'a self, run_id: &'a str, from: u64, ) -> BoxFuture<'a, StoreResult<Vec<StoredEvent>>>; fn save_snapshot<'a>( &'a self, run_id: &'a str, snapshot: &'a Snapshot, ) -> BoxFuture<'a, StoreResult<()>>; fn load_snapshot<'a>( &'a self, run_id: &'a str, ) -> BoxFuture<'a, StoreResult<Option<Snapshot>>>; fn claim_resume<'a>( &'a self, run_id: &'a str, now_ms: u64, ) -> BoxFuture<'a, StoreResult<RunRecord>>; fn recover_interrupted( &self, now_ms: u64, ) -> BoxFuture<'_, StoreResult<usize>>; fn purge_before(&self, cutoff_ms: u64) -> BoxFuture<'_, StoreResult<usize>>; // Provided method fn claim_dispatch<'a>( &'a self, run_id: &'a str, expected_epoch: u64, owner: Option<String>, now_ms: u64, ) -> BoxFuture<'a, StoreResult<RunRecord>> { ... }
}
Expand description

Durable storage of run records, events and snapshots.

Implementations must make RunStore::claim_resume and RunStore::put_if atomic: of two concurrent claims (or conditional writes) on the same run, exactly one succeeds. RunStore::append_events must be idempotent per index range (see the module docs). The store-conformance feature of this crate ships an abstract test suite every implementation should pass.

Required Methods§

Source

fn create(&self, record: RunRecord) -> BoxFuture<'_, StoreResult<()>>

Insert a new record. Fails with StoreError::Conflict if the id exists.

Source

fn put(&self, record: RunRecord) -> BoxFuture<'_, StoreResult<()>>

Insert or replace a record, unconditionally. Hosts with more than one writer use RunStore::put_if instead.

Source

fn put_if( &self, record: RunRecord, expected_epoch: u64, ) -> BoxFuture<'_, StoreResult<()>>

Replace the record of an existing run only while its stored epoch is expected_epoch. Fails with StoreError::Precondition otherwise, and with StoreError::NotFound when the run does not exist. The store keeps its own event counters, as with put.

Source

fn get<'a>( &'a self, run_id: &'a str, ) -> BoxFuture<'a, StoreResult<Option<RunRecord>>>

Source

fn list(&self, filter: RunFilter) -> BoxFuture<'_, StoreResult<RunPage>>

Source

fn delete<'a>(&'a self, run_id: &'a str) -> BoxFuture<'a, StoreResult<bool>>

Remove a run and everything stored for it. Returns whether it existed.

Source

fn append_events<'a>( &'a self, run_id: &'a str, first_index: u64, events: &'a [StoredEvent], ) -> BoxFuture<'a, StoreResult<u64>>

Append events (already serialized by event_to_stored, secrets masked) whose first one has index first_index, and return the run’s new RunRecord::event_count.

Idempotent: events at indices already stored must equal the stored ones and are skipped (a retried batch is not stored twice). Fails with StoreError::Conflict when first_index is past the run’s event count (a gap) or an overlapping event differs. Stores may cap the number of events kept per run; they then set events_truncated and keep counting.

Source

fn events<'a>( &'a self, run_id: &'a str, from: u64, ) -> BoxFuture<'a, StoreResult<Vec<StoredEvent>>>

Stored events, starting at index from.

Source

fn save_snapshot<'a>( &'a self, run_id: &'a str, snapshot: &'a Snapshot, ) -> BoxFuture<'a, StoreResult<()>>

Source

fn load_snapshot<'a>( &'a self, run_id: &'a str, ) -> BoxFuture<'a, StoreResult<Option<Snapshot>>>

Source

fn claim_resume<'a>( &'a self, run_id: &'a str, now_ms: u64, ) -> BoxFuture<'a, StoreResult<RunRecord>>

Atomically move a paused run to running, increment its epoch and return the updated record. Fails with StoreError::Conflict when the run is not paused (including when another request claimed it first).

Source

fn recover_interrupted(&self, now_ms: u64) -> BoxFuture<'_, StoreResult<usize>>

After a host restart: mark every running run as failed (“interrupted by restart”). Paused and queued runs are kept. Returns how many runs were marked.

Source

fn purge_before(&self, cutoff_ms: u64) -> BoxFuture<'_, StoreResult<usize>>

Delete runs (any status except running and queued) last updated before cutoff_ms.

Provided Methods§

Source

fn claim_dispatch<'a>( &'a self, run_id: &'a str, expected_epoch: u64, owner: Option<String>, now_ms: u64, ) -> BoxFuture<'a, StoreResult<RunRecord>>

Compare-and-set a queued or paused run at expected_epoch to running at expected_epoch + 1, executed by owner, before the run is handed to that executor. Fails with StoreError::Precondition when the epoch moved, StoreError::Conflict when the run is in another status.

The default implementation is get + RunStore::put_if, which is atomic as long as put_if is.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§