raft
raft copied to clipboard
Raft protocol implementation in C
libraft
Raft protocol implementation in C.
Features
- Leader Election
- Log Replication
- Log Compaction
Usage
-
Include raft.h and link with -lraft
-
Initialize: a. Populate a
raft_config_twith parameters (host, port, timeouts, log length, etc.)b. Set an applier and a snapshooter callbacks. The applier should perform state modification, and the snapshooter should dump the state. See raft.h for their signatures.
c. Call raft_init(cfg).
d. Use raft_peer_up(...) to configure the peers, including the current one.
e. Create and bind the socket with raft_create_udp_socket(...).
-
Serve raft: a. Call raft_tick(...) frequently to perform the logic of timeouts.
b. Try to extract a message with raft_recv_message(...) when you believe there is one in the socket.
c. Call raft_handle_message(...) when a message has been successfully extracted from the socket.
-
Serve clients: a. If this server is a leader (call raft_get_leader(...) to find out), then it should accept pending connections and process client quieries.
b. Use raft_emit(...) to update the state though raft. Then wait until raft_applied(...) before returning the result to the client.
c. You may use raft_get_leader(...) to redirect clients to the leader, though this is not necessary.
Please read raft.h and example/ for more details.
Testing
- Install docker and blockade.
- You may want to gain superuser privileges at this point.
- $ make check
TODO
- Membership Changes