storage

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = fmt.Errorf("record not found")

ErrRecordNotFound indicates that a record was not found

Functions

func NewBadgerTMDB

func NewBadgerTMDB(dir string) (tmdb.DB, error)

NewBadgerTMDB creates a tendermint database. If dir is unset, an in-memory tendermint DB is returned

Types

type BadgerStore

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

BadgerStore implements storagetypes.Engine. It provides storage functions built on top of badger.

func NewBadger

func NewBadger(dir string) (*BadgerStore, error)

NewBadger creates an instance of BadgerStore.

func (*BadgerStore) Close

func (b *BadgerStore) Close() error

Close closes the database engine and frees resources

func (*BadgerStore) Closed

func (b *BadgerStore) Closed() bool

Closed checks whether the DB has been closed

func (*BadgerStore) GetDB

func (b *BadgerStore) GetDB() *badger.DB

GetDB get the underlying db

func (*BadgerStore) NewTx

func (b *BadgerStore) NewTx(autoFinish, renew bool) types.Tx

NewTx creates a new transaction.

autoFinish: ensure that the underlying transaction is committed after each successful operation.

renew: re-initializes the transaction after each operation. Requires autoFinish to be enabled.

type Tx

type Tx struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Tx implements types.Tx

func NewTx

func NewTx(db *badger.DB, finish, renew bool) *Tx

NewTx returns an instance of Tx

func (*Tx) CanFinish

func (t *Tx) CanFinish() bool

CanFinish checks whether transaction is automatically committed after every successful operation.

func (*Tx) Commit

func (t *Tx) Commit() error

Commit commits the transaction

func (*Tx) Del

func (t *Tx) Del(key []byte) error

Del deletes a record by key

func (*Tx) Discard

func (t *Tx) Discard()

Discard discards the transaction

func (*Tx) Get

func (t *Tx) Get(key []byte) (*common.Record, error)

Get a record by key

func (*Tx) GetTx

func (t *Tx) GetTx() *badger.Txn

GetTx get the underlying transaction

func (*Tx) Iterate

func (t *Tx) Iterate(prefix []byte, first bool, iterFunc func(rec *common.Record) bool)

Iterate finds a set of records by prefix and passes them to iterFunc for further processing.

If iterFunc returns true, the iterator is stopped and immediately released.

If first is set to true, it begins from the first record, otherwise, it will begin from the last record

func (*Tx) NewBatch

func (t *Tx) NewBatch() interface{}

NewBatch returns a batch writer

func (*Tx) NewTx

func (t *Tx) NewTx(autoFinish, renew bool) types.Tx

NewTx creates a new transaction. autoFinish: ensure that the underlying transaction is committed after each successful operation. renew: reinitialize the transaction after each operation. Requires autoFinish to be enabled.

func (*Tx) Put

func (t *Tx) Put(record *common.Record) error

Put adds a record to the database. It will discard the transaction if an error occurred.

func (*Tx) RawIterator

func (t *Tx) RawIterator(opts interface{}) interface{}

RawIterator returns badger's Iterator

func (*Tx) RenewTx

func (t *Tx) RenewTx()

RenewTx forcefully renews the underlying transaction.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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