raftfastlog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MPL-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

raft-fastlog

This repository provides the raftfastlog package. The package exports a Raft Store which is an implementation of a LogStore, StableStore, and PeerStore.

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

This implementation is an in-memory database that persists to disk.

RaftStore Performance Comparison

FastLog (This implementation)

BenchmarkBuntStore_FirstIndex-8    20000000           92 ns/op
BenchmarkBuntStore_LastIndex-8     20000000           92 ns/op
BenchmarkBuntStore_GetLog-8        10000000          139 ns/op
BenchmarkBuntStore_StoreLog-8       1000000         2028 ns/op
BenchmarkBuntStore_StoreLogs-8       300000         4507 ns/op
BenchmarkBuntStore_DeleteRange-8    1000000         3164 ns/op
BenchmarkBuntStore_Set-8            1000000         1522 ns/op
BenchmarkBuntStore_Get-8           10000000          119 ns/op
BenchmarkBuntStore_SetUint64-8      1000000         1506 ns/op
BenchmarkBuntStore_GetUint64-8     20000000          117 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 ErrClosed = errors.New("closed")
View Source
var ErrKeyNotFound = errors.New("not found")

An error indicating a given key does not exist

View Source
var ErrShrinking = errors.New("shrink in progress")

Functions

This section is empty.

Types

type FastLogStore

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

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

func NewFastLogStore

func NewFastLogStore(path string, durability Level, logOutput io.Writer) (*FastLogStore, error)

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

func (*FastLogStore) Close

func (b *FastLogStore) Close() error

Close is used to gracefully close the DB connection.

func (*FastLogStore) DeleteRange

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

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

func (*FastLogStore) FirstIndex

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

FirstIndex returns the first known index from the Raft log.

func (*FastLogStore) Get

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

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

func (*FastLogStore) GetLog

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

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

func (*FastLogStore) GetUint64

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

GetUint64 is like Get, but handles uint64 values

func (*FastLogStore) LastIndex

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

LastIndex returns the last known index from the Raft log.

func (*FastLogStore) Set

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

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

func (*FastLogStore) SetUint64

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

SetUint64 is like Set, but handles uint64 values

func (*FastLogStore) Shrink

func (b *FastLogStore) Shrink() error

func (*FastLogStore) StoreLog

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

StoreLog is used to store a single raft log

func (*FastLogStore) StoreLogs

func (b *FastLogStore) 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
⌂ 换网址