Struct raft::storage::MemStorage
source · pub struct MemStorage { /* private fields */ }
Expand description
MemStorage
is a thread-safe but incomplete implementation of Storage
, mainly for tests.
A real Storage
should save both raft logs and applied data. However MemStorage
only
contains raft logs. So you can call MemStorage::append
to persist new received unstable raft
logs and then access them with Storage
APIs. The only exception is Storage::snapshot
. There
is no data in Snapshot
returned by MemStorage::snapshot
because applied data is not stored
in MemStorage
.
Implementations§
source§impl MemStorage
impl MemStorage
sourcepub fn new() -> MemStorage
pub fn new() -> MemStorage
Returns a new memory storage value.
sourcepub fn new_with_conf_state<T>(conf_state: T) -> MemStoragewhere
ConfState: From<T>,
pub fn new_with_conf_state<T>(conf_state: T) -> MemStoragewhere ConfState: From<T>,
Create a new MemStorage
with a given Config
. The given Config
will be used to
initialize the storage.
You should use the same input to initialize all nodes.
sourcepub fn initialize_with_conf_state<T>(&self, conf_state: T)where
ConfState: From<T>,
pub fn initialize_with_conf_state<T>(&self, conf_state: T)where ConfState: From<T>,
Initialize a MemStorage
with a given Config
.
You should use the same input to initialize all nodes.
sourcepub fn rl(&self) -> RwLockReadGuard<'_, MemStorageCore>
pub fn rl(&self) -> RwLockReadGuard<'_, MemStorageCore>
Opens up a read lock on the storage and returns a guard handle. Use this with functions that don’t require mutation.
sourcepub fn wl(&self) -> RwLockWriteGuard<'_, MemStorageCore>
pub fn wl(&self) -> RwLockWriteGuard<'_, MemStorageCore>
Opens up a write lock on the storage and returns guard handle. Use this with functions that take a mutable reference to self.
Trait Implementations§
source§impl Clone for MemStorage
impl Clone for MemStorage
source§fn clone(&self) -> MemStorage
fn clone(&self) -> MemStorage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Default for MemStorage
impl Default for MemStorage
source§fn default() -> MemStorage
fn default() -> MemStorage
source§impl Storage for MemStorage
impl Storage for MemStorage
source§fn initial_state(&self) -> Result<RaftState>
fn initial_state(&self) -> Result<RaftState>
Implements the Storage trait.
source§fn entries(
&self,
low: u64,
high: u64,
max_size: impl Into<Option<u64>>,
context: GetEntriesContext
) -> Result<Vec<Entry>>
fn entries( &self, low: u64, high: u64, max_size: impl Into<Option<u64>>, context: GetEntriesContext ) -> Result<Vec<Entry>>
Implements the Storage trait.
source§fn first_index(&self) -> Result<u64>
fn first_index(&self) -> Result<u64>
Implements the Storage trait.
source§fn last_index(&self) -> Result<u64>
fn last_index(&self) -> Result<u64>
Implements the Storage trait.