GoRaft is an implementation of the Raft consensus algorithm written in Go.
The goal of this project is for me to learn Go and become better acquainted with Raft's inner workings. The implementation mostly follows the Raft definition found in In Search of an Understandable Consensus Algorithm by Diego Ongaro and John Ousterhout, though some parts of the code may stray as I play with different ways to get Go to fulfill various functionalities of Raft.
GoRaft depends on the following external packages:
- github.com/boltdb/bolt - To store persistent state
- github.com/go-yaml/yaml - To parse the YAML config file
- github.com/golang/protobuf - To serialize gRPC requests/responses
- github.com/op/go-logging - For leveled logging
- golang.org/x/net/context - For context handling across gRPC requests
- google.golang.org/grpc - To make/receive gRPC requests/responses
This package uses gRPC to send/receive rpc requests between nodes. *.proto files will need to be compiled into Go code using protoc to be usable by gRPC. The executable file generate_protobuf.sh runs the necessary commands to compile all *.proto files.
To install GoRaft, first install Go and then run "go get":
$ go get github.com/thomasylee/GoRaft
Configurations can be found in config.yaml. The details of each configuration is explained in the comments above the relevant key-value pairs.
$ go test -cover -v ./...
Run using "go run" from the source directory, or run "go run" on the main.go file itself:
$ go run main.go
For now, the send_test_append_entries.go program can be used to append new entries to the node logs. It must be edited before being run to include the correct request values.
# Rename, since two files with main() methods will break the test setup.
mv send_test_append_entries.go2 send_test_append_entries.go
go run send_test_append_entries.go
The inspect_bolt.go file can be used to alter and inspect Bolt database files.
# Rename, since two files with main() methods will break the test setup.
mv run inspect_bolt.go2 inspect_bolt.go
go run inspect_bolt.go