storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package storage contains ledger storage implementation on top of BadgerDB engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound returns if record/index not found in storage.
	ErrNotFound = errors.New("storage object not found")

	// ErrConflictRetriesOver is returned if Update transaction fails on all retry attempts.
	ErrConflictRetriesOver = errors.New("transaction conflict retries limit exceeded")

	// ErrConflict is the alias for badger.ErrConflict.
	ErrConflict = badger.ErrConflict

	// ErrOverride is returned if SetRecord tries update existing record
	ErrOverride = errors.New("records override is forbidden")
)

Functions

This section is empty.

Types

type DB added in v0.0.6

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

DB represents BadgerDB storage implementation.

func NewDB added in v0.0.6

func NewDB(conf configuration.Ledger, opts *badger.Options) (*DB, error)

NewDB returns storage.DB with BadgerDB instance initialized by opts. Creates database in provided dir or in current directory if dir parameter is empty.

func (*DB) BeginTransaction added in v0.0.6

func (db *DB) BeginTransaction(update bool) *TransactionManager

BeginTransaction opens a new transaction. All methods called on returned transaction manager will persist changes only after success on "Commit" call.

func (*DB) Bootstrap added in v0.0.6

func (db *DB) Bootstrap() error

Bootstrap creates initial records in storage.

func (*DB) Close added in v0.0.6

func (db *DB) Close() error

Close wraps BadgerDB Close method.

From https://godoc.org/github.com/dgraph-io/badger#DB.Close: «It's crucial to call it to ensure all the pending updates make their way to disk. Calling DB.Close() multiple times is not safe and wouldcause panic.»

func (*DB) Get added in v0.0.6

func (db *DB) Get(key []byte) ([]byte, error)

Get wraps matching transaction manager method.

func (*DB) GetClassIndex added in v0.0.6

func (db *DB) GetClassIndex(ref *record.Reference) (*index.ClassLifeline, error)

GetClassIndex wraps matching transaction manager method.

func (*DB) GetCurrentPulse added in v0.0.6

func (db *DB) GetCurrentPulse() core.PulseNumber

GetCurrentPulse returns current pulse number.

func (*DB) GetDrop added in v0.0.6

func (db *DB) GetDrop(pulse core.PulseNumber) (*jetdrop.JetDrop, error)

GetDrop returns jet drop for a given pulse number.

func (*DB) GetEntropy added in v0.0.6

func (db *DB) GetEntropy(pulse core.PulseNumber) (*core.Entropy, error)

GetEntropy wraps matching transaction manager method.

func (*DB) GetObjectIndex added in v0.0.6

func (db *DB) GetObjectIndex(ref *record.Reference) (*index.ObjectLifeline, error)

GetObjectIndex wraps matching transaction manager method.

func (*DB) GetRecord added in v0.0.6

func (db *DB) GetRecord(ref *record.Reference) (record.Record, error)

GetRecord wraps matching transaction manager method.

func (*DB) GetSlotHashes added in v0.0.6

func (db *DB) GetSlotHashes(n core.PulseNumber) ([][]byte, error)

GetSlotHashes returns array of all record's hashes in provided PulseNum.

func (*DB) ProcessSlotHashes added in v0.0.6

func (db *DB) ProcessSlotHashes(n core.PulseNumber, ifn func(it HashIterator) error) error

ProcessSlotHashes executes a iteration function ifn and provides HashIterator inside it to iterate over all records hashes with the same record.PulseNum.

Error returned by the ProcessSlotRecords is based on iteration function result or BadgerDB iterator error if any.

func (*DB) RootRef added in v0.0.6

func (db *DB) RootRef() *record.Reference

RootRef returns the root record reference.

Root record is the parent for all top-level records.

func (*DB) Set added in v0.0.6

func (db *DB) Set(key, value []byte) error

Set wraps matching transaction manager method.

func (*DB) SetClassIndex added in v0.0.6

func (db *DB) SetClassIndex(ref *record.Reference, idx *index.ClassLifeline) error

SetClassIndex wraps matching transaction manager method.

func (*DB) SetCurrentPulse added in v0.0.6

func (db *DB) SetCurrentPulse(pulse core.PulseNumber)

SetCurrentPulse sets current pulse number.

func (*DB) SetDrop added in v0.0.6

func (db *DB) SetDrop(pulse core.PulseNumber, prevdrop *jetdrop.JetDrop) (*jetdrop.JetDrop, error)

SetDrop stores jet drop for given pulse number.

Previous JetDrop should be provided. On success returns saved drop hash.

func (*DB) SetEntropy added in v0.0.6

func (db *DB) SetEntropy(pulse core.PulseNumber, entropy core.Entropy) error

SetEntropy wraps matching transaction manager method.

func (*DB) SetObjectIndex added in v0.0.6

func (db *DB) SetObjectIndex(ref *record.Reference, idx *index.ObjectLifeline) error

