Skip to main content

Action

Enum Action 

Source
#[non_exhaustive]
pub enum Action { Send { to: NodeId, message: Message, }, Apply { index: Index, term: Term, command: Vec<u8>, }, Snapshot { index: Index, term: Term, }, RestoreSnapshot { index: Index, term: Term, data: Vec<u8>, }, MembershipChanged { members: Vec<NodeId>, }, }
Expand description

An instruction RaftNode::step returns for the caller to carry out.

The node decides what must happen; the caller makes it happen. Execute the actions in the order returned: any state the protocol depends on has already been persisted through the RaftLog before a Send is emitted, so honouring the order preserves Raft’s durability rule.

The enum is #[non_exhaustive]: future versions may add variants, so a match must include a wildcard arm.

§Examples

use raft_io::{Action, Event, RaftConfig, RaftNode};

let mut node = RaftNode::new(RaftConfig::single(1));
while !node.is_leader() {
    let _ = node.step(Event::Tick).unwrap();
}
for action in node.step(Event::Propose(b"x".to_vec())).unwrap() {
    match action {
        Action::Send { to, message } => { let _ = (to, message); }
        Action::Apply { index, term, command } => { let _ = (index, term, command); }
        _ => {}
    }
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Send

Send message to node to via the transport.

Fields

§to: NodeId

Destination node.

§message: Message

The message to deliver.

§

Apply

Apply a committed command to the application state machine.

Applies are emitted in strictly increasing index order and each index is emitted at most once, so the caller can apply them blindly in sequence.

Fields

§index: Index

Index of the committed entry.

§term: Term

Term the entry was created in.

§command: Vec<u8>

The opaque command bytes to apply.

§

Snapshot

Take a snapshot of the state machine through index and return it.

A hint emitted when the log has grown past the configured snapshot threshold. The application serializes its state up to index and feeds it back with Event::Snapshot, after which the node compacts the log. Acting on the hint is optional but unbounded growth follows from ignoring it.

Fields

§index: Index

The applied index the snapshot should cover.

§term: Term

Term of the entry at index.

§

RestoreSnapshot

Reset the state machine to an installed snapshot.

Emitted on a follower that received a leader’s snapshot because it had fallen too far behind to replicate entry by entry. The application replaces its state with data (which represents the state through index); subsequent Apply actions resume from index + 1.

Fields

§index: Index

The index the snapshot covers.

§term: Term

Term of the entry at index.

§data: Vec<u8>

The serialized state to restore.

§

MembershipChanged

The cluster’s voting membership changed.

Emitted whenever the node adopts a new configuration (as a leader appending the change, or a follower receiving it). The application should update its transport so it can reach the new members and stop reaching removed ones. Membership takes effect immediately on this action, before the change commits.

Fields

§members: Vec<NodeId>

The new voting membership.

Trait Implementations§

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

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 Debug for Action

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Action

Source§

impl PartialEq for Action

Source§

fn eq(&self, other: &Action) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Action

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, 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> 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<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error