1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! # skiff
//!
//! An embedded [Raft](https://raft.github.io/) consensus library backed by
//! [sled](https://docs.rs/sled). Skiff lets you embed a replicated key-value
//! store directly in your application without running a separate consensus
//! service.
//!
//! ## Architecture
//!
//! Each participating process runs a [`Skiff`] node. Nodes elect a leader
//! among themselves using the Raft protocol. All writes are routed to the
//! leader, replicated to a majority of followers, and only acknowledged once
//! they are durably committed. Followers automatically forward client
//! requests to the current leader, so callers can connect to any node.
//!
//! Persistent state (Raft hard state, the log, and applied key-value data) is
//! stored in a [sled](https://docs.rs/sled) embedded database. A node that
//! restarts will recover its identity and log from disk and re-join the
//! cluster without any manual intervention.
//!
//! ## Quick start
//!
//! ```no_run
//! use std::net::Ipv4Addr;
//! use skiff_rs::{Builder, Client};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Build and start a single-node cluster.
//! let node = Builder::new()
//! .set_dir("/tmp/my-skiff-node")
//! .bind("127.0.0.1".parse()?)
//! .build()?;
//!
//! let node_ref = node.clone();
//! tokio::spawn(async move { node_ref.start().await });
//!
//! // Block until a leader is elected before connecting a client.
//! node.wait_for_leader(std::time::Duration::from_secs(2)).await?;
//!
//! // Connect a client and perform some operations.
//! let mut client = Client::new(vec!["127.0.0.1".parse()?]);
//! client.connect().await?;
//!
//! client.insert("greeting", "hello world").await?;
//! let value: Option<String> = client.get("greeting").await?;
//! println!("{:?}", value);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Multi-node cluster
//!
//! Pass the addresses of existing cluster members to [`Builder::join_cluster`]
//! when constructing additional nodes. The new node will contact one of its
//! peers and register itself via the Raft `add_server` RPC.
//!
//! ```no_run
//! use skiff_rs::Builder;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Node 1 – sole member of a brand-new cluster.
//! let node1 = Builder::new()
//! .set_dir("/tmp/node1")
//! .bind("127.0.0.1".parse()?)
//! .build()?;
//!
//! // Node 2 – joins the cluster seeded by node 1.
//! let node2 = Builder::new()
//! .set_dir("/tmp/node2")
//! .bind("127.0.0.2".parse()?)
//! .join_cluster(vec!["127.0.0.1".parse()?])
//! .build()?;
//! # Ok(())
//! # }
//! ```
pub use Builder;
pub use Client;
pub use Error;
pub use ;
pub use Subscriber;