Action

Enum Action 

Source
pub enum Action {
    SetElectionTimeout,
    SaveCurrentTerm,
    SaveVotedFor,
    BroadcastMessage(Message),
    AppendLogEntries(LogEntries),
    SendMessage(NodeId, Message),
    InstallSnapshot(NodeId),
}
Expand description

Action represents the I/O operations for Node that crate users need to execute.

Variants§

§

SetElectionTimeout

Set an election timeout.

When the timeout expires, please call Node::handle_election_timeout().

An existing timeout is cancelled when a new one is set.

The user needs to set different timeouts for each node based on its Role as follows:

  • For Role::Leader:
    • When the timeout expires, the leader sends heartbeat messages to followers.
    • To maintain the role of leader, the timeout should be shorter than the election timeouts of the followers.
  • For Role::Candidate:
    • When the timeout expires, the candidate starts a new election.
    • The timeout should have some randomness to avoid conflicts with other candidates.
  • For Role::Follower:
    • When the timeout expires, the follower starts a new election.
    • The timeout should be longer than the heartbeat timeout of the leader.

Note that the appropriate timeout values depend on the specific application.

§

SaveCurrentTerm

Save the current term (Node::current_term()) to persistent storage.

To guarantee properties by the Raft algorithm, the value must be saved before responding to users or sending messages to other nodes.

§

SaveVotedFor

Save the voted-for node ID (Node::voted_for()) to persistent storage.

To guarantee properties by the Raft algorithm, the value must be saved before responding to users or sending messages to other nodes.

§

BroadcastMessage(Message)

Broadcast a message to all other nodes (Node::peers()).

On the receiving side, the message is handled by Node::handle_message().

Unlike storage-related actions, this action can be executed asynchronously and can be discarded if the communication link is busy. Additionally, the reordering of messages to the same destination node is acceptable.

§

AppendLogEntries(LogEntries)

Append log entries to the node-local log on persistent storage.

Note that previously written log suffix entries may be overwritten by these new entries. In other words, the LogEntries::last_position().index can be any value within the range from the start index to the end index of the local log.

To guarantee properties by the Raft algorithm, the entries must be appended before responding to users or other nodes. (However, because writing all log entries to persistent storage synchronously could be too costly, in reality, the entries are often written asynchronously.)

§

SendMessage(NodeId, Message)

Send a message to a specific node.

On the receiving side, the message is handled by Node::handle_message().

Unlike storage-related actions, this action can be executed asynchronously and can be discarded if the communication link is busy. Additionally, the reordering of messages to the same destination node is acceptable.

Additionally, if an AppendEntriesRPC contains too many entries to be sent in a single message, they can be safely truncated using LogEntries::truncate() before sending the message.

§

InstallSnapshot(NodeId)

Install a snapshot on a specific node.

The user is responsible for managing the details of sending and installing the snapshots.

Note that once the snapshot installation is complete, the user needs to call Node::handle_snapshot_installed().

Trait Implementations§

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

Returns a duplicate 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 Debug for Action

Source§

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

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

impl Hash for Action

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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 · 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 Eq for Action

Source§

impl StructuralPartialEq for Action

Auto Trait Implementations§

§

impl Freeze for Action

§

impl RefUnwindSafe for Action

§

impl Send for Action

§

impl Sync for Action

§

impl Unpin for Action

§

impl UnwindSafe for Action

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.