#[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
Send
Send message to node to via the transport.
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
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
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
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.