raftexample
raftexample is an example usage of raft-foiver. It provides a simple REST API for a key-value store cluster backed by the Raft Consensus Algorithm. Inspired by etcd/contrib/raftexample.
Usage
Build
Clone raft-foiver.
cd raftexample
go build -o raftexample
Start a Three-Node Cluster
- Start Cluster
goreman start
- Add Key-Value
curl -L http://127.0.0.1:9999/hello -X POST -d world
- Get Key-Value
curl -L http://127.0.0.1:9999/hello
Fault Tolerance
- Start Cluster and Add Key-Value (hello:world)
goreman start
curl -L http://127.0.0.1:9999/hello -X POST -d world
- Stop a Node and Update Key-Value (hello:foiver)
goreman run stop raftexample3
curl -L http://127.0.0.1:7777/hello -X POST -d foiver
curl -L http://127.0.0.1:7777/hello
- Restart Node and Check Key-Value (hello:foiver)
goreman run start raftexample3
curl -L http://127.0.0.1:9999/hello
Dynamic Cluster Reconfiguration
- Start Three-Node Cluster
goreman start
- Add New Node to Cluster
curl -L http://127.0.0.1:9999/4 -X PUT -d localhost:6000
raftexample --id 4 --addr localhost:6000 --peerids 1,2,3 --peeraddrs localhost:7000,localhost:8000,localhost:9000 --port 6666 --join
- Test Cluster
curl -L http://127.0.0.1:9999/hello -X POST -d world
curl -L http://127.0.0.1:6666/hello
- Remove Node from Cluster
curl -L http://127.0.0.1:9999/2 -X DELETE