Skip to main content

Node

Struct Node 

Source
pub struct Node { /* private fields */ }
Expand description

One Raft node.

Implementations§

Source§

impl Node

Source

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.

Source

pub const fn id(&self) -> NodeId

This node’s id.

Source

pub const fn role(&self) -> Role

The node’s current role.

Source

pub const fn current_term(&self) -> Term

The node’s current term.

Source

pub const fn voted_for(&self) -> Option<NodeId>

Who this node voted for in its current term, if anyone.

Source

pub const fn commit_index(&self) -> LogIndex

The node’s commit index.

Source

pub const fn last_applied(&self) -> LogIndex

The highest index this node has emitted an Action::Apply for.

Source

pub const fn log(&self) -> &Log

The node’s log, for drivers, oracles, and tests.

Source

pub const fn cluster(&self) -> &ClusterConfig

The current cluster configuration.

Source

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

Source

pub const fn leader_id(&self) -> Option<NodeId>

The node’s current best hint for the leader’s identity.

Source

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.

Source

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.

Source

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.

Source

pub fn step(&mut self, event: Event) -> Vec<Action>

Advance the state machine by one event, returning the actions the driver must execute, in order.

Trait Implementations§

Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Node

§

impl Freeze for Node

§

impl Move for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.