All Projects → Jille → raft-grpc-example

Jille / raft-grpc-example

Licence: Unlicense license
Example code for how to get hashicorp/raft running with gRPC

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to raft-grpc-example

nebula
A distributed, fast open-source graph database featuring horizontal scalability and high availability
Stars: ✭ 8,196 (+9774.7%)
Mutual labels:  raft
distmq
Distributed Message Queue based on Raft
Stars: ✭ 32 (-61.45%)
Mutual labels:  raft
little-raft
The lightest distributed consensus library. Run your own replicated state machine! ❤️
Stars: ✭ 316 (+280.72%)
Mutual labels:  raft
go-distsys
Distributed Systems programming examples in the Go programming language.
Stars: ✭ 101 (+21.69%)
Mutual labels:  grpc-go
Raft-Paxos-Sample
MIT6.824实现分布式一致性算法——Raft&Paxos
Stars: ✭ 37 (-55.42%)
Mutual labels:  raft
kshaka
Kshaka is a Go implementation of the CASPaxos consensus protocol.
Stars: ✭ 23 (-72.29%)
Mutual labels:  raft
blockchain consensus algorithm
代码实现五种区块链共识算法 The code implements five blockchain consensus algorithms
Stars: ✭ 251 (+202.41%)
Mutual labels:  raft
Go-gRPC-RabbitMQ-microservice
Go gRPC RabbitMQ email microservice
Stars: ✭ 107 (+28.92%)
Mutual labels:  grpc-go
engine
Online 4X Grand Strategy RPG Engine
Stars: ✭ 19 (-77.11%)
Mutual labels:  grpc-go
mmqtt
An Open-Source, Distributed MQTT Broker for IoT.
Stars: ✭ 58 (-30.12%)
Mutual labels:  raft
dubbo-go-pixiu
Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
Stars: ✭ 385 (+363.86%)
Mutual labels:  grpc-go
dledger
A raft-based java library for building high-available, high-durable, strong-consistent commitlog.
Stars: ✭ 615 (+640.96%)
Mutual labels:  raft
raftor
Distributed chat system built with rust
Stars: ✭ 31 (-62.65%)
Mutual labels:  raft
Distributed-Algorithms
利用 Go 语言实现多种分布式算法
Stars: ✭ 53 (-36.14%)
Mutual labels:  raft
huffleraft
Replicated key-value store driven by the raft consensus protocol 🚵
Stars: ✭ 32 (-61.45%)
Mutual labels:  raft
nebula-graph
A distributed, fast open-source graph database featuring horizontal scalability and high availability. This is an archived repo for v2.5 only, from 2.6.0 +, NebulaGraph switched back to https://github.com/vesoft-inc/nebula
Stars: ✭ 833 (+903.61%)
Mutual labels:  raft
paper
Computer Foundations Practices
Stars: ✭ 17 (-79.52%)
Mutual labels:  raft
savetheworldwithgo
Build systems with Go examples
Stars: ✭ 81 (-2.41%)
Mutual labels:  grpc-go
MIT6.824-2021
4 labs + 2 challenges + 4 docs
Stars: ✭ 594 (+615.66%)
Mutual labels:  raft
console-chat
Chat on your terminal with other users through a gRPC service
Stars: ✭ 21 (-74.7%)
Mutual labels:  grpc-go

raft-grpc-example

This is some example code for how to use Hashicorp's Raft implementation with gRPC.

Start your own cluster

$ mkdir /tmp/my-raft-cluster
$ mkdir /tmp/my-raft-cluster/node{A,B,C}
$ ./raft-grpc-example --raft_bootstrap --raft_id=nodeA --address=localhost:50051 --raft_data_dir /tmp/my-raft-cluster
$ ./raft-grpc-example --raft_id=nodeB --address=localhost:50052 --raft_data_dir /tmp/my-raft-cluster
$ ./raft-grpc-example --raft_id=nodeC --address=localhost:50053 --raft_data_dir /tmp/my-raft-cluster
$ go get github.com/Jille/raftadmin
$ raftadmin localhost:50051 add_voter nodeB localhost:50052 0
$ raftadmin --leader multi:///localhost:50051,localhost:50052 add_voter nodeC localhost:50053 0
$ go run cmd/hammer/hammer.go &
$ raftadmin --leader multi:///localhost:50051,localhost:50052,localhost:50053 leadership_transfer
$ wait

You start up three nodes, and bootstrap one of them. Then you tell the bootstrapped node where to find peers. Those peers sync up to the state of the bootstrapped node and become members of the cluster. Once your cluster is running, you never need to pass --raft_bootstrap again.

raftadmin is used to communicate with the cluster and add the other nodes.

This example uses Jille/raft-grpc-transport to communicate between nodes using gRPC.

This example uses Jille/raft-grpc-leader-rpc to send RPCs to the leader.

Hammer is a client that connects to your raft cluster and sends a bunch of requests. Trigger some leadership failovers to show that it's unaffected.

What's what

Raft uses logs to synchronize changes. Every change submitted to a Raft cluster is a log entry, which gets stored and replicated to the followers in the cluster. In this example, we use raft-boltdb to store these logs. Once in a while Raft decides the logs have grown too large, and makes a snapshot. Your code is asked to write out its state. That state captures all previous logs. Now Raft can delete all the old logs and just use the snapshot. These snapshots are stored using the FileSnapshotStore, which means they'll just be files in your disk. Raft also needs a way to talk to other nodes, that's called a Transport. This example uses Jille/raft-grpc-transport to communicate between nodes using gRPC.

You can see all this happening in NewRaft() in main.go.

Your application

See application.go. You'll need to implement a raft.FSM, and you probably want a gRPC RPC interface.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].