Documentation ¶
Overview ¶
Package storage contains ledger storage implementation on top of BadgerDB engine.
Index ¶
- Variables
- type DB
- func (db *DB) AddPulse(pulse core.Pulse) error
- func (db *DB) BeginTransaction(update bool) *TransactionManager
- func (db *DB) Bootstrap() error
- func (db *DB) Close() error
- func (db *DB) CreateDrop(pulse core.PulseNumber, prevHash []byte) (*jetdrop.JetDrop, [][2][]byte, error)
- func (db *DB) GenesisRef() *record.Reference
- func (db *DB) Get(key []byte) ([]byte, error)
- func (db *DB) GetClassIndex(id *record.ID, forupdate bool) (*index.ClassLifeline, error)
- func (db *DB) GetDrop(pulse core.PulseNumber) (*jetdrop.JetDrop, error)
- func (db *DB) GetLatestPulseNumber() (core.PulseNumber, error)
- func (db *DB) GetObjectIndex(id *record.ID, forupdate bool) (*index.ObjectLifeline, error)
- func (db *DB) GetPulse(num core.PulseNumber) (*record.PulseRecord, error)
- func (db *DB) GetRecord(id *record.ID) (record.Record, error)
- func (db *DB) GetRequest(id *record.ID) (record.Request, error)
- func (db *DB) Set(key, value []byte) error
- func (db *DB) SetClassIndex(id *record.ID, idx *index.ClassLifeline) error
- func (db *DB) SetDrop(drop *jetdrop.JetDrop) error
- func (db *DB) SetObjectIndex(id *record.ID, idx *index.ObjectLifeline) error
- func (db *DB) SetRecord(rec record.Record) (*record.ID, error)
- func (db *DB) SetRecordBinary(key, rec []byte) error
- func (db *DB) SetRequest(req record.Request) (*record.ID, error)
- func (db *DB) SetTxRetiries(n int)
- func (db *DB) Update(fn func(*TransactionManager) error) error
- func (db *DB) View(fn func(*TransactionManager) error) error
- type IDLocker
- type Store
- type TransactionManager
- func (m *TransactionManager) Commit() error
- func (m *TransactionManager) Discard()
- func (m *TransactionManager) Get(key []byte) ([]byte, error)
- func (m *TransactionManager) GetClassIndex(id *record.ID, forupdate bool) (*index.ClassLifeline, error)
- func (m *TransactionManager) GetLatestPulseNumber() (core.PulseNumber, error)
- func (m *TransactionManager) GetObjectIndex(id *record.ID, forupdate bool) (*index.ObjectLifeline, error)
- func (m *TransactionManager) GetRecord(id *record.ID) (record.Record, error)
- func (m *TransactionManager) GetRequest(id *record.ID) (record.Request, error)
- func (m *TransactionManager) Set(key, value []byte) error
- func (m *TransactionManager) SetClassIndex(id *record.ID, idx *index.ClassLifeline) error
- func (m *TransactionManager) SetObjectIndex(id *record.ID, idx *index.ObjectLifeline) error
- func (m *TransactionManager) SetRecord(rec record.Record) (*record.ID, error)
- func (m *TransactionManager) SetRequest(req record.Request) (*record.ID, error)
Constants ¶
This section is empty.
Variables ¶
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
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) Close ¶ added in v0.0.6
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) CreateDrop ¶ added in v0.6.0
func (db *DB) CreateDrop(pulse core.PulseNumber, prevHash []byte) (*jetdrop.JetDrop, [][2][]byte, error)
CreateDrop creates and stores jet drop for given pulse number.
Previous JetDrop hash should be provided. On success returns saved drop and slot records.
func (*DB) GenesisRef ¶ added in v0.6.0
GenesisRef returns the genesis record reference.
Genesis record is the parent for all top-level records.
func (*DB) GetClassIndex ¶ added in v0.0.6
GetClassIndex wraps matching transaction manager method.
func (*DB) GetLatestPulseNumber ¶ added in v0.6.0
func (db *DB) GetLatestPulseNumber() (core.PulseNumber, error)
GetLatestPulseNumber returns current pulse number.
func (*DB) GetObjectIndex ¶ added in v0.0.6
GetObjectIndex wraps matching transaction manager method.
func (*DB) GetPulse ¶ added in v0.6.0
func (db *DB) GetPulse(num core.PulseNumber) (*record.PulseRecord, error)
GetPulse returns pulse for provided pulse number.
func (*DB) GetRequest ¶ added in v0.5.0
GetRequest wraps matching transaction manager method.
func (*DB) SetClassIndex ¶ added in v0.0.6
SetClassIndex wraps matching transaction manager method.
func (*DB) SetObjectIndex ¶ added in v0.0.6
SetObjectIndex wraps matching transaction manager method.
func (*DB) SetRecordBinary ¶ added in v0.6.0
SetRecordBinary saves binary record for specified key.
This method is used for data replication.
func (*DB) SetRequest ¶ added in v0.5.0
SetRequest wraps matching transaction manager method.
func (*DB) SetTxRetiries ¶ added in v0.0.6
SetTxRetiries sets number of retries on conflict in Update
type IDLocker ¶ added in v0.6.0
type IDLocker struct {
// contains filtered or unexported fields
}
IDLocker provides Lock/Unlock methods per record ID.
TODO: for further optimization we could use sync.Pool for mutexes.
func NewIDLocker ¶ added in v0.6.0
func NewIDLocker() *IDLocker
NewIDLocker creates new initialized IDLocker.
type Store ¶ added in v0.0.5
type Store interface { GetRecord(ref *record.ID) (record.Record, error) SetRecord(rec record.Record) (*record.ID, error) GetClassIndex(ref *record.ID, forupdate bool) (*index.ClassLifeline, error) SetClassIndex(ref *record.ID, idx *index.ClassLifeline) error GetObjectIndex(ref *record.ID, forupdate bool) (*index.ObjectLifeline, error) SetObjectIndex(ref *record.ID, idx *index.ObjectLifeline) error GetLatestPulseNumber() (core.PulseNumber, 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(id *record.ID, forupdate bool) (*index.ClassLifeline, error)
GetClassIndex fetches class lifeline's index.
func (*TransactionManager) GetLatestPulseNumber ¶ added in v0.6.0
func (m *TransactionManager) GetLatestPulseNumber() (core.PulseNumber, error)
GetLatestPulseNumber returns current pulse number.
func (*TransactionManager) GetObjectIndex ¶ added in v0.0.6
func (m *TransactionManager) GetObjectIndex(id *record.ID, forupdate bool) (*index.ObjectLifeline, error)
GetObjectIndex fetches object lifeline index.
func (*TransactionManager) GetRecord ¶ added in v0.0.6
GetRecord returns record from BadgerDB by *record.Reference.
It returns ErrNotFound if the DB does not contain the key.
func (*TransactionManager) GetRequest ¶ added in v0.5.0
GetRequest returns request 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(id *record.ID, idx *index.ClassLifeline) error
SetClassIndex stores class lifeline index.
func (*TransactionManager) SetObjectIndex ¶ added in v0.0.6
func (m *TransactionManager) SetObjectIndex(id *record.ID, idx *index.ObjectLifeline) error
SetObjectIndex stores object lifeline index.
func (*TransactionManager) SetRecord ¶ added in v0.0.6
SetRecord stores record in BadgerDB and returns *record.ID of new record.
If record exists returns both *record.ID and ErrOverride error. If record not found returns nil and ErrNotFound error
func (*TransactionManager) SetRequest ¶ added in v0.5.0
SetRequest stores request record in BadgerDB and returns *record.ID of new record.
If record exists SetRequest just returns *record.ID without 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. |