kvdb

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package kvdb provides a key-value database with Checkpoints & Resets system

Index

Constants

View Source
const (
	// PathBatchNum defines the subpath of the Batch Checkpoint in the
	// subpath of the KVDB
	PathBatchNum = "BatchNum"
	// PathCurrent defines the subpath of the current Batch in the subpath
	// of the KVDB
	PathCurrent = "current"
	// PathLast defines the subpath of the last Batch in the subpath
	// of the StateDB
	PathLast = "last"
	// DefaultKeep is the default value for the Keep parameter
	DefaultKeep = 128
)

Variables

View Source
var (
	// KeyCurrentBatch is used as key in the db to store the current BatchNum
	KeyCurrentBatch = []byte("k:currentbatch")

	// ErrNoLast is returned when the KVDB has been configured to not have
	// a Last checkpoint but a Last method is used
	ErrNoLast = fmt.Errorf("no last checkpoint")
)

Functions

func PebbleMakeCheckpoint

func PebbleMakeCheckpoint(source, dest string) error

PebbleMakeCheckpoint is a hepler function to make a pebble checkpoint from source to dest.

Types

type Config

type Config struct {
	// Path where the checkpoints will be stored
	Path string
	// Keep is the number of old checkpoints to keep.  If 0, all
	// checkpoints are kept.
	Keep int
	// At every checkpoint, check that there are no gaps between the
	// checkpoints
	NoGapsCheck bool
	// NoLast skips having an opened DB with a checkpoint to the last
	// batchNum for thread-safe reads.
	NoLast bool
}

Config of the KVDB

type KVDB

type KVDB struct {

	// CurrentIdx holds the current Idx that the BatchBuilder is using
	CurrentIdx   common.Idx
	CurrentBatch common.BatchNum
	// contains filtered or unexported fields
}

KVDB represents the Key-Value DB object

func NewKVDB

func NewKVDB(cfg Config) (*KVDB, error)

NewKVDB creates a new KVDB, allowing to use an in-memory or in-disk storage. Checkpoints older than the value defined by `keep` will be deleted. func NewKVDB(pathDB string, keep int) (*KVDB, error) {

func (*KVDB) CheckpointExists

func (k *KVDB) CheckpointExists(batchNum common.BatchNum) (bool, error)

CheckpointExists returns true if the checkpoint exists

func (*KVDB) Close

func (k *KVDB) Close()

Close the DB

func (*KVDB) DB

func (k *KVDB) DB() *pebble.Storage

DB returns the *pebble.Storage from the KVDB

func (*KVDB) DeleteCheckpoint

func (k *KVDB) DeleteCheckpoint(batchNum common.BatchNum) error

DeleteCheckpoint removes if exist the checkpoint of the given batchNum

func (*KVDB) DeleteOldCheckpoints added in v1.1.0

func (k *KVDB) DeleteOldCheckpoints() error

DeleteOldCheckpoints deletes old checkpoints when there are more than `s.keep` checkpoints

func (*KVDB) GetCurrentBatch

func (k *KVDB) GetCurrentBatch() (common.BatchNum, error)

GetCurrentBatch returns the current BatchNum stored in the KVDB

func (*KVDB) GetCurrentIdx

func (k *KVDB) GetCurrentIdx() (common.Idx, error)

GetCurrentIdx returns the stored Idx from the KVDB, which is the last Idx used for an Account in the k.

func (*KVDB) LastRead

func (k *KVDB) LastRead(fn func(db *pebble.Storage) error) error

LastRead is a thread-safe method to query the last KVDB

func (*KVDB) ListCheckpoints

func (k *KVDB) ListCheckpoints() ([]int, error)

ListCheckpoints returns the list of batchNums of the checkpoints, sorted. If there's a gap between the list of checkpoints, an error is returned.

func (*KVDB) MakeCheckpoint

func (k *KVDB) MakeCheckpoint() error

MakeCheckpoint does a checkpoint at the given batchNum in the defined path. Internally this advances & stores the current BatchNum, and then stores a Checkpoint of the current state of the k.

func (*KVDB) MakeCheckpointFromTo

func (k *KVDB) MakeCheckpointFromTo(fromBatchNum common.BatchNum, dest string) error

MakeCheckpointFromTo makes a checkpoint from the current db at fromBatchNum to the dest folder. This method is locking, so it can be called from multiple places at the same time.

func (*KVDB) Reset

func (k *KVDB) Reset(batchNum common.BatchNum) error

Reset resets the KVDB to the checkpoint at the given batchNum. Reset does not delete the checkpoints between old current and the new current, those checkpoints will remain in the storage, and eventually will be deleted when MakeCheckpoint overwrites them.

func (*KVDB) ResetFromSynchronizer

func (k *KVDB) ResetFromSynchronizer(batchNum common.BatchNum, synchronizerKVDB *KVDB) error

ResetFromSynchronizer performs a reset in the KVDB getting the state from synchronizerKVDB for the given batchNum.

func (*KVDB) SetCurrentIdx

func (k *KVDB) SetCurrentIdx(idx common.Idx) error

SetCurrentIdx stores Idx in the KVDB

func (*KVDB) StorageWithPrefix

func (k *KVDB) StorageWithPrefix(prefix []byte) db.Storage

StorageWithPrefix returns the db.Storage with the given prefix from the current KVDB

type Last

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

Last is a consistent view to the last batch of the stateDB that can be queried concurrently.

Jump to

Keyboard shortcuts

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