Skip to main content

StateMachine

Struct StateMachine 

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

State machine for Statehouse Single-writer design: all mutations go through one logical thread

Implementations§

Source§

impl StateMachine

Source

pub fn new(storage: Arc<dyn Storage>) -> Self

Source

pub fn begin_transaction(&self, timeout_ms: Option<u64>) -> Result<TxnId>

Begin a new transaction

Source

pub fn write( &self, txn_id: &str, namespace: String, agent_id: String, key: String, value: Value, ) -> Result<()>

Stage a write operation

Source

pub fn delete( &self, txn_id: &str, namespace: String, agent_id: String, key: String, ) -> Result<()>

Stage a delete operation

Source

pub fn commit(&self, txn_id: &str) -> Result<CommitTs>

Commit a transaction atomically

Source

pub fn abort(&self, txn_id: &str) -> Result<()>

Abort a transaction

Source

pub fn get_state( &self, namespace: &str, agent_id: &str, key: &str, ) -> Result<Option<StateRecord>>

Read latest state

Source

pub fn get_state_at_version( &self, namespace: &str, agent_id: &str, key: &str, version: Version, ) -> Result<Option<StateRecord>>

Read state at specific version

Source

pub fn list_keys(&self, namespace: &str, agent_id: &str) -> Result<Vec<String>>

List keys for an agent

Source

pub fn scan_prefix( &self, namespace: &str, agent_id: &str, prefix: &str, ) -> Result<Vec<StateRecord>>

Scan keys with prefix

Source

pub fn replay( &self, namespace: &str, agent_id: &str, start_ts: Option<CommitTs>, end_ts: Option<CommitTs>, ) -> Result<Vec<EventLogEntry>>

Replay events for an agent

Source

pub fn cleanup_expired_transactions(&self)

Cleanup expired transactions (should be called periodically)

Source

pub fn create_snapshot(&self) -> Result<()>

Create a snapshot of current state

Source

pub fn maybe_snapshot(&self, snapshot_interval: u64) -> Result<()>

Check if snapshot should be created and do it if needed

Source

pub fn recover_from_snapshot(&self, snapshot: &Snapshot) -> Result<()>

Load snapshot and replay events after snapshot timestamp

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more