Home

Awesome

raft-badger

CircleCI Go Report Card Maintainability codecov.io Code Coverage HitCount GoDoc

Raft + Badger backend plugin

This repository provides a storage backend for the excellent raft package from Hashicorp. Raft is a distributed consensus protocol. Distributed consensus has many practical applications, ranging from fault-tolerant databases to clock synchronization to things like Google's PageRank.

This package exports the BadgerStore, which is an implementation of both a LogStore and StableStore (interfaces used by the raft package for reading/writing logs as part of its consensus protocol).

installation

go get -u github.com/markthethomas/raft-badger

usage

Create a new BadgerStore and pass it to Raft when setting up.

//...
var logStore raft.LogStore
var stableStore raft.StableStore
myPath  := filepath.Join(s.RaftDir) // replace this with what you're actually using
badgerDB, err := raftbadgerdb.NewBadgerStore(myPath)
if err != nil {
  return fmt.Errorf("error creating new badger store: %s", err)
}
logStore = badgerDB
stableStore = badgerDB

r, err := raft.NewRaft(config, (*fsm)(s), logStore, stableStore, snapshots, transport)
//...

developing

To run tests, run:

go test -cover -coverprofile=coverage.out .

To view coverage, run:

go tool cover -html=coverage.out

To run the benchmark, run:

go test -race -bench .

motivation

This package is meant to be used with the raft package from Hashicorb. This package borrows heavily from the excellent raft-boltdb package, also from Hashicorp. I wanted to learn about Badger and similar tools and needed to use Raft + a durable backend.

misc.

todo