raftboltdb

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

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

Go to latest
Published: Dec 11, 2023 License: MPL-2.0 Imports: 9 Imported by: 592

README

raft-boltdb

This repository provides the raftboltdb package. The package exports the BoltStore 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 BoltDB. BoltDB is a simple key/value store implemented in pure Go, and inspired by LMDB.

Metrics

The raft-boldb library emits a number of metrics utilizing github.com/armon/go-metrics. Those metrics are detailed in the following table. One note is that the application which pulls in this library may add its own prefix to the metric names. For example within Consul, the metrics will be prefixed with consul..

Metric Unit Type Description
raft.boltdb.freelistBytes bytes gauge Represents the number of bytes necessary to encode the freelist metadata. When raft_boltdb.NoFreelistSync is set to false these metadata bytes must also be written to disk for each committed log.
raft.boltdb.freePageBytes bytes gauge Represents the number of bytes of free space within the raft.db file.
raft.boltdb.getLog ms timer Measures the amount of time spent reading logs from the db.
raft.boltdb.logBatchSize bytes sample Measures the total size in bytes of logs being written to the db in a single batch.
raft.boltdb.logsPerBatch logs sample Measures the number of logs being written per batch to the db.
raft.boltdb.logSize bytes sample Measures the size of logs being written to the db.
raft.boltdb.numFreePages pages gauge Represents the number of free pages within the raft.db file.
raft.boltdb.numPendingPages pages gauge Represents the number of pending pages within the raft.db that will soon become free.
raft.boltdb.openReadTxn transactions gauge Represents the number of open read transactions against the db
raft.boltdb.storeLogs ms timer Measures the amount of time spent writing logs to the db.
raft.boltdb.totalReadTxn transactions gauge Represents the total number of started read transactions against the db
raft.boltdb.txstats.cursorCount cursors counter Counts the number of cursors created since Consul was started.
raft.boltdb.txstats.nodeCount allocations counter Counts the number of node allocations within the db since Consul was started.
raft.boltdb.txstats.nodeDeref dereferences counter Counts the number of node dereferences in the db since Consul was started.
raft.boltdb.txstats.pageAlloc bytes gauge Represents the number of bytes allocated within the db since Consul was started. Note that this does not take into account space having been freed and reused. In that case, the value of this metric will still increase.
raft.boltdb.txstats.pageCount pages gauge Represents the number of pages allocated since Consul was started. Note that this does not take into account space having been freed and reused. In that case, the value of this metric will still increase.
raft.boltdb.txstats.rebalance rebalances counter Counts the number of node rebalances performed in the db since Consul was started.
raft.boltdb.txstats.rebalanceTime ms timer Measures the time spent rebalancing nodes in the db.
raft.boltdb.txstats.spill spills counter Counts the number of nodes spilled in the db since Consul was started.
raft.boltdb.txstats.spillTime ms timer Measures the time spent spilling nodes in the db.
raft.boltdb.txstats.split splits counter Counts the number of nodes split in the db since Consul was started.
raft.boltdb.txstats.write writes counter Counts the number of writes to the db since Consul was started.
raft.boltdb.txstats.writeTime ms timer Measures the amount of time spent performing writes to the db.
raft.boltdb.writeCapacity logs/second sample Theoretical write capacity in terms of the number of logs that can be written per second. Each sample outputs what the capacity would be if future batched log write operations were similar to this one. This similarity encompasses 4 things: batch size, byte size, disk performance and boltdb performance. While none of these will be static and its highly likely individual samples of this metric will vary, aggregating this metric over a larger time window should provide a decent picture into how this BoltDB store can perform

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 BoltStore

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

BoltStore provides access to BoltDB 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(options Options) (*BoltStore, error)

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

func NewBoltStore

func NewBoltStore(path string) (*BoltStore, error)

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

func (*BoltStore) Close

func (b *BoltStore) Close() error

Close is used to gracefully close the DB connection.

func (*BoltStore) DeleteRange

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

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

func (*BoltStore) FirstIndex

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

FirstIndex returns the first known index from the Raft log.

func (*BoltStore) Get

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

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

func (*BoltStore) GetLog

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

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

func (*BoltStore) GetUint64

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

GetUint64 is like Get, but handles uint64 values

func (*BoltStore) LastIndex

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

LastIndex returns the last known index from the Raft log.

func (*BoltStore) RunMetrics

func (b *BoltStore) RunMetrics(ctx context.Context, interval time.Duration)

RunMetrics should be executed in a go routine and will periodically emit metrics on the given interval until the context has been cancelled.

func (*BoltStore) Set

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

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

func (*BoltStore) SetUint64

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

SetUint64 is like Set, but handles uint64 values

func (*BoltStore) StoreLog

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

StoreLog is used to store a single raft log

func (*BoltStore) StoreLogs

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

StoreLogs is used to store a set of raft logs

func (*BoltStore) Sync

func (b *BoltStore) Sync() error

Sync performs an fsync on the database file handle. This is not necessary under normal operation unless NoSync is enabled, in which this forces the database file to sync against the disk.

type Options

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

	// BoltOptions contains any specific BoltDB options you might
	// want to specify [e.g. open timeout]
	BoltOptions *bolt.Options

	// 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
}

Options contains all the configuration used to open the BoltDB

Jump to

Keyboard shortcuts

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