store

package
v0.9.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Overview

Package db contains primitives for storing and indexing data.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when value was not found.
	ErrNotFound = errors.New("value not found")
)

Functions

This section is empty.

Types

type Backuper

type Backuper interface {
	// Backup does incremental backup starting from 'since' timestamp and write result to 'to' parameter.
	// It returns a timestamp indicating when the entries were dumped which can be passed into a
	// later invocation to generate an incremental dump.
	Backup(to io.Writer, since uint64) (uint64, error)
}

Backuper provides interface for making backups

type BadgerDB

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

BadgerDB is a badger DB implementation.

func NewBadgerDB

func NewBadgerDB(ops badger.Options) (*BadgerDB, error)

NewBadgerDB creates new BadgerDB instance. Creates new badger.DB instance with provided working dir and use it as backend for BadgerDB.

func (*BadgerDB) Backend

func (b *BadgerDB) Backend() *badger.DB

func (*BadgerDB) Backup

func (b *BadgerDB) Backup(w io.Writer, since uint64) (uint64, error)

Backup creates backup.

func (*BadgerDB) Delete

func (b *BadgerDB) Delete(key Key) error

Delete deletes value for a key.

func (*BadgerDB) ForceValueGC

func (b *BadgerDB) ForceValueGC(ctx context.Context)

ForceValueGC forces badger values garbage collection.

func (*BadgerDB) Get

func (b *BadgerDB) Get(key Key) (value []byte, err error)

Get returns value for specified key or an error. A copy of a value will be returned (i.e. getting large value can be long).

func (*BadgerDB) NewIterator

func (b *BadgerDB) NewIterator(pivot Key, reverse bool) Iterator

NewIterator returns new Iterator over the store.

func (*BadgerDB) Set

func (b *BadgerDB) Set(key Key, value []byte) error

Set stores value for a key.

func (*BadgerDB) Stop

func (b *BadgerDB) Stop(ctx context.Context) error

Stop gracefully stops all disk writes. After calling this, it's safe to kill the process without losing data.

type DB

type DB interface {
	Get(key Key) (value []byte, err error)
	Set(key Key, value []byte) error
	Delete(key Key) error
	NewIterator(pivot Key, reverse bool) Iterator
}

DB provides a simple key-value store interface for persisting data. But it is internally ordered ( lexicographically by key bytes ) so if you want you can iterate over store using Iterator interface.

type DBMock

type DBMock struct {
	DeleteMock mDBMockDelete

	GetMock mDBMockGet

	NewIteratorMock mDBMockNewIterator

	SetMock mDBMockSet
	// contains filtered or unexported fields
}

DBMock implements DB

func NewDBMock

func NewDBMock(t minimock.Tester) *DBMock

NewDBMock returns a mock for DB

func (*DBMock) Delete

func (mmDelete *DBMock) Delete(key Key) (err error)

Delete implements DB

func (*DBMock) DeleteAfterCounter

func (mmDelete *DBMock) DeleteAfterCounter() uint64

DeleteAfterCounter returns a count of finished DBMock.Delete invocations

func (*DBMock) DeleteBeforeCounter

func (mmDelete *DBMock) DeleteBeforeCounter() uint64

DeleteBeforeCounter returns a count of DBMock.Delete invocations

func (*DBMock) Get

func (mmGet *DBMock) Get(key Key) (value []byte, err error)

Get implements DB

func (*DBMock) GetAfterCounter

func (mmGet *DBMock) GetAfterCounter() uint64

GetAfterCounter returns a count of finished DBMock.Get invocations

func (*DBMock) GetBeforeCounter

func (mmGet *DBMock) GetBeforeCounter() uint64

GetBeforeCounter returns a count of DBMock.Get invocations

func (*DBMock) MinimockDeleteDone

func (m *DBMock) MinimockDeleteDone() bool

MinimockDeleteDone returns true if the count of the Delete invocations corresponds the number of defined expectations

func (*DBMock) MinimockDeleteInspect

func (m *DBMock) MinimockDeleteInspect()

MinimockDeleteInspect logs each unmet expectation

func (*DBMock) MinimockFinish

func (m *DBMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*DBMock) MinimockGetDone

func (m *DBMock) MinimockGetDone() bool

MinimockGetDone returns true if the count of the Get invocations corresponds the number of defined expectations

func (*DBMock) MinimockGetInspect

func (m *DBMock) MinimockGetInspect()

MinimockGetInspect logs each unmet expectation

