This repository contains an educational implementation of the Raft Consensus Algorithm in Go.
| Feature | Implemented |
|---|---|
| Log Replication | Yes |
| Leader Election | Yes |
| Persistence | Yes |
| Membership Changes | No |
| Log Compaction | No |
- Format:
go run kv/bin/main.go --id {node server id} --kvaddr {key-value server address}- Example, running all the nodes listed in the configuration file
config.go:
Process#0
go run kv/bin/main.go --id 0 --kvaddr localhost:27004Process#1
go run kv/bin/main.go --id 1 --kvaddr localhost:27005Process#2
go run kv/bin/main.go --id 2 --kvaddr localhost:27006Client
curl http://localhost:27006/set?key=a&val=b
> set value
curl http://localhost:27006/get?key=a
> bkey-value and raft servers are running under the same process
server.go- main partMakefile- compiles protokv/bin/state#{id}.json- persistent state of a node with id {id} (generated after running main.go)kv/bin/main.go- starts raft and key-value API serversconfig.go- config of the raft cluster in the following way:
var Cluster = []ServerConfig{
{Id: 0, Address: "localhost:8080"},
}time.go- all raft time constants multiplied by slow coefficient in the following way:
const (
slowCoeff = 10
DefaultElectionTimeout = slowCoeff * 150 * time.Millisecond
...
)- Require further validation to ensure the implementation's correctness