Trait openraft::storage::RaftStorage

source ·
pub trait RaftStorage<C>: RaftLogReader<C> + OptionalSend + OptionalSync + 'static + Send
where C: RaftTypeConfig,
{ type LogReader: RaftLogReader<C>; type SnapshotBuilder: RaftSnapshotBuilder<C>;
Show 15 methods // Required methods fn save_vote( &mut self, vote: &Vote<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send; fn read_vote( &mut self ) -> impl Future<Output = Result<Option<Vote<C::NodeId>>, StorageError<C::NodeId>>> + Send; fn get_log_state( &mut self ) -> impl Future<Output = Result<LogState<C>, StorageError<C::NodeId>>> + Send; fn get_log_reader(&mut self) -> impl Future<Output = Self::LogReader> + Send; fn append_to_log<I>( &mut self, entries: I ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send where I: IntoIterator<Item = C::Entry> + OptionalSend; fn delete_conflict_logs_since( &mut self, log_id: LogId<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send; fn purge_logs_upto( &mut self, log_id: LogId<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send; fn last_applied_state( &mut self ) -> impl Future<Output = Result<(Option<LogId<C::NodeId>>, StoredMembership<C::NodeId, C::Node>), StorageError<C::NodeId>>> + Send; fn apply_to_state_machine( &mut self, entries: &[C::Entry] ) -> impl Future<Output = Result<Vec<C::R>, StorageError<C::NodeId>>> + Send; fn get_snapshot_builder( &mut self ) -> impl Future<Output = Self::SnapshotBuilder> + Send; fn begin_receiving_snapshot( &mut self ) -> impl Future<Output = Result<Box<C::SnapshotData>, StorageError<C::NodeId>>> + Send; fn install_snapshot( &mut self, meta: &SnapshotMeta<C::NodeId, C::Node>, snapshot: Box<C::SnapshotData> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send; fn get_current_snapshot( &mut self ) -> impl Future<Output = Result<Option<Snapshot<C>>, StorageError<C::NodeId>>> + Send; // Provided methods fn save_committed( &mut self, _committed: Option<LogId<C::NodeId>> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send { ... } fn read_committed( &mut self ) -> impl Future<Output = Result<Option<LogId<C::NodeId>>, StorageError<C::NodeId>>> + Send { ... }
}
👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead
Expand description

A trait defining the interface for a Raft storage system.

Typically, the storage implementation as such will be hidden behind a Box<T>, Arc<T> or a similar, more advanced reference type and this interface implemented on that reference type.

All methods on the storage are called inside of Raft core task. There is no concurrency on the storage, except concurrency with snapshot builder and log reader, both created by this API. The implementation of the API has to cope with (infrequent) concurrent access from these two components.

Required Associated Types§

source

type LogReader: RaftLogReader<C>

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Log reader type.

source

type SnapshotBuilder: RaftSnapshotBuilder<C>

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Snapshot builder type.

Required Methods§

source

