Categorygithub.com/devMYC/raft
repositorypackage
0.0.0-20211203212508-2868bd0c74fd
Repository: https://github.com/devmyc/raft.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

This implementation is used to learn/understand the Raft consensus algorithm. The code implements the behaviors shown in Figure 2 of the Raft paper with no log persistence.

The servers in the cluster communicate with each other via grpc calls. Make sure protobuf compiler is installed.

Also, we need Go plugins for the protobuf compiler

$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]

Update PATH so protoc can find the plugins

$ export PATH="$PATH:$(go env GOPATH)/bin"

Generate gRPC stubs from .proto definition file using the following command

$ protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    proto/raft.proto

The docker-compose.yml file will create a Raft cluster with 3 nodes.

$ docker-compose build
$ docker-compose up -d

After a leader is elected, we can then send requests to the leader node using client/client.go.

NOTE: the X in a port shown in the commands should be replaced by the node's ID. (i.e. 8081 for node1)

$ go run client.go -server <dockerHostIP:808X> -command <string>

There's also an http server running in each container that can be queried to modify iptables rules.

$ curl -i http://dockerHostIP:909X/block    # isolate a node from the cluster
$ curl -i http://dockerHostIP:909X/unblock  # reconnect a node with the cluster

To stop the containers and clean up everything, run

$ docker-compose down
$ make clean