Documentation ¶
Overview ¶
Package kvdb provides a key-value database with Checkpoints & Resets system
Index ¶
- Constants
- Variables
- func PebbleMakeCheckpoint(source, dest string) error
- type Config
- type KVDB
- func (k *KVDB) CheckpointExists(batchNum common.BatchNum) (bool, error)
- func (k *KVDB) Close()
- func (k *KVDB) DB() *pebble.Storage
- func (k *KVDB) DeleteCheckpoint(batchNum common.BatchNum) error
- func (k *KVDB) DeleteOldCheckpoints() error
- func (k *KVDB) GetCurrentBatch() (common.BatchNum, error)
- func (k *KVDB) GetCurrentIdx() (common.Idx, error)
- func (k *KVDB) LastRead(fn func(db *pebble.Storage) error) error
- func (k *KVDB) ListCheckpoints() ([]int, error)
- func (k *KVDB) MakeCheckpoint() error
- func (k *KVDB) MakeCheckpointFromTo(fromBatchNum common.BatchNum, dest string) error
- func (k *KVDB) Reset(batchNum common.BatchNum) error
- func (k *KVDB) ResetFromSynchronizer(batchNum common.BatchNum, synchronizerKVDB *KVDB) error
- func (k *KVDB) SetCurrentIdx(idx common.Idx) error
- func (k *KVDB) StorageWithPrefix(prefix []byte) db.Storage
- type Last
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
CheckpointExists returns true if the checkpoint exists
func (*KVDB) DeleteCheckpoint ¶
DeleteCheckpoint removes if exist the checkpoint of the given batchNum
func (*KVDB) DeleteOldCheckpoints ¶ added in v1.1.0
DeleteOldCheckpoints deletes old checkpoints when there are more than `s.keep` checkpoints
func (*KVDB) GetCurrentBatch ¶
GetCurrentBatch returns the current BatchNum stored in the KVDB
func (*KVDB) GetCurrentIdx ¶
GetCurrentIdx returns the stored Idx from the KVDB, which is the last Idx used for an Account in the k.
func (*KVDB) ListCheckpoints ¶
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 ¶
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 ¶
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 ¶
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 ¶
ResetFromSynchronizer performs a reset in the KVDB getting the state from synchronizerKVDB for the given batchNum.
func (*KVDB) SetCurrentIdx ¶
SetCurrentIdx stores Idx in the KVDB