func (*DBMock) MinimockNewIteratorDone

func (m *DBMock) MinimockNewIteratorDone() bool

MinimockNewIteratorDone returns true if the count of the NewIterator invocations corresponds the number of defined expectations

func (*DBMock) MinimockNewIteratorInspect

func (m *DBMock) MinimockNewIteratorInspect()

MinimockNewIteratorInspect logs each unmet expectation

func (*DBMock) MinimockSetDone

func (m *DBMock) MinimockSetDone() bool

MinimockSetDone returns true if the count of the Set invocations corresponds the number of defined expectations

func (*DBMock) MinimockSetInspect

func (m *DBMock) MinimockSetInspect()

MinimockSetInspect logs each unmet expectation

func (*DBMock) MinimockWait

func (m *DBMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*DBMock) NewIterator

func (mmNewIterator *DBMock) NewIterator(pivot Key, reverse bool) (i1 Iterator)

NewIterator implements DB

func (*DBMock) NewIteratorAfterCounter

func (mmNewIterator *DBMock) NewIteratorAfterCounter() uint64

NewIteratorAfterCounter returns a count of finished DBMock.NewIterator invocations

func (*DBMock) NewIteratorBeforeCounter

func (mmNewIterator *DBMock) NewIteratorBeforeCounter() uint64

NewIteratorBeforeCounter returns a count of DBMock.NewIterator invocations

func (*DBMock) Set

func (mmSet *DBMock) Set(key Key, value []byte) (err error)

Set implements DB

func (*DBMock) SetAfterCounter

func (mmSet *DBMock) SetAfterCounter() uint64

SetAfterCounter returns a count of finished DBMock.Set invocations

func (*DBMock) SetBeforeCounter

func (mmSet *DBMock) SetBeforeCounter() uint64

SetBeforeCounter returns a count of DBMock.Set invocations

type DBMockDeleteExpectation

type DBMockDeleteExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

DBMockDeleteExpectation specifies expectation struct of the DB.Delete

func (*DBMockDeleteExpectation) Then

func (e *DBMockDeleteExpectation) Then(err error) *DBMock

Then sets up DB.Delete return parameters for the expectation previously defined by the When method

type DBMockDeleteParams

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

DBMockDeleteParams contains parameters of the DB.Delete

type DBMockDeleteResults

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

DBMockDeleteResults contains results of the DB.Delete

type DBMockGetExpectation

type DBMockGetExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

DBMockGetExpectation specifies expectation struct of the DB.Get

func (*DBMockGetExpectation) Then

func (e *DBMockGetExpectation) Then(value []byte, err error) *DBMock

Then sets up DB.Get return parameters for the expectation previously defined by the When method

type DBMockGetParams

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

DBMockGetParams contains parameters of the DB.Get

type DBMockGetResults

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

DBMockGetResults contains results of the DB.Get

type DBMockNewIteratorExpectation

type DBMockNewIteratorExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

DBMockNewIteratorExpectation specifies expectation struct of the DB.NewIterator

func (*DBMockNewIteratorExpectation) Then

Then sets up DB.NewIterator return parameters for the expectation previously defined by the When method

type DBMockNewIteratorParams

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

DBMockNewIteratorParams contains parameters of the DB.NewIterator

type DBMockNewIteratorResults

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

DBMockNewIteratorResults contains results of the DB.NewIterator

type DBMockSetExpectation

type DBMockSetExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

DBMockSetExpectation specifies expectation struct of the DB.Set

func (*DBMockSetExpectation) Then

func (e *DBMockSetExpectation) Then(err error) *DBMock

Then sets up DB.Set return parameters for the expectation previously defined by the When method

type DBMockSetParams

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

DBMockSetParams contains parameters of the DB.Set

type DBMockSetResults

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

DBMockSetResults contains results of the DB.Set

type Iterator

type Iterator interface {
	// Next moves the iterator to the next key-value pair.
	Next() bool
	// Close frees resources within the iterator and invalidates it.
	Close()
	// Key returns only the second part of the composite key - (ID) without scope id.
	// Warning: Key is only valid as long as item is valid (until iterator.Next() called), or transaction is valid.
	// If you need to use it outside its validity, please copy the key.
	Key() []byte
	// Value returns value itself (ex: record, drop, blob, etc).
	// Warning: Value is only valid as long as item is valid (until iterator.Next() called), or transaction is valid.
	// If you need to use it outside its validity, please copy the value.
	Value() ([]byte, error)
}

