Raft Consensus Algorithm implementation in Scala. This is pretty much still Work in progress.
Implemented features:
- Leader election
- Log replication (pluggable with a sample implementation)
- Persistence (pluggable with a sample implementation)
- Membership changes
A sample node initialization and a persistent log store is under opt/node-template
There are several modules currently implemented under the mod
directory:
lib-trabica-model
Data models for node states and auxiliary datalib-trabica-net
Abstraction for client and server networkinglib-trabica-node
Core Raft implementationlib-trabica-proto
Protobuf model of client and server messageslib-trabica-rpc
Protobuf service specification, along client and server endpoint factorieslib-trabica-store
Abstraction for pluggable Log store, a sample implementation is underopt/node-template
The code uses cats-effect and fs2 extensively.
It is possible to build both a JVM and a native application. From SBT prompt run project node-template
, then:
stage
for a JVM build, ornative
for a native image build
Several shell scripts can be found under bin
to start and experiment with a cluster, if you are initializing
a new cluster, start with bin/bootstrap-00.sh
. This will start a new cluster with a fresh log store, and
expects 2 other nodes to join. bin/node-{n}.sh
will start instances of the node in follower mode, where n
is the node id.
To test membership changes, see the scripts under etc
. Those scripts use grpcurl
to send gRPC requests.
Configuration of election and RPC timeouts is under mod/lib-trabica-node/src/main/resources/reference.conf
, which you
can override in opt/node-template/src/main/resources/application.conf
If you start the example node with the default scripts under bin
, logs are written under var/{n}
directory, where n
is the node id.
- The store implementation is just an example, a more robust store is needed in production situations
- A call to
RemoveServer
will aggressively send a termination signal to this server if removal was successful, which will terminate the node process - Delivering (applying) messages to the FSM is not implemented yet