raftpebble

package module
v0.0.0-...-6a3a6c2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

README

raft-pebble

This repository provides the raftpebble package. The package exports the PebbleKVStore 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 cockroachdb pebble. pebble is a simple persistent key-value store written in pure Go for adapter cockroachdb. It has a Log-Structured-Merge (LSM) design and it's meant to be a performant alternative to non-Go based stores like RocksDB.

bench Pebble vs Badger

bench with BBVA/raft-badger, run go test -run=NONE -benchmem -bench=. ./... to diff bench result, below just simple bench on macOS, more bench please test on product env machine (use SATA/NVMe SSD, think Compression and sync w, use diff k/v dataset, w/r mode)

goos: darwin
goarch: amd64
pkg: github.com/BBVA/raft-badger
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkBadgerStore_FirstIndex-8         558468              1893 ns/op            1005 B/op         17 allocs/op
BenchmarkBadgerStore_LastIndex-8          476727              2329 ns/op             991 B/op         17 allocs/op
BenchmarkBadgerStore_GetLog-8             260952              4269 ns/op            1780 B/op         43 allocs/op
BenchmarkBadgerStore_StoreLog-8            55231             21848 ns/op            4816 B/op         65 allocs/op
BenchmarkBadgerStore_StoreLogs-8           31244             37265 ns/op           10133 B/op        139 allocs/op
BenchmarkBadgerStore_DeleteRange-8         50634             23891 ns/op            4609 B/op         89 allocs/op
BenchmarkBadgerStore_Set-8                 77796             14079 ns/op            2675 B/op         41 allocs/op
BenchmarkBadgerStore_Get-8                652993              1546 ns/op             451 B/op         12 allocs/op
BenchmarkBadgerStore_SetUint64-8           75255             14539 ns/op            2729 B/op         41 allocs/op
BenchmarkBadgerStore_GetUint64-8          775291              1621 ns/op             449 B/op         12 allocs/op
BenchmarkSet-8                             77793             13437 ns/op            2703 B/op         40 allocs/op
BenchmarkGet-8                            554457              2234 ns/op             560 B/op         13 allocs/op
BenchmarkStoreLogs-8                       59142             20193 ns/op            4690 B/op         64 allocs/op
BenchmarkGetLog-8                         259209              4268 ns/op            1740 B/op         41 allocs/op
goos: darwin
goarch: amd64
pkg: github.com/weedge/raft-pebble
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkPebbleKVStoreStore_FirstIndex-8         1645522               728.4 ns/op             8 B/op          1 allocs/op
BenchmarkPebbleKVStoreStore_LastIndex-8          1514397               779.2 ns/op            88 B/op          2 allocs/op
BenchmarkPebbleKVStoreStore_GetLog-8              405542              2603 ns/op            1136 B/op         34 allocs/op
BenchmarkPebbleKVStoreStore_StoreLog-8             89127             12486 ns/op            1489 B/op         27 allocs/op
BenchmarkPebbleKVStoreStore_StoreLogs-8            22774             47654 ns/op            4195 B/op         75 allocs/op
BenchmarkPebbleKVStoreStore_DeleteRange-8         390418              5706 ns/op              89 B/op          3 allocs/op
BenchmarkPebbleKVStoreStore_Set-8                 254138              4334 ns/op              18 B/op          3 allocs/op
BenchmarkPebbleKVStoreStore_Get-8                3295018               382.8 ns/op            16 B/op          2 allocs/op
BenchmarkPebbleKVStoreStore_SetUint64-8           182452              5517 ns/op              20 B/op          2 allocs/op
BenchmarkPebbleKVStoreStore_GetUint64-8          3092731               500.6 ns/op            16 B/op          2 allocs/op
BenchmarkSet-8                                    259359              3996 ns/op              18 B/op          1 allocs/op
BenchmarkGet-8                                   1206459              1020 ns/op              16 B/op          1 allocs/op
BenchmarkStoreLogs-8                              127917              7970 ns/op            1480 B/op         26 allocs/op
BenchmarkGetLog-8                                 364390              3033 ns/op             784 B/op         29 allocs/op

pebble have more better ops on raft log store case. more prioritization feature vs rocksdb diff see pebble-rocksdb-kv-store

references

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrKeyNotFound is an error indicating a given key does not exist
	// for hashicorp raft vote meta stable get check, if err != nil && err.Error() != "not found"
	ErrKeyNotFound = errors.New("not found")
)

Functions

func FirstError

func FirstError(err1 error, err2 error) error

FirstError returns the first error.

Types

type LogDBCallback

type LogDBCallback func(busy bool)

LogDBCallback is a callback function called by the LogDB eg: do some metrics export

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithConfig

func WithConfig(config RaftLogRocksDBConfig) Option

func WithDbDirPath

func WithDbDirPath(dbDir string) Option

func WithFS

func WithFS(fs vfs.FS) Option

func WithLogDBCallback

func WithLogDBCallback(cb LogDBCallback) Option

func WithLogger

func WithLogger(logger pebble.Logger) Option

func WithPebbleOptions

func WithPebbleOptions(opts *pebble.Options) Option

func WithWalDirPath

func WithWalDirPath(walDir string) Option

type PebbleKVStore

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

KV is a pebble based LogStore StableStore type.

func New

func New(options ...Option) (*PebbleKVStore, error)

New uses the supplied config to open the Pebble db and prepare it for using as a raft backend pebble kv store. level no compression for raft meta/log store

func (*PebbleKVStore) Close

func (s *PebbleKVStore) Close() error

Close the Raft log

func (*PebbleKVStore) DeleteRange