Iterator provides an interface for walking through the storage record sequence (where records are sorted lexicographically).

func NewReadIterator

func NewReadIterator(db *badger.DB, pivot Key, reverse bool) Iterator

NewReadIterator returns new Iterator over the store.

type IteratorMock

type IteratorMock struct {
	CloseMock mIteratorMockClose

	KeyMock mIteratorMockKey

	NextMock mIteratorMockNext

	ValueMock mIteratorMockValue
	// contains filtered or unexported fields
}

IteratorMock implements Iterator

func NewIteratorMock

func NewIteratorMock(t minimock.Tester) *IteratorMock

NewIteratorMock returns a mock for Iterator

func (*IteratorMock) Close

func (mmClose *IteratorMock) Close()

Close implements Iterator

func (*IteratorMock) CloseAfterCounter

func (mmClose *IteratorMock) CloseAfterCounter() uint64

CloseAfterCounter returns a count of finished IteratorMock.Close invocations

func (*IteratorMock) CloseBeforeCounter

func (mmClose *IteratorMock) CloseBeforeCounter() uint64

CloseBeforeCounter returns a count of IteratorMock.Close invocations

func (*IteratorMock) Key

func (mmKey *IteratorMock) Key() (ba1 []byte)

Key implements Iterator

func (*IteratorMock) KeyAfterCounter

func (mmKey *IteratorMock) KeyAfterCounter() uint64

KeyAfterCounter returns a count of finished IteratorMock.Key invocations

func (*IteratorMock) KeyBeforeCounter

func (mmKey *IteratorMock) KeyBeforeCounter() uint64

KeyBeforeCounter returns a count of IteratorMock.Key invocations

func (*IteratorMock) MinimockCloseDone

func (m *IteratorMock) MinimockCloseDone() bool

MinimockCloseDone returns true if the count of the Close invocations corresponds the number of defined expectations

func (*IteratorMock) MinimockCloseInspect

func (m *IteratorMock) MinimockCloseInspect()

MinimockCloseInspect logs each unmet expectation

func (*IteratorMock) MinimockFinish

func (m *IteratorMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*IteratorMock) MinimockKeyDone

func (m *IteratorMock) MinimockKeyDone() bool

MinimockKeyDone returns true if the count of the Key invocations corresponds the number of defined expectations

func (*IteratorMock) MinimockKeyInspect

func (m *IteratorMock) MinimockKeyInspect()

MinimockKeyInspect logs each unmet expectation

func (*IteratorMock) MinimockNextDone

func (m *IteratorMock) MinimockNextDone() bool

MinimockNextDone returns true if the count of the Next invocations corresponds the number of defined expectations

func (*IteratorMock) MinimockNextInspect

func (m *IteratorMock) MinimockNextInspect()

MinimockNextInspect logs each unmet expectation

func (*IteratorMock) MinimockValueDone

func (m *IteratorMock) MinimockValueDone() bool

MinimockValueDone returns true if the count of the Value invocations corresponds the number of defined expectations

func (*IteratorMock) MinimockValueInspect

func (m *IteratorMock) MinimockValueInspect()

MinimockValueInspect logs each unmet expectation

func (*IteratorMock) MinimockWait

func (m *IteratorMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*IteratorMock) Next

func (mmNext *IteratorMock) Next() (b1 bool)

Next implements Iterator

func (*IteratorMock) NextAfterCounter

func (mmNext *IteratorMock) NextAfterCounter() uint64

NextAfterCounter returns a count of finished IteratorMock.Next invocations

func (*IteratorMock) NextBeforeCounter

func (mmNext *IteratorMock) NextBeforeCounter() uint64

NextBeforeCounter returns a count of IteratorMock.Next invocations

func (*IteratorMock) Value

func (mmValue *IteratorMock) Value() (ba1 []byte, err error)

Value implements Iterator

func (*IteratorMock) ValueAfterCounter

func (mmValue *IteratorMock) ValueAfterCounter() uint64

ValueAfterCounter returns a count of finished IteratorMock.Value invocations

func (*IteratorMock) ValueBeforeCounter

func (mmValue *IteratorMock) ValueBeforeCounter() uint64

ValueBeforeCounter returns a count of IteratorMock.Value invocations

type IteratorMockCloseExpectation

type IteratorMockCloseExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

IteratorMockCloseExpectation specifies expectation struct of the Iterator.Close

type IteratorMockKeyExpectation

type IteratorMockKeyExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

IteratorMockKeyExpectation specifies expectation struct of the Iterator.Key

