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