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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! `raftbare` is a minimal but feature-complete, I/O-free implementation of the [Raft] distributed consensus algorithm.
//!
//! [Raft]: https://raft.github.io/
//!
//! [`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 [`Action`]s that represent pending I/O operations.
//! How to execute these actions is up to the crate user.
//!
//! Except for a few optimizations, `raftbare` 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:
//! ```
//! use raftbare::{Action, Node, NodeId};
//!
//! // Start a node.
//! let mut node = Node::start(NodeId::new(0));
//!
//! // Create a three nodes cluster.
//! let commit_position = node.create_cluster(&[NodeId::new(0), NodeId::new(1), 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 {
//! Action::SetElectionTimeout => { /* ... */ },
//! Action::SaveCurrentTerm => { /* ... */ },
//! Action::SaveVotedFor => { /* ... */ },
//! Action::BroadcastMessage(_) => { /* ... */ },
//! Action::AppendLogEntries(_) => { /* ... */ },
//! Action::SendMessage(_, _) => { /* ... */ },
//! 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);
//! }
//! # break;
//! }
//!
//! // Propose a user-defined command.
//! let commit_position = node.propose_command();
//!
//! // Execute actions as before.
//!
//! # fn is_election_timeout_expired() -> bool { true }
//! # fn try_receive_message() -> Option<raftbare::Message> { None }
//! ```
pub use ;
pub use ClusterConfig;
pub use ;
pub use ;
pub use ;
pub use Role;
/// Term.
;