type IteratorMockKeyResults

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

IteratorMockKeyResults contains results of the Iterator.Key

type IteratorMockNextExpectation

type IteratorMockNextExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

IteratorMockNextExpectation specifies expectation struct of the Iterator.Next

type IteratorMockNextResults

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

IteratorMockNextResults contains results of the Iterator.Next

type IteratorMockValueExpectation

type IteratorMockValueExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

IteratorMockValueExpectation specifies expectation struct of the Iterator.Value

type IteratorMockValueResults

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

IteratorMockValueResults contains results of the Iterator.Value

type JetIndex

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

JetIndex contains methods to implement quick access to data by jet. Indexes are stored in memory. Consider disk implementation for large collections.

func NewJetIndex

func NewJetIndex() *JetIndex

NewJetIndex creates new index instance.

func (*JetIndex) Add

func (i *JetIndex) Add(id insolar.ID, jetID insolar.JetID)

Add creates index record for specified id and jet. To remove clean up index, use "Delete" method.

func (*JetIndex) Delete

func (i *JetIndex) Delete(id insolar.ID, jetID insolar.JetID)

Delete removes specified id - jet record from index.

func (*JetIndex) For

func (i *JetIndex) For(jetID insolar.JetID) map[insolar.ID]struct{}

For returns a collection of ids, that are stored for a specific jetID

type JetIndexAccessor

type JetIndexAccessor interface {
	For(jetID insolar.JetID) map[insolar.ID]struct{}
}

JetIndexAccessor is an interface for modifying index records.

type JetIndexAccessorMock

type JetIndexAccessorMock struct {
	ForMock mJetIndexAccessorMockFor
	// contains filtered or unexported fields
}

JetIndexAccessorMock implements JetIndexAccessor

func NewJetIndexAccessorMock

func NewJetIndexAccessorMock(t minimock.Tester) *JetIndexAccessorMock

NewJetIndexAccessorMock returns a mock for JetIndexAccessor

func (*JetIndexAccessorMock) For

func (mmFor *JetIndexAccessorMock) For(jetID insolar.JetID) (m1 map[insolar.ID]struct {
})

For implements JetIndexAccessor

func (*JetIndexAccessorMock) ForAfterCounter

func (mmFor *JetIndexAccessorMock) ForAfterCounter() uint64

ForAfterCounter returns a count of finished JetIndexAccessorMock.For invocations

func (*JetIndexAccessorMock) ForBeforeCounter

func (mmFor *JetIndexAccessorMock) ForBeforeCounter() uint64

ForBeforeCounter returns a count of JetIndexAccessorMock.For invocations

func (*JetIndexAccessorMock) MinimockFinish

func (m *JetIndexAccessorMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*JetIndexAccessorMock) MinimockForDone

func (m *JetIndexAccessorMock) MinimockForDone() bool

MinimockForDone returns true if the count of the For invocations corresponds the number of defined expectations

func (*JetIndexAccessorMock) MinimockForInspect

func (m *JetIndexAccessorMock) MinimockForInspect()

MinimockForInspect logs each unmet expectation

func (*JetIndexAccessorMock) MinimockWait

