1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// All possible states of a Raft node.
#[derive(Debug, Clone, Copy, Default)]
#[derive(PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum ServerState {
/// The node is completely passive; replicating entries, but neither voting nor timing out.
#[default]
Learner,
/// The node is replicating logs from the leader.
Follower,
/// The node is campaigning to become the cluster leader.
Candidate,
/// The node is the Raft cluster leader.
Leader,
/// The Raft node is shutting down.
Shutdown,
}
impl ServerState {
/// Check if currently in learner state.
pub fn is_learner(&self) -> bool {
matches!(self, Self::Learner)
}
/// Check if currently in follower state.
pub fn is_follower(&self) -> bool {
matches!(self, Self::Follower)
}
/// Check if currently in candidate state.
pub fn is_candidate(&self) -> bool {
matches!(self, Self::Candidate)
}
/// Check if currently in leader state.
pub fn is_leader(&self) -> bool {
matches!(self, Self::Leader)
}
}