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
impl StateMachine
pub fn new(storage: Arc<dyn Storage>) -> Self
Sourcepub fn begin_transaction(&self, timeout_ms: Option<u64>) -> Result<TxnId>
pub fn begin_transaction(&self, timeout_ms: Option<u64>) -> Result<TxnId>
Begin a new transaction
Sourcepub fn write(
&self,
txn_id: &str,
namespace: String,
agent_id: String,
key: String,
value: Value,
) -> Result<()>
pub fn write( &self, txn_id: &str, namespace: String, agent_id: String, key: String, value: Value, ) -> Result<()>
Stage a write operation
Sourcepub fn delete(
&self,
txn_id: &str,
namespace: String,
agent_id: String,
key: String,
) -> Result<()>
pub fn delete( &self, txn_id: &str, namespace: String, agent_id: String, key: String, ) -> Result<()>
Stage a delete operation
Sourcepub fn get_state(
&self,
namespace: &str,
agent_id: &str,
key: &str,
) -> Result<Option<StateRecord>>
pub fn get_state( &self, namespace: &str, agent_id: &str, key: &str, ) -> Result<Option<StateRecord>>
Read latest state
Sourcepub fn get_state_at_version(
&self,
namespace: &str,
agent_id: &str,
key: &str,
version: Version,
) -> Result<Option<StateRecord>>
pub fn get_state_at_version( &self, namespace: &str, agent_id: &str, key: &str, version: Version, ) -> Result<Option<StateRecord>>
Read state at specific version
Sourcepub fn list_keys(&self, namespace: &str, agent_id: &str) -> Result<Vec<String>>
pub fn list_keys(&self, namespace: &str, agent_id: &str) -> Result<Vec<String>>
List keys for an agent
Sourcepub fn scan_prefix(
&self,
namespace: &str,
agent_id: &str,
prefix: &str,
) -> Result<Vec<StateRecord>>
pub fn scan_prefix( &self, namespace: &str, agent_id: &str, prefix: &str, ) -> Result<Vec<StateRecord>>
Scan keys with prefix
Sourcepub fn replay(
&self,
namespace: &str,
agent_id: &str,
start_ts: Option<CommitTs>,
end_ts: Option<CommitTs>,
) -> Result<Vec<EventLogEntry>>
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
Sourcepub fn cleanup_expired_transactions(&self)
pub fn cleanup_expired_transactions(&self)
Cleanup expired transactions (should be called periodically)
Sourcepub fn create_snapshot(&self) -> Result<()>
pub fn create_snapshot(&self) -> Result<()>
Create a snapshot of current state
Sourcepub fn maybe_snapshot(&self, snapshot_interval: u64) -> Result<()>
pub fn maybe_snapshot(&self, snapshot_interval: u64) -> Result<()>
Check if snapshot should be created and do it if needed
Sourcepub fn recover_from_snapshot(&self, snapshot: &Snapshot) -> Result<()>
pub fn recover_from_snapshot(&self, snapshot: &Snapshot) -> Result<()>
Load snapshot and replay events after snapshot timestamp
Auto Trait Implementations§
impl Freeze for StateMachine
impl !RefUnwindSafe for StateMachine
impl Send for StateMachine
impl Sync for StateMachine
impl Unpin for StateMachine
impl !UnwindSafe for StateMachine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more