func (s *PebbleKVStore) DeleteRange(min, max uint64) (err error)

DeleteRange deletes logs within a given range inclusively.

func (*PebbleKVStore) FirstIndex

func (s *PebbleKVStore) FirstIndex() (first uint64, err error)

FirstIndex returns the first known index from the Raft log. use SeekPrefixGE,Reverse iteration (Prev) is not supported when an iterator is in prefix iteration mode. https://pkg.go.dev/github.com/cockroachdb/pebble#Iterator.SeekPrefixGE so use lowerBound,UpperBound for iter prefixLog notice: if not found return 0, nil

func (*PebbleKVStore) Get

func (s *PebbleKVStore) Get(key []byte) (value []byte, err error)

Get is used to retrieve a value from the k/v store by key notice: if key/val not found return ErrKeyNotFound

func (*PebbleKVStore) GetLog

func (s *PebbleKVStore) GetLog(index uint64, log *raft.Log) (err error)

GetLog gets a log entry from Pebble at a given index. notice: if index log not found return raft ErrLogNotFound

func (*PebbleKVStore) GetUint64

func (s *PebbleKVStore) GetUint64(key []byte) (uint64, error)

GetUint64 is like Get, but return uint64 values

func (*PebbleKVStore) LastIndex

func (s *PebbleKVStore) LastIndex() (last uint64, err error)

LastIndex returns the last known index from the Raft log. use SeekPrefixGE,Reverse iteration (Prev) is not supported when an iterator is in prefix iteration mode. https://pkg.go.dev/github.com/cockroachdb/pebble#Iterator.SeekPrefixGE so use lowerBound,UpperBound for iter prefixLog notice: if not found return 0, nil

func (*PebbleKVStore) Set

func (s *PebbleKVStore) Set(key []byte, val []byte) (err error)

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

func (*PebbleKVStore) SetUint64

func (s *PebbleKVStore) SetUint64(key []byte, val uint64) error

SetUint64 is like Set, but handles uint64 values

func (*PebbleKVStore) StoreLog

func (s *PebbleKVStore) StoreLog(log *raft.Log) (err error)

StoreLog stores a single raft log.

func (*PebbleKVStore) StoreLogs

func (s *PebbleKVStore) StoreLogs(logs []*raft.Log) (err error)

StoreLogs stores a set of raft logs.

type RaftLogRocksDBConfig

type RaftLogRocksDBConfig struct {
	Shards                             uint64
	KVKeepLogFileNum                   uint64
	KVMaxBackgroundCompactions         uint64
	KVMaxBackgroundFlushes             uint64
	KVLRUCacheSize                     uint64
	KVWriteBufferSize                  uint64
	KVMaxWriteBufferNumber             uint64
	KVLevel0FileNumCompactionTrigger   uint64
	KVLevel0SlowdownWritesTrigger      uint64
	KVLevel0StopWritesTrigger          uint64
	KVMaxBytesForLevelBase             uint64
	KVMaxBytesForLevelMultiplier       uint64
	KVTargetFileSizeBase               uint64
	KVTargetFileSizeMultiplier         uint64
	KVLevelCompactionDynamicLevelBytes uint64
	KVRecycleLogFileNum                uint64
	KVNumOfLevels                      uint64
	KVBlockSize                        uint64
	SaveBufferSize                     uint64
	MaxSaveBufferSize                  uint64
}

RaftLogRocksDBConfig pebble add sst block lru cache for read others more detail see rocksdb guid wiki

func GetDefaultRaftLogRocksDBConfig

func GetDefaultRaftLogRocksDBConfig() RaftLogRocksDBConfig

GetDefaultRaftLogRocksDBConfig returns the default configurations for the LogDB storage engine. The default LogDB configuration use up to 8GBytes memory.

func GetLargeMemRaftLogRocksDBConfig

func GetLargeMemRaftLogRocksDBConfig() RaftLogRocksDBConfig

GetLargeMemRaftLogRocksDBConfig returns a LogDB config aimed to keep memory size to be large for good I/O performance. It is the default setting used by the system. When using the returned config, LogDB takes up to 8GBytes memory.

func GetMediumMemRaftLogRocksDBConfig

func GetMediumMemRaftLogRocksDBConfig() RaftLogRocksDBConfig

GetMediumMemRaftLogRocksDBConfig returns a LogDB config aimed to keep memory size at medium level. When using the returned config, LogDB takes up to 4GBytes memory.

func GetSmallMemRaftLogRocksDBConfig

func GetSmallMemRaftLogRocksDBConfig() RaftLogRocksDBConfig

GetSmallMemRaftLogRocksDBConfig returns a LogDB config aimed to keep memory size at low level. When using the returned config, LogDB takes up to 1GBytes memory.

func GetTinyMemRaftLogRocksDBConfig

func GetTinyMemRaftLogRocksDBConfig() RaftLogRocksDBConfig

GetTinyMemRaftLogRocksDBConfig returns a LogDB config aimed for minimizing memory size. When using the returned config, LogDB takes up to 256MBytes memory.

func (*RaftLogRocksDBConfig) IsEmpty

func (cfg *RaftLogRocksDBConfig) IsEmpty() bool

IsEmpty returns a boolean value indicating whether the RaftLogRocksDBConfig instance is empty.

func (*RaftLogRocksDBConfig) MemorySizeMB

func (cfg *RaftLogRocksDBConfig) MemorySizeMB() uint64

MemorySizeMB returns the estimated upper bound memory size used by the LogDB storage engine. The returned value is in MBytes.

Jump to

Keyboard shortcuts

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