struct raft
— Raft server¶
The raft server struct is the central part of C-Raft. It holds and drive the state of a single raft server in a cluster.
Data types¶
-
struct
raft
¶ A single raft server in a cluster.
-
raft_id
¶ Hold the value of a raft server ID. Guaranteed to be at least 64-bit long.
-
void
(*raft_close_cb)
(struct raft *r)¶ Type definition for callback passed to
raft_close()
.
API¶
-
int
raft_init
(struct raft *r, struct raft_io *io, struct raft_fsm *fsm, raft_id id, const char *address)¶ Initialize a raft server object.
-
int
raft_close
(struct raft* r, raft_close_cb cb)¶ Close a raft server object, releasing all used resources.
The memory of the object itself can be released only once the given close callback has been invoked.
-
int
raft_start
(struct raft* r)¶ Start a raft server.
The initial term, vote, snapshot and entries will be loaded from disk using the
raft_io->load()
method. The instance will start as follower, unless it’s the only voting server in the cluster, in which case it will automatically elect itself and become leader.