SetObjectIndex wraps matching transaction manager method.

func (*DB) SetRecord added in v0.0.6

func (db *DB) SetRecord(rec record.Record) (ref *record.Reference, err error)

SetRecord wraps matching transaction manager method.

func (*DB) SetTxRetiries added in v0.0.6

func (db *DB) SetTxRetiries(n int)

SetTxRetiries sets number of retries on conflict in Update

func (*DB) Update added in v0.0.6

func (db *DB) Update(fn func(*TransactionManager) error) error

Update accepts transaction function and commits changes. All calls to received transaction manager will be consistent and written tp disk or an error will be returned.

func (*DB) View added in v0.0.6

func (db *DB) View(fn func(*TransactionManager) error) error

View accepts transaction function. All calls to received transaction manager will be consistent.

type HashIterator added in v0.0.6

type HashIterator interface {
	// Next moves the iterator to the next key/value pair.
	// It returns false then iterator is exhausted.
	Next() bool

	// Hash returns record's hash copy. That allows use returned value
	// on any iteration step or outside of iteration function.
	Hash() []byte

	// ShallowHash returns unsafe record's hash, that could be used only
	// in current iteration step. It could be useful for processing hashes
	// on the fly to avoid unnecessary copy and memory allocations.
	ShallowHash() []byte
}

HashIterator iterates over a database record's hashes. An iterator provides methods for record's hash access.

HashIterator supposed to be used only in functions like ProcessSlotHashes. Any release of iterator resources not needed.

type Store added in v0.0.5

type Store interface {
	GetRecord(ref *record.Reference) (record.Record, error)
	SetRecord(rec record.Record) (*record.Reference, error)
	GetClassIndex(ref *record.Reference) (*index.ClassLifeline, error)
	SetClassIndex(ref *record.Reference, idx *index.ClassLifeline) error
	GetObjectIndex(ref *record.Reference) (*index.ObjectLifeline, error)
	SetObjectIndex(ref *record.Reference, idx *index.ObjectLifeline) error
}

Store is used by context unaware clients who can work inside transactions as well as outside.

type TransactionManager added in v0.0.6

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

TransactionManager is used to ensure persistent writes to disk.

func (*TransactionManager) Commit added in v0.0.6

func (m *TransactionManager) Commit() error

Commit tries to write transaction on disk. Returns error on fail.

func (*TransactionManager) Discard added in v0.0.6

func (m *TransactionManager) Discard()

Discard terminates transaction without disk writes.

func (*TransactionManager) Get added in v0.0.6

func (m *TransactionManager) Get(key []byte) ([]byte, error)

Get returns value by key.

func (*TransactionManager) GetClassIndex added in v0.0.6

func (m *TransactionManager) GetClassIndex(ref *record.Reference) (*index.ClassLifeline, error)

GetClassIndex fetches class lifeline's index.

func (*TransactionManager) GetEntropy added in v0.0.6

func (m *TransactionManager) GetEntropy(pulse core.PulseNumber) (*core.Entropy, error)

GetEntropy returns entropy from storage for given pulse.

Entropy is used for calculating node roles.

func (*TransactionManager) GetObjectIndex added in v0.0.6

func (m *TransactionManager) GetObjectIndex(ref *record.Reference) (*index.ObjectLifeline, error)

GetObjectIndex fetches object lifeline index.

func (*TransactionManager) GetRecord added in v0.0.6

func (m *TransactionManager) GetRecord(ref *record.Reference) (record.Record, error)

GetRecord returns record from BadgerDB by *record.Reference.

It returns ErrNotFound if the DB does not contain the key.

func (*TransactionManager) Set added in v0.0.6

func (m *TransactionManager) Set(key, value []byte) error

Set stores value by key.

func (*TransactionManager) SetClassIndex added in v0.0.6

func (m *TransactionManager) SetClassIndex(ref *record.Reference, idx *index.ClassLifeline) error

SetClassIndex stores class lifeline index.

func (*TransactionManager) SetEntropy added in v0.0.6

func (m *TransactionManager) SetEntropy(pulse core.PulseNumber, entropy core.Entropy) error

SetEntropy stores given entropy for given pulse in storage.

Entropy is used for calculating node roles.

func (*TransactionManager) SetObjectIndex added in v0.0.6

func (m *TransactionManager) SetObjectIndex(ref *record.Reference, idx *index.ObjectLifeline) error

SetObjectIndex stores object lifeline index.

func (*TransactionManager) SetRecord added in v0.0.6

func (m *TransactionManager) SetRecord(rec record.Record) (*record.Reference, error)

SetRecord stores record in BadgerDB and returns *record.Reference of new record.

If record exists returns ErrOverride error.

Directories

Path Synopsis
Package storagetest contains high level API tests and test utils for other modules.
Package storagetest contains high level API tests and test utils for other modules.

Jump to

Keyboard shortcuts

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