fn save_vote( &mut self, vote: &Vote<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

To ensure correctness: the vote must be persisted on disk before returning.

source

fn read_vote( &mut self ) -> impl Future<Output = Result<Option<Vote<C::NodeId>>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead
source

fn get_log_state( &mut self ) -> impl Future<Output = Result<LogState<C>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Returns the last deleted log id and the last log id.

The impl should not consider the applied log id in state machine. The returned last_log_id could be the log id of the last present log entry, or the last_purged_log_id if there is no entry at all.

source

fn get_log_reader(&mut self) -> impl Future<Output = Self::LogReader> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Get the log reader.

The method is intentionally async to give the implementation a chance to use asynchronous sync primitives to serialize access to the common internal object, if needed.

source

fn append_to_log<I>( &mut self, entries: I ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send
where I: IntoIterator<Item = C::Entry> + OptionalSend,

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Append a payload of entries to the log.

Though the entries will always be presented in order, each entry’s index should be used to determine its location to be written in the log.

To ensure correctness:

  • All entries must be persisted on disk before returning.

  • There must not be a hole in logs. Because Raft only examine the last log id to ensure correctness.

source

fn delete_conflict_logs_since( &mut self, log_id: LogId<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Delete conflict log entries since log_id, inclusive.

This method is called by a follower or learner when the local logs conflict with the leaders.

To ensure correctness:

  • When this function returns, the deleted logs must not be read(e.g., by RaftLogReader::try_get_log_entries()) any more.

  • It must not leave a hole in the log. In other words, if it has to delete logs in more than one transactions, it must delete logs in backward order. So that in a case server crashes, it won’t leave a hole.

source

fn purge_logs_upto( &mut self, log_id: LogId<C::NodeId> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Delete applied log entries upto log_id, inclusive.

To ensure correctness:

  • It must not leave a hole in logs.
source

fn last_applied_state( &mut self ) -> impl Future<Output = Result<(Option<LogId<C::NodeId>>, StoredMembership<C::NodeId, C::Node>), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

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

§Correctness requirements

It is all right to return a membership with greater log id than the last-applied-log-id.

source

fn apply_to_state_machine( &mut self, entries: &[C::Entry] ) -> impl Future<Output = Result<Vec<C::R>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Apply the given payload of entries to the state machine.

The Raft protocol guarantees that only logs which have been committed, that is, logs which have been replicated to a quorum of the cluster, will be applied to the state machine.

This is where the business logic of interacting with your application’s state machine should live. This is 100% application specific. Perhaps this is where an application specific transaction is being started, or perhaps committed. This may be where a key/value is being stored.

For every entry to apply, an implementation should:

  • Store the log id as last applied log id.
  • Deal with the EntryPayload::Normal() log, which is business logic log.
  • Store membership config in EntryPayload::Membership.

Note that for a membership log, the implementation need to do nothing about it, except storing it.

An implementation may choose to persist either the state machine or the snapshot:

  • An implementation with persistent state machine: persists the state on disk before returning from apply_to_state_machine(). So that a snapshot does not need to be persistent.

  • An implementation with persistent snapshot: apply_to_state_machine() does not have to persist state on disk. But every snapshot has to be persistent. And when starting up the application, the state machine should be rebuilt from the last snapshot.

source

fn get_snapshot_builder( &mut self ) -> impl Future<Output = Self::SnapshotBuilder> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Get the snapshot builder for the state machine.

The method is intentionally async to give the implementation a chance to use asynchronous sync primitives to serialize access to the common internal object, if needed.

source

fn begin_receiving_snapshot( &mut self ) -> impl Future<Output = Result<Box<C::SnapshotData>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Create a new blank snapshot, returning a writable handle to the snapshot object.

Raft will use this handle to receive snapshot data.

See the storage chapter of the guide for details on log compaction / snapshotting.

source

fn install_snapshot( &mut self, meta: &SnapshotMeta<C::NodeId, C::Node>, snapshot: Box<C::SnapshotData> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Install a snapshot which has finished streaming from the leader.

All other snapshots should be deleted at this point.

§snapshot

A snapshot created from an earlier call to begin_receiving_snapshot which provided the snapshot.

source

fn get_current_snapshot( &mut self ) -> impl Future<Output = Result<Option<Snapshot<C>>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Get a readable handle to the current snapshot, along with its metadata.

§implementation algorithm

Implementing this method should be straightforward. Check the configured snapshot directory for any snapshot files. A proper implementation will only ever have one active snapshot, though another may exist while it is being created. As such, it is recommended to use a file naming pattern which will allow for easily distinguishing between the current live snapshot, and any new snapshot which is being created.

A proper snapshot implementation will store the term, index and membership config as part of the snapshot, which should be decoded for creating this method’s response data.

Provided Methods§

source

fn save_committed( &mut self, _committed: Option<LogId<C::NodeId>> ) -> impl Future<Output = Result<(), StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Saves the last committed log id to storage.

§Optional feature

If the state machine flushes state to disk before returning from apply(), then the application does not need to implement this method.

Otherwise, i.e., the state machine just relies on periodical snapshot to persist state to disk:

  • If the committed log id is saved, the state machine will be recovered to the state corresponding to this committed log id upon system startup, i.e., the state at the point when the committed log id was applied.

  • If the committed log id is not saved, Openraft will just recover the state machine to the state of the last snapshot taken.

source

fn read_committed( &mut self ) -> impl Future<Output = Result<Option<LogId<C::NodeId>>, StorageError<C::NodeId>>> + Send

👎Deprecated since 0.8.4: use RaftLogStorage and RaftStateMachine instead

Return the last saved committed log id by Self::save_committed.

Object Safety§

This trait is not object safe.

Implementors§