Skip to main content

Event

Enum Event 

Source
pub enum Event {
    Tick,
    Message(Message),
    Propose(Vec<u8>),
    Snapshot {
        index: Index,
        data: Vec<u8>,
    },
    AddServer(NodeId),
    RemoveServer(NodeId),
    TransferLeadership(NodeId),
}
Expand description

An input handed to RaftNode::step.

A node only ever changes state in response to an event. There are exactly three, matching Raft’s three sources of progress: the passage of (logical) time, a message from a peer, and a request from a client.

§Examples

use raft_io::{Event, Message, RequestVote};

let _tick = Event::Tick;
let _propose = Event::Propose(b"command".to_vec());
let _msg = Event::Message(Message::RequestVote(RequestVote {
    term: 1, candidate: 2, last_log_index: 0, last_log_term: 0, force: false,
}));

Variants§

§

Tick

One logical clock tick. The caller decides the wall-clock interval.

§

Message(Message)

A message arrived from a peer.

§

Propose(Vec<u8>)

A client proposes a command to be replicated and applied.

Only a leader may accept a proposal; on any other node step returns Error::NotLeader.

§

Snapshot

The application supplies a snapshot of its state machine through index.

This is the reply to an Action::Snapshot hint: the application has serialized its state up to index into data. The node compacts the log up to index. A snapshot for an uncommitted or stale index is ignored.

Fields

§index: Index

The log index the snapshot covers (must be applied and committed).

§data: Vec<u8>

The serialized state machine state.

§

AddServer(NodeId)

Add a voting server to the cluster.

Only the leader may reconfigure; elsewhere step returns Error::NotLeader. One change is processed at a time — a request made while a previous configuration change is still uncommitted returns Error::ConfigInProgress. Adding a server already present is a no-op.

§

RemoveServer(NodeId)

Remove a voting server from the cluster.

Same rules as AddServer. Removing the leader makes it step down once the change commits.

§

TransferLeadership(NodeId)

Ask the leader to transfer leadership to target.

The leader brings target fully up to date, then signals it to start an election immediately so it takes over with minimal disruption. A no-op on a non-leader or when target is not a voter.

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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