func (m *JetIndexAccessorMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

type JetIndexAccessorMockForExpectation

type JetIndexAccessorMockForExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

JetIndexAccessorMockForExpectation specifies expectation struct of the JetIndexAccessor.For

func (*JetIndexAccessorMockForExpectation) Then

Then sets up JetIndexAccessor.For return parameters for the expectation previously defined by the When method

type JetIndexAccessorMockForParams

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

JetIndexAccessorMockForParams contains parameters of the JetIndexAccessor.For

type JetIndexAccessorMockForResults

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

JetIndexAccessorMockForResults contains results of the JetIndexAccessor.For

type JetIndexModifier

type JetIndexModifier interface {
	Add(id insolar.ID, jetID insolar.JetID)
	Delete(id insolar.ID, jetID insolar.JetID)
}

JetIndexModifier is an interface for modifying index records.

type JetIndexModifierMock

type JetIndexModifierMock struct {
	AddMock mJetIndexModifierMockAdd

	DeleteMock mJetIndexModifierMockDelete
	// contains filtered or unexported fields
}

JetIndexModifierMock implements JetIndexModifier

func NewJetIndexModifierMock

func NewJetIndexModifierMock(t minimock.Tester) *JetIndexModifierMock

NewJetIndexModifierMock returns a mock for JetIndexModifier

func (*JetIndexModifierMock) Add

func (mmAdd *JetIndexModifierMock) Add(id insolar.ID, jetID insolar.JetID)

Add implements JetIndexModifier

func (*JetIndexModifierMock) AddAfterCounter

func (mmAdd *JetIndexModifierMock) AddAfterCounter() uint64

AddAfterCounter returns a count of finished JetIndexModifierMock.Add invocations

func (*JetIndexModifierMock) AddBeforeCounter

func (mmAdd *JetIndexModifierMock) AddBeforeCounter() uint64

AddBeforeCounter returns a count of JetIndexModifierMock.Add invocations

func (*JetIndexModifierMock) Delete

func (mmDelete *JetIndexModifierMock) Delete(id insolar.ID, jetID insolar.JetID)

Delete implements JetIndexModifier

func (*JetIndexModifierMock) DeleteAfterCounter

func (mmDelete *JetIndexModifierMock) DeleteAfterCounter() uint64

DeleteAfterCounter returns a count of finished JetIndexModifierMock.Delete invocations

func (*JetIndexModifierMock) DeleteBeforeCounter

func (mmDelete *JetIndexModifierMock) DeleteBeforeCounter() uint64

DeleteBeforeCounter returns a count of JetIndexModifierMock.Delete invocations

func (*JetIndexModifierMock) MinimockAddDone

func (m *JetIndexModifierMock) MinimockAddDone() bool

MinimockAddDone returns true if the count of the Add invocations corresponds the number of defined expectations

func (*JetIndexModifierMock) MinimockAddInspect

func (m *JetIndexModifierMock) MinimockAddInspect()

MinimockAddInspect logs each unmet expectation

func (*JetIndexModifierMock) MinimockDeleteDone

func (m *JetIndexModifierMock) MinimockDeleteDone() bool

MinimockDeleteDone returns true if the count of the Delete invocations corresponds the number of defined expectations

func (*JetIndexModifierMock) MinimockDeleteInspect

func (m *JetIndexModifierMock) MinimockDeleteInspect()

MinimockDeleteInspect logs each unmet expectation

func (*JetIndexModifierMock) MinimockFinish

func (m *JetIndexModifierMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*JetIndexModifierMock) MinimockWait

func (m *JetIndexModifierMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

type JetIndexModifierMockAddExpectation

type JetIndexModifierMockAddExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

JetIndexModifierMockAddExpectation specifies expectation struct of the JetIndexModifier.Add

type JetIndexModifierMockAddParams

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

JetIndexModifierMockAddParams contains parameters of the JetIndexModifier.Add

type JetIndexModifierMockDeleteExpectation

type JetIndexModifierMockDeleteExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

JetIndexModifierMockDeleteExpectation specifies expectation struct of the JetIndexModifier.Delete

type JetIndexModifierMockDeleteParams

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

JetIndexModifierMockDeleteParams contains parameters of the JetIndexModifier.Delete

type Key

type Key interface {
	// Scope returns a first part for constructing a composite key for storing record in db
	Scope() Scope
	// ID returns a second part for constructing a composite key for storing record in db
	ID() []byte
}

Key represents a key for the key-value store. Scope is required to separate different DB clients and should be unique.

type Scope

type Scope byte

Scope separates DB clients.

const (
	// ScopePulse is the scope for pulse storage.
	ScopePulse Scope = 1
	// ScopeRecord is the scope for record storage.
	ScopeRecord Scope = 2
	// ScopeJetDrop is the scope for a jet drop storage.
	ScopeJetDrop Scope = 3
	// ScopeIndex is the scope for an index records.
	ScopeIndex Scope = 4
	// ScopeLastKnownIndexPN is the scope for a last known pulse number of the index bucket
	ScopeLastKnownIndexPN Scope = 5
	// ScopeGenesis is the scope for a genesis records.
	ScopeGenesis Scope = 6
	// ScopeJetTree is the scope for a jet tree storage.
	ScopeJetTree Scope = 7
	// ScopeJetKeeper is the scope for a jet id storage.
	ScopeJetKeeper Scope = 8
	// ScopeJetKeeperSyncPulse is the scope for a top sync pulse storage.
	ScopeJetKeeperSyncPulse Scope = 9
	// ScopeRecordPosition is the scope for records' positions.
	ScopeRecordPosition Scope = 10
)

func (Scope) Bytes

func (s Scope) Bytes() []byte

Bytes returns binary scope representation.

Jump to

Keyboard shortcuts

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