[][src]Crate rast

An implementation of the raft consensus protocol.

Examples

The core logic is deterministic and single threaded.

use std::time::Instant;
use rast::prelude::*;

let mut raft = Raft::new(NodeID(0), vec![NodeID(0)], Config::default());
let mut output = vec![];
raft.step(&mut output, Input::Tick(Instant::now()));

A "batteries included" runtime is also available that hooks this up to a ticker and persistent log. This is enabled by opting in to the "runtime" crate feature.

use std::time::Instant;
use rast::prelude::*;
use rast::runtime::{Runtime,MemRPC,MemLog,RastClient};
use extreme;

async fn do_work(client: RastClient) -> String {
  let _ = client.write(WriteReq{payload: "1".as_bytes().to_vec()});
  let read = client.read(ReadReq{payload: vec![]});
  let result_bytes = read.await.unwrap();
  String::from_utf8(result_bytes.payload).unwrap()
}

let raft = Raft::new(NodeID(0), vec![NodeID(0)], Config::default(), Instant::now());
let mut rpc = MemRPC::new();
let runtime = Runtime::new(raft, rpc.clone(), MemLog::new());
rpc.register(NodeID(0), runtime.sender());

// This client is Clone+Send.
let client = runtime.client();
assert_eq!(extreme::run(do_work(client)), "1");

Modules

prelude

The Raft prelude.

runtime

A "batteries included" runtime.

Structs

Config

Raft tunables.

Entry

An entry in the Raft log.

Index

A Raft index.

Message

An rpc message.

NodeID

A unique identifier for a node in a raft group.

NotLeaderError

An error returned when a read or write was sent to a node that was not the Raft leader.

PersistRes

See Input::PersistRes.

Raft

An implementation of the raft consensus protocol.

ReadFuture

A Future resolved with the result of a user read.

ReadID

An internal identifier for tracking the allowability of a read request.

ReadReq

See Input::Read.

ReadRes

See Input::Read.

ReadStateMachineRes

See Input::ReadStateMachineRes.

Term

A Raft term.

WriteFuture

A Future resolved with the result of a user write.

WriteReq

See Input::Write.

WriteRes

See Input::Write.

Enums

ClientError

An error to be handed by the user of this Raft library.

Input

An input to step.

Output

An output from step.