raftbuntdb

package module
v0.0.0-...-a00e39f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2020 License: MPL-2.0 Imports: 7 Imported by: 0

README

This project is deprecated. Please see the tidwall/raft-wal project for a more advanced raft log.

raft-buntdb

For a better and faster Raft store please see the raft-fastlog project.

This repository provides the raftbuntdb package. The package exports the BuntStore which is an implementation of both a LogStore and StableStore.

It is meant to be used as a backend for the raft package here.

This implementation uses BuntDB. BuntDB is an in-memory database that persists to disk and is written in pure Go. It includes transactions, is ACID compliant, and is very fast.

RaftStore Performance Comparison

BuntDB (This implementation)

BenchmarkBuntStore_FirstIndex-8     5000000          282 ns/op
BenchmarkBuntStore_LastIndex-8      5000000          276 ns/op
BenchmarkBuntStore_GetLog-8         3000000          577 ns/op
BenchmarkBuntStore_StoreLog-8        500000         3663 ns/op
BenchmarkBuntStore_StoreLogs-8       200000        10149 ns/op
BenchmarkBuntStore_DeleteRange-8     200000         9768 ns/op
BenchmarkBuntStore_Set-8             500000         2843 ns/op
BenchmarkBuntStore_Get-8            3000000          434 ns/op
BenchmarkBuntStore_SetUint64-8       500000         2942 ns/op
BenchmarkBuntStore_GetUint64-8      3000000          430 ns/op

MDB

BenchmarkMDBStore_FirstIndex-8  	 500000	        3043 ns/op
BenchmarkMDBStore_LastIndex-8  	     500000	        2941 ns/op
BenchmarkMDBStore_GetLog-8     	     300000	        4665 ns/op
BenchmarkMDBStore_StoreLog-8   	      10000	      183860 ns/op
BenchmarkMDBStore_StoreLogs-8  	      10000	      193783 ns/op
BenchmarkMDBStore_DeleteRange-8	      10000	      199927 ns/op
BenchmarkMDBStore_Set-8        	      10000	      147540 ns/op
BenchmarkMDBStore_Get-8        	     500000	        2324 ns/op
BenchmarkMDBStore_SetUint64-8  	      10000	      162291 ns/op
BenchmarkMDBStore_GetUint64-8  	    1000000	        2451 ns/op

BoltDB

BenchmarkBoltStore_FirstIndex-8 	2000000 	     848 ns/op
BenchmarkBoltStore_LastIndex-8  	2000000	         857 ns/op
BenchmarkBoltStore_GetLog-8     	 500000	        3169 ns/op
BenchmarkBoltStore_StoreLog-8   	  10000	      197432 ns/op
BenchmarkBoltStore_StoreLogs-8  	  10000	      205238 ns/op
BenchmarkBoltStore_DeleteRange-8	  10000	      189994 ns/op
BenchmarkBoltStore_Set-8        	  10000	      177010 ns/op
BenchmarkBoltStore_Get-8        	2000000	         983 ns/op
BenchmarkBoltStore_SetUint64-8  	  10000	      175435 ns/op
BenchmarkBoltStore_GetUint64-8  	2000000	         976 ns/op

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// An error indicating a given key does not exist
	ErrKeyNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type BuntStore

type BuntStore struct {
	// contains filtered or unexported fields
}

BuntStore provides access to BuntDB for Raft to store and retrieve log entries. It also provides key/value storage, and can be used as a LogStore and StableStore.

func NewBuntStore

func NewBuntStore(path string, durability Level) (*BuntStore, error)

NewBuntStore takes a file path and returns a connected Raft backend.

func (*BuntStore) Close

func (b *BuntStore) Close() error

Close is used to gracefully close the DB connection.

func (*BuntStore) DeleteRange

func (b *BuntStore) DeleteRange(min, max uint64) error

DeleteRange is used to delete logs within a given range inclusively.

func (*BuntStore) FirstIndex

func (b *BuntStore) FirstIndex() (uint64, error)

FirstIndex returns the first known index from the Raft log.

func (*BuntStore) Get

func (b *BuntStore) Get(k []byte) ([]byte, error)

Get is used to retrieve a value from the k/v store by key

func (*BuntStore) GetLog

func (b *BuntStore) GetLog(idx uint64, log *raft.Log) error

GetLog is used to retrieve a log from BuntDB at a given index.

func (*BuntStore) GetUint64

func (b *BuntStore) GetUint64(key []byte) (uint64, error)

GetUint64 is like Get, but handles uint64 values

func (*BuntStore) LastIndex

func (b *BuntStore) LastIndex() (uint64, error)

LastIndex returns the last known index from the Raft log.

func (*BuntStore) Peers

func (b *BuntStore) Peers() ([]string, error)

Peers returns raft peers

func (*BuntStore) Set

func (b *BuntStore) Set(k, v []byte) error

Set is used to set a key/value set outside of the raft log

func (*BuntStore) SetPeers

func (b *BuntStore) SetPeers(peers []string) error

SetPeers sets raft peers

func (*BuntStore) SetUint64

func (b *BuntStore) SetUint64(key []byte, val uint64) error

SetUint64 is like Set, but handles uint64 values

func (*BuntStore) Shrink

func (b *BuntStore) Shrink() error

Shrink will trigger a shrink operation on the aof file. Useful after a log compaction is completed.

func (*BuntStore) StoreLog

func (b *BuntStore) StoreLog(log *raft.Log) error

StoreLog is used to store a single raft log

func (*BuntStore) StoreLogs

func (b *BuntStore) StoreLogs(logs []*raft.Log) error

StoreLogs is used to store a set of raft logs

type Level

type Level int
const (
	Low    Level = -1
	Medium Level = 0
	High   Level = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL