badgerstore

package
v0.2.26 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MIT Imports: 9 Imported by: 0

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")
	ErrNotAbleToAcquireLock = errors.New("Not able to acquire a lock")
	ErrNotAbleToReleaseLock = errors.New("Not able to release a lock")
)

Functions

func DecodeMsgPack added in v0.2.17

func DecodeMsgPack(buf []byte, out interface{}) error

Decode reverses the encode operation on a byte slice input

func EncodeMsgPack added in v0.2.17

func EncodeMsgPack(in interface{}, useNewTimeFormat bool) (*bytes.Buffer, error)

Encode writes an encoded object to a new bytes buffer

func End

func End(prefix []byte) []byte

Copy the prefix into a new slice that is one larger than the prefix and add an `0xFF` byte to it so

Types

type BadgerStore

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

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

func New

func New(logger *logrus.Logger, options Options) (*BadgerStore, error)

New uses the supplied options to open the Badger and prepare it for use as a raft backend.

func NewBadgerStore

func NewBadgerStore(logger *logrus.Logger, path string) (*BadgerStore, error)

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

func (*BadgerStore) Acquire added in v0.2.1

func (b *BadgerStore) Acquire(k []byte, expireAt time.Time) error

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

func (*BadgerStore) Close

func (b *BadgerStore) Close() error

Close is used to gracefully close the DB connection.

func (*BadgerStore) CopyLogs added in v0.2.17

func (b *BadgerStore) CopyLogs(w io.Writer) error

func (*BadgerStore) DBPath added in v0.2.1

func (b *BadgerStore) DBPath() string

DBPath returns a path to a DB file

func (*BadgerStore) DeleteRange

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

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

func (*BadgerStore) FirstIndex

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

FirstIndex returns the first known index from the Raft log.

func (*BadgerStore) Get

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

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

func (*BadgerStore) GetLog

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

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

func (*BadgerStore) GetUint64

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

GetUint64 is like Get, but handles uint64 values

func (*BadgerStore) LastIndex

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

LastIndex returns the last known index from the Raft log.

func (*BadgerStore) Locks added in v0.2.2

func (b *BadgerStore) Locks() []string

func (*BadgerStore) Release added in v0.2.1

func (b *BadgerStore) Release(k []byte) error

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

func (*BadgerStore) RunValueLogGC added in v0.2.2

func (b *BadgerStore) RunValueLogGC(discardRatio float64) error

func (*BadgerStore) Set

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

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

func (*BadgerStore) SetUint64

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

SetUint64 is like Set, but handles uint64 values

func (*BadgerStore) Size added in v0.2.2

func (b *BadgerStore) Size() (lsm, vlog int64)

func (*BadgerStore) StoreLog

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

StoreLog is used to store a single raft log

func (*BadgerStore) StoreLogs

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

StoreLogs is used to store a set of raft logs

type Options

type Options struct {
	// Path is the file path to the Badger to use
	Path string

	// NoSync causes the database to skip fsync calls after each
	// write to the log. This is unsafe, so it should be used
	// with caution.
	NoSync bool

	// MsgpackUseNewTimeFormat when set to true, force the underlying msgpack
	// codec to use the new format of time.Time when encoding (used in
	// go-msgpack v1.1.5 by default). Decoding is not affected, as all
	// go-msgpack v2.1.0+ decoders know how to decode both formats.
	MsgpackUseNewTimeFormat bool
	// contains filtered or unexported fields
}

Options contains all the configuration used to open the Badger

type Store added in v0.2.18

type Store interface {
	Close() error
	FirstIndex() (uint64, error)
	LastIndex() (uint64, error)
	GetLog(idx uint64, log *raft.Log) error
	StoreLog(log *raft.Log) error
	StoreLogs(logs []*raft.Log) error
	DeleteRange(min, max uint64) error
	CopyLogs(w io.Writer) error
	Set(k, v []byte) error
	Get(k []byte) ([]byte, error)
	Acquire(k []byte, expireAt time.Time) error
	Release(k []byte) error
	SetUint64(key []byte, val uint64) error
	GetUint64(key []byte) (uint64, error)
	DBPath() string
	RunValueLogGC(discardRatio float64) error
	Size() (lsm, vlog int64)
	Locks() []string
}

Jump to

Keyboard shortcuts

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