[][src]Struct rast::Raft

pub struct Raft { /* fields omitted */ }

An implementation of the raft consensus protocol.

Paraphrased from the Raft paper: Raft is a consensus algorithm for managing a replicated state machine via a replicated log. Each node (called a server by the Raft literature) stores a log containing a series of commands, which its state machine executes in order. Each log contains the same commands in the same order, so each state machine processes the same sequence of commands. Since the state machines are deterministic, the maintained states all match.

This is a deterministic implementation of the Raft logic. Network and disk IO are modeled as inputs and outputs to the step method. This method takes one input (an rpc arrival, a disk write has finished) and produces zero or more outputs (send this rpc, write this to disk). Raft uses a clock for availability and this is also modeled as an input. step is called in a loop, invoked whenever there is a new input. This produces outputs, which represent network/disk IO to be performed. The completion of that IO is then communicated as an input to step (possibly on another node).

These input and output events are written to be fully pipelineable. For example, when an "AppendEntries" rpc arrives, Raft requires that the new log entries are persisted to disk before the rpc response is sent (similarly for "RequestVote" and persisting the Raft "hard state"). An output requests the disk write and when it finishes an input communicating this is given to step. This will, in turn, cause an output with the "AppendEntries" rpc response. While the entries is being persisted to disk, step can continue to be called with other rpc messages, click ticks, etc. See Input and Output for details.

Reads and Writes are similarly modeled as inputs. With each, a Future is passed in that is resolved with the result of the read or write when it completes.

This is an implementation of only the core Raft logic and needs an rpc system, service discovery, a disk-backed log, and a disk-backed state machine. Implementations of these, as well as a "batteries included" runtime loop is included in the runtime module.

TODO: Document consistency guarantees.

Implementations

impl Raft[src]

pub fn new(id: NodeID, peers: Vec<NodeID>, cfg: Config) -> Raft[src]

Returns a new, empty Raft node.

This should not be used when a node restarts. The id must be unique all-time. It must be reused if the node restarts and cannot ever be reused (whether by another node or this one if it loses data). The peers must contain all nodes in the group, including this one.

pub fn id(&self) -> NodeID[src]

The unique id of this node.

pub fn step(&mut self, output: &mut impl Extend<Output>, input: Input)[src]

Advance the raft logic in response to a single input.

This is guaranteed to be non-blocking. Any blocking work (network/disk IO) is emitted as an Output entry.

Trait Implementations

impl Drop for Raft[src]

Auto Trait Implementations

impl RefUnwindSafe for Raft

impl Send for Raft

impl Sync for Raft

impl Unpin for Raft

impl UnwindSafe for Raft

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.