Skip to main content

HighWaterStateMachine

Struct HighWaterStateMachine 

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

RaftStateMachine for the high-water counter, with pluggable snapshot persistence.

Clone-cheap: the Arc<Mutex<Core>>, the Arc<dyn SnapshotStore>, and the Arc<Mutex<()>> persist lock are all shared by clone. Required by openraft’s get_snapshot_builder contract which uses SnapshotBuilder = Self.

Implementations§

Source§

impl HighWaterStateMachine

Source

pub fn new() -> Self

Build a state machine backed by an in-memory snapshot store.

Equivalent to HighWaterStateMachine::with_store(Arc::new(InMemorySnapshotStore::new())). Snapshots survive within a process but not across restarts; for that use HighWaterStateMachine::with_store with a durable backend such as crate::snapshot_store::RocksdbSnapshotStore.

Source

pub fn with_store(store: Arc<dyn SnapshotStore>) -> Result<Self>

Build a state machine backed by store and rehydrated from whatever snapshot the store currently holds.

If store.load() returns a snapshot, the state machine’s current_value, last_applied, last_membership, dense state, and get_current_snapshot() all reflect that snapshot on return. This is the contract that lets openraft re-enable the default snapshot policy: after a restart the log store’s last_purged_log_id may sit above index 0, and the state machine must already cover those purged entries or openraft will panic during recovery.

The active write version is recovered to at least the persisted snapshot’s leading version byte, so a store holding a v5/dense snapshot does not come back at the baseline (which would trip the fail-loud NotRepresentable guard on the next build_snapshot). For full max-of-evidence recovery — folding in the highest version byte among durable log records as well — seed the cell via recover_active_write_version and pass it to with_store_and_active_version; with_store only sees the snapshot store.

Source

pub fn with_store_and_active_version( store: Arc<dyn SnapshotStore>, active_write_version: ActiveWriteVersion, ) -> Result<Self>

Build a state machine backed by store, sharing active_write_version with the log store (and, in a later phase, the wire sender). Bootstrap constructs and seeds the cell once, then threads the same clone here and into the log store; non-bootstrap callers use with_store, which supplies a fresh BASELINE cell.

Source

pub fn active_write_version(&self) -> u8

The version this SM currently stamps onto snapshots.

Source

pub async fn current_value(&self) -> u64

Read the current high-water value without going through raft.

Returns the value most-recently written by apply or install_snapshot. This is a state-machine-local read; callers that need linearizability must coordinate a read barrier through Raft before calling.

Source

pub fn dense_value(&self, key: &str) -> u64

Read a dense counter by key, returning 0 if absent. State-machine-local read; callers needing linearizability must issue a read barrier first.

Trait Implementations§

Source§

impl Clone for HighWaterStateMachine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for HighWaterStateMachine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RaftSnapshotBuilder<TypeConfig> for HighWaterStateMachine

Source§

type SnapshotData = Cursor<Vec<u8>>

Snapshot data this builder produces. Read more
Source§

async fn build_snapshot( &mut self, ) -> Result<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>, Error>

Build snapshot Read more
Source§

impl RaftStateMachine<TypeConfig> for HighWaterStateMachine

Source§

type SnapshotData = Cursor<Vec<u8>>

Snapshot data for exposing a snapshot for reading & writing. Read more
Source§

type SnapshotBuilder = HighWaterStateMachine

Snapshot builder type. Read more
Source§

async fn applied_state( &mut self, ) -> Result<(Option<LogIdOf<TypeConfig>>, StoredMembershipOf<TypeConfig>), Error>

Returns the last applied log id which is recorded in state machine, and the last applied membership config. Read more
Source§

async fn apply<Strm>(&mut self, entries: Strm) -> Result<(), Error>

Apply the given payload of entries to the state machine. Read more
Source§

async fn get_snapshot_builder(&mut self) -> Self::SnapshotBuilder

Get the snapshot builder for the state machine. Read more
Source§

async fn begin_receiving_snapshot(&mut self) -> Result<Cursor<Vec<u8>>, Error>

Create a new blank snapshot, returning a writable handle to the snapshot object. Read more
Source§

async fn install_snapshot( &mut self, meta: &SnapshotMetaOf<TypeConfig>, snapshot: Cursor<Vec<u8>>, ) -> Result<(), Error>

Install a snapshot which has finished streaming from the leader. Read more
Source§

async fn get_current_snapshot( &mut self, ) -> Result<Option<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>>, Error>

Get a readable handle to the current snapshot. Read more
Source§

fn try_create_snapshot_builder( &mut self, force: bool, ) -> impl Future<Output = Option<Self::SnapshotBuilder>> + Send

Try to create a snapshot builder for the state machine. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OptionalSend for T
where T: Send + ?Sized,

Source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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