Skip to main content

Module store

Module store 

Source
Expand description

Durable run records for hosts that serve many runs (an HTTP server, a job queue).

A RunStore keeps, per run: a RunRecord (status, outputs, pause reasons…), the run’s events as JSON, and the Snapshot of a paused run, so a run can be resumed by id after the client went away or the host restarted.

Nothing secret is persisted: event values serialize with secrets masked, and snapshots never contain secret plaintext (see crate::snapshot).

§Writes that can be retried

A host that writes through a network (a gateway in front of agents, an object store) must be able to retry any write without corrupting the run:

  • RunStore::append_events takes the index of the first event of the batch. A batch that is already stored (a retry after a lost reply) is accepted without storing it twice; a batch that would leave a gap, or that differs from the events already stored at those indices, is refused.
  • RunStore::put_if replaces a record only while its RunRecord::epoch is still the expected one, so a stale writer (a zombie replica, an execution that was taken over) cannot overwrite a newer one.
  • Every claim (RunStore::claim_resume, RunStore::claim_dispatch) increments the epoch.

Structs§

AppendPlan
How a batch passed to RunStore::append_events lines up with the events a store already holds (shared by implementations).
RunFilter
Query for RunStore::list.
RunPage
One page of RunStore::list, newest first.
RunRecord
Persisted summary of one run.

Enums§

RunStatus
Lifecycle status of a stored run.
StoreError
Store failure.

Constants§

INTERRUPTED_BY_RESTART
Error message stored on runs interrupted by a host restart.

Traits§

RunStore
Durable storage of run records, events and snapshots.

Functions§

append_mismatch
StoreError::Conflict for a retried event that differs from the stored one.
check_epoch
StoreError::Precondition unless record is at expected_epoch.
event_to_json
Serialize an event for storage. Secrets are masked by the value serializer; the snapshot carried by run_paused is dropped (stores keep it separately).
event_to_stored
Serialize an event for storage: the same JSON as event_to_json, written straight to text.
now_ms
Current Unix time in milliseconds (0 where no clock exists).
page_of
Apply filter to records already sorted newest first (shared by implementations).
plan_append
Plan an append of batch_len events at first_index to a run holding event_count events. Fails with StoreError::Conflict on a gap.
sort_newest_first
Sort records newest first (ties broken by id, descending) for page_of.
stored_event_type
The type field of a stored event (e.g. node_started), if it has one.
validate_run_id
Validate a run id used as a storage key: 1–128 chars of [A-Za-z0-9_.-], not starting with ..

Type Aliases§

StoreResult
Result type of RunStore operations.
StoredEvent
An event serialized as one JSON object, the form in which stores keep events.