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

source

pub fn new() -> MemStorage

Returns a new memory storage value.

source

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.

source

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.

source

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.

source

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

source§

fn clone(&self) -> MemStorage

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for MemStorage

source§

fn default() -> MemStorage

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

impl Storage for MemStorage

source§

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>>

Implements the Storage trait.

source§

fn term(&self, idx: u64) -> Result<u64>

Implements the Storage trait.

source§

fn first_index(&self) -> Result<u64>

Implements the Storage trait.

source§

fn last_index(&self) -> Result<u64>

Implements the Storage trait.

source§

fn snapshot(&self, request_index: u64, _to: u64) -> Result<Snapshot>

Implements the Storage trait.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> SendSyncUnwindSafe for Twhere T: Send + Sync + UnwindSafe + ?Sized,