Skip to main content

Module state

Module state 

Source
Expand description

Persistence for watch resume state.

StateStore is an async trait for persisting and retrieving Checkpoints keyed by ResumeKey, consumed by the aviso watch supervisor for at-least-once delivery across reconnects and process restarts. Implementations are Send + Sync and serialise concurrent writes internally so the in-memory and (where applicable) on-disk states stay consistent.

A successful StateStore::put is committed-before-visible: a subsequent StateStore::get returns the resolved value. For durable implementations (such as JsonFileStore) the same guarantee is durable-before-visible: the disk write returns success before the new value becomes visible to readers. A failed put leaves all state unchanged.

put is strictly monotonic in last_committed_sequence: a put with a sequence less than or equal to the existing value is a silent no-op. Both implementations enforce this so consumers see identical behaviour regardless of the backing store. Callers needing to reset a checkpoint to a lower sequence must delete first, then put.

Two implementations are provided:

  • MemoryStore: in-process. State dies with the program. Good for tests and short-lived consumers.
  • JsonFileStore: backed by a JSON file with crash-safe atomic writes via the atomicwrites crate plus a cross-process advisory lock on a sidecar lockfile. Safe for cooperating processes on local filesystems; see the type docs for the precondition list (no NFS/CIFS, no external deletion of the lockfile).

Resume keys are derived from a base URL, an event type, the watch filter body, and an optional schema fingerprint. The hash deliberately excludes any server-side resume position; the same logical subscription always computes the same key.

Structs§

Checkpoint
A committed position in a watch stream, keyed by ResumeKey.
JsonFileStore
File-backed state store, multi-process safe for cooperating processes on local filesystems.
MemoryStore
In-process StateStore backed by a HashMap behind a tokio RwLock.
ResumeKey
A logical identifier for a watch subscription.

Enums§

ResumeKeyError
Errors specific to resume-key construction.
StoreError
Errors a StateStore implementation can return.

Traits§

StateStore
Persistent storage for Checkpoint keyed by ResumeKey.