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
impl HighWaterStateMachine
Sourcepub fn new() -> Self
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.
Sourcepub fn with_store(store: Arc<dyn SnapshotStore>) -> Result<Self>
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.
Sourcepub fn with_store_and_active_version(
store: Arc<dyn SnapshotStore>,
active_write_version: ActiveWriteVersion,
) -> Result<Self>
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.
Sourcepub fn active_write_version(&self) -> u8
pub fn active_write_version(&self) -> u8
The version this SM currently stamps onto snapshots.
Sourcepub async fn current_value(&self) -> u64
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.
Sourcepub fn dense_value(&self, key: &str) -> u64
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
impl Clone for HighWaterStateMachine
Source§impl Default for HighWaterStateMachine
impl Default for HighWaterStateMachine
Source§impl RaftSnapshotBuilder<TypeConfig> for HighWaterStateMachine
impl RaftSnapshotBuilder<TypeConfig> for HighWaterStateMachine
Source§async fn build_snapshot(
&mut self,
) -> Result<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>, Error>
async fn build_snapshot( &mut self, ) -> Result<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>, Error>
Source§impl RaftStateMachine<TypeConfig> for HighWaterStateMachine
impl RaftStateMachine<TypeConfig> for HighWaterStateMachine
Source§type SnapshotData = Cursor<Vec<u8>>
type SnapshotData = Cursor<Vec<u8>>
Source§type SnapshotBuilder = HighWaterStateMachine
type SnapshotBuilder = HighWaterStateMachine
Source§async fn applied_state(
&mut self,
) -> Result<(Option<LogIdOf<TypeConfig>>, StoredMembershipOf<TypeConfig>), Error>
async fn applied_state( &mut self, ) -> Result<(Option<LogIdOf<TypeConfig>>, StoredMembershipOf<TypeConfig>), Error>
Source§async fn apply<Strm>(&mut self, entries: Strm) -> Result<(), Error>
async fn apply<Strm>(&mut self, entries: Strm) -> Result<(), Error>
Source§async fn get_snapshot_builder(&mut self) -> Self::SnapshotBuilder
async fn get_snapshot_builder(&mut self) -> Self::SnapshotBuilder
Source§async fn begin_receiving_snapshot(&mut self) -> Result<Cursor<Vec<u8>>, Error>
async fn begin_receiving_snapshot(&mut self) -> Result<Cursor<Vec<u8>>, Error>
Source§async fn install_snapshot(
&mut self,
meta: &SnapshotMetaOf<TypeConfig>,
snapshot: Cursor<Vec<u8>>,
) -> Result<(), Error>
async fn install_snapshot( &mut self, meta: &SnapshotMetaOf<TypeConfig>, snapshot: Cursor<Vec<u8>>, ) -> Result<(), Error>
Source§async fn get_current_snapshot(
&mut self,
) -> Result<Option<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>>, Error>
async fn get_current_snapshot( &mut self, ) -> Result<Option<SnapshotOf<TypeConfig, Cursor<Vec<u8>>>>, Error>
Source§fn try_create_snapshot_builder(
&mut self,
force: bool,
) -> impl Future<Output = Option<Self::SnapshotBuilder>> + Send
fn try_create_snapshot_builder( &mut self, force: bool, ) -> impl Future<Output = Option<Self::SnapshotBuilder>> + Send
Auto Trait Implementations§
impl !RefUnwindSafe for HighWaterStateMachine
impl !UnwindSafe for HighWaterStateMachine
impl Freeze for HighWaterStateMachine
impl Send for HighWaterStateMachine
impl Sync for HighWaterStateMachine
impl Unpin for HighWaterStateMachine
impl UnsafeUnpin for HighWaterStateMachine
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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