pub struct Node { /* private fields */ }Expand description
One Raft node.
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
id: NodeId,
config: Config,
cluster: ClusterConfig,
seed: u64,
) -> Result<Self, ConfigError>
pub fn new( id: NodeId, config: Config, cluster: ClusterConfig, seed: u64, ) -> Result<Self, ConfigError>
Create a fresh follower with an empty log in term 0.
seed is the driver-supplied deterministic seed for this node’s
election timer offsets. It is not OS randomness: the same seed
and the same event sequence always produce the same deadlines.
§Errors
Returns the ConfigError from Config::validate when the
timing configuration is invalid.
Sourcepub const fn current_term(&self) -> Term
pub const fn current_term(&self) -> Term
The node’s current term.
Sourcepub const fn voted_for(&self) -> Option<NodeId>
pub const fn voted_for(&self) -> Option<NodeId>
Who this node voted for in its current term, if anyone.
Sourcepub const fn commit_index(&self) -> LogIndex
pub const fn commit_index(&self) -> LogIndex
The node’s commit index.
Sourcepub const fn last_applied(&self) -> LogIndex
pub const fn last_applied(&self) -> LogIndex
The highest index this node has emitted an Action::Apply for.
Sourcepub const fn cluster(&self) -> &ClusterConfig
pub const fn cluster(&self) -> &ClusterConfig
The current cluster configuration.
Sourcepub const fn last_config_index(&self) -> LogIndex
pub const fn last_config_index(&self) -> LogIndex
The log index of the newest config entry in this node’s log, or 0 when the log holds none (the construction configuration rules). A leader rejects a new config change while this index is above its commit index (invariant M-01).
Sourcepub const fn leader_id(&self) -> Option<NodeId>
pub const fn leader_id(&self) -> Option<NodeId>
The node’s current best hint for the leader’s identity.
Sourcepub fn progress(&self, peer: NodeId) -> Option<(LogIndex, LogIndex)>
pub fn progress(&self, peer: NodeId) -> Option<(LogIndex, LogIndex)>
A leader’s replication progress for peer, as
(next_index, match_index). None when this node is not leading
or has no progress entry for the peer.
Sourcepub fn stats(&self) -> NodeStats
pub fn stats(&self) -> NodeStats
The node’s whole operating state as data, for drivers, dashboards, and tests (invariant O-01).
The snapshot gathers the values the individual accessors
report at this instant into one comparable struct, so a
driver can log, diff, or assert on a node’s state without
stepping it. The peers map carries a leader’s replication
progress and is empty in every other role, where progress
is not tracked.
Sourcepub const fn poll_timeout(&self) -> Option<Tick>
pub const fn poll_timeout(&self) -> Option<Tick>
The next tick at which the driver must wake this node with an
Event::Tick, if it has a deadline pending. Leaders return
their heartbeat deadline; everyone else returns their election
deadline.