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-modelData models for node states and auxiliary datalib-trabica-netAbstraction for client and server networkinglib-trabica-nodeCore Raft implementationlib-trabica-protoProtobuf model of client and server messageslib-trabica-rpcProtobuf service specification, along client and server endpoint factorieslib-trabica-storeAbstraction 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:
stagefor a JVM build, ornativefor 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
RemoveServerwill 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