noraft 0.4.0

Minimal, feature-complete Raft for Rust - no I/O, no dependencies
Documentation
  • Coverage
  • 100%
    66 out of 66 items documented2 out of 5 items with examples
  • Size
  • Source code size: 192.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 9.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • sile/noraft
    50 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sile

noraft

noraft Documentation Actions Status License

noraft: Minimal, feature-complete Raft for Rust - no I/O, no dependencies.

noraft is a minimal but feature-complete, sans I/O implementation of the Raft distributed consensus algorithm.

Node is the main struct that represents a Raft node. It offers methods for creating a cluster, proposing commands, updating cluster configurations, handling incoming messages, snapshotting, and more.

Node itself does not execute I/O operations. Instead, it generates Actions that represent pending I/O operations. How to execute these actions is up to the crate user.

noraft keeps its API surface minimal and lets users choose and integrate their own I/O layer freely.

Except for a few optimizations, noraft is a very straightforward (yet efficient) implementation of the Raft algorithm. This crate focuses on the core part of the algorithm. So, offering various convenience features (which are not described in the Raft paper) is left to the crate user.

The following example outlines a basic usage flow of this crate:

// Start a node.
let mut node = noraft::Node::start(noraft::NodeId::new(0));

// Create a three nodes cluster.
let commit_position = node.create_cluster(&[
    noraft::NodeId::new(0),
    noraft::NodeId::new(1),
    noraft::NodeId::new(2),
]);

// Execute actions requested by the node until the cluster creation is complete.
while node.get_commit_status(commit_position).is_in_progress() {
    for action in node.actions_mut() {
        // How to execute actions is up to the crate user.
        match action {
           noraft::Action::SetElectionTimeout => { /* ... */ },
           noraft::Action::SaveCurrentTerm => { /* ... */ },
           noraft::Action::SaveVotedFor => { /* ... */ },
           noraft::Action::BroadcastMessage(_) => { /* ... */ },
           noraft::Action::AppendLogEntries(_) => { /* ... */ },
           noraft::Action::SendMessage(_, _) => { /* ... */ },
           noraft::Action::InstallSnapshot(_) => { /* ... */ },
        }
    }

    // If the election timeout is expired, handle it.
    if is_election_timeout_expired() {
        node.handle_election_timeout();
    }

    // If a message is received, handle it.
    while let Some(message) = try_receive_message() {
        node.handle_message(&message);
    }
}

// Propose a user-defined command.
let commit_position = node.propose_command();

// Execute actions as before.