storage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChangeSent = errors.New("change sent")
View Source
var ErrEndOfIterator = errors.New("end of iterator")
View Source
var ErrNotFound = errors.New("couldn't find element")

Functions

func InjectStateTransaction

func InjectStateTransaction(ctx context.Context, tx StateTransaction) context.Context

For now save in context

func TestDequeIterator

func TestDequeIterator(iter *DequeIterator, expectedValues []octosql.Value) (bool, error)

func TestMapIteratorCorrectness

func TestMapIteratorCorrectness(iter *MapIterator, expectedKeys, expectedValues []octosql.Value) (bool, error)

func TestSetIteratorCorrectness

func TestSetIteratorCorrectness(iter *MultiSetIterator, expectedValues []octosql.Value, expectedCounts []int) error

The iterator of a set has no determined order

Types

type BadgerIterator

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

BadgerIterator is a wrapper around *badger.Iterator that implements the Iterator interface

func NewBadgerIterator

func NewBadgerIterator(it *badger.Iterator, prefixLength int) *BadgerIterator

func (*BadgerIterator) Close

func (bi *BadgerIterator) Close() error

func (*BadgerIterator) Next

func (bi *BadgerIterator) Next(value proto.Message) error

func (*BadgerIterator) NextWithKey

func (bi *BadgerIterator) NextWithKey(key MonotonicallySerializable, value proto.Message) error

type BadgerStorage

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

func NewBadgerStorage

func NewBadgerStorage(db *badger.DB) *BadgerStorage

func (*BadgerStorage) BeginTransaction

func (bs *BadgerStorage) BeginTransaction() StateTransaction

func (*BadgerStorage) Close

func (bs *BadgerStorage) Close() error

func (*BadgerStorage) DropAll

func (bs *BadgerStorage) DropAll(prefix []byte) error

func (*BadgerStorage) Subscribe

func (bs *BadgerStorage) Subscribe(ctx context.Context) *Subscription

func (*BadgerStorage) WithPrefix

func (bs *BadgerStorage) WithPrefix(prefix []byte) Storage

type ChangesNotifierFunc

type ChangesNotifierFunc func(ctx context.Context, changes chan<- struct{}) error

type Deque

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

func NewDeque

func NewDeque(tx StateTransaction) *Deque

func (*Deque) Clear

func (dq *Deque) Clear() error

Clears all contents of the queue including the metadata.

func (*Deque) GetIterator

func (dq *Deque) GetIterator(opts ...IteratorOption) *DequeIterator

func (*Deque) Length

func (dq *Deque) Length() (int, error)

func (*Deque) PeekBack

func (dq *Deque) PeekBack(value proto.Message) error

Returns the last element of the queue without removing it. Returns ErrNotFound if the queue is empty.

func (*Deque) PeekFront

func (dq *Deque) PeekFront(value proto.Message) error

Returns the first element of the queue without removing it. Returns ErrNotFound if the queue is empty.

func (*Deque) PopBack

func (dq *Deque) PopBack(value proto.Message) error

Removes the last element from the queue and returns it. Returns ErrNotFound if the list is empty.

func (*Deque) PopFront

func (dq *Deque) PopFront(value proto.Message) error

Removes the first element from the queue and returns it. Returns ErrNotFound if the list is empty.

func (*Deque) PushBack

func (dq *Deque) PushBack(value proto.Message) error

Adds new element to the back of the queue.

func (*Deque) PushFront

func (dq *Deque) PushFront(value proto.Message) error

Adds new element to the front of the queue.

type DequeIterator

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

func NewDequeIterator

func NewDequeIterator(it Iterator) *DequeIterator

func (*DequeIterator) Close

func (lli *DequeIterator) Close() error

func (*DequeIterator) Next

func (lli *DequeIterator) Next(value proto.Message) error

type Iterator

type Iterator interface {
	Next(proto.Message) error
	NextWithKey(key MonotonicallySerializable, value proto.Message) error
	io.Closer
}

type IteratorOption

type IteratorOption func(*IteratorOptions)

func WithDefault

func WithDefault() IteratorOption

func WithPrefix

func WithPrefix(prefix []byte) IteratorOption

func WithReverse

func WithReverse() IteratorOption

type IteratorOptions

type IteratorOptions struct {
	PrefetchValues bool
	PrefetchSize   int
	Reverse        bool
	AllVersions    bool
	Prefix         []byte
	InternalAccess bool
}

IteratorOptions are a copy of badger.IteratorOptions They are used so that there is no explicit badger dependency in StateTransaction

func (*IteratorOptions) ToBadgerOptions

func (io *IteratorOptions) ToBadgerOptions() badger.IteratorOptions

type Map

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

func NewMap

func NewMap(tx StateTransaction) *Map

func (*Map) Clear

func (hm *Map) Clear() error

Clears the contents of the map. Important: To call map.Clear() one must close any iterators opened on that map

func (*Map) Delete

func (hm *Map) Delete(key MonotonicallySerializable) error

Removes a key from the map even if it wasn't present in it to begin with.

func (*Map) Get

func (hm *Map) Get(key MonotonicallySerializable, value proto.Message) error

Returns the value corresponding to key. Returns ErrNotFound if the given key doesn't correspond to a value in the map.

func (*Map) GetIterator

func (hm *Map) GetIterator(opts ...IteratorOption) *MapIterator

func (*Map) GetIteratorWithPrefix

func (hm *Map) GetIteratorWithPrefix(prefix []byte) *MapIterator

Returns an iterator with a specified prefix, that allows to iterate over a specified range of keys

func (*Map) Set

func (hm *Map) Set(key MonotonicallySerializable, value proto.Message) error

Inserts the mapping key -> value to the map. If key was already present in the map then the value is overwritten.

type MapIterator

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

func NewMapIterator

func NewMapIterator(it Iterator) *MapIterator

func (*MapIterator) Close

func (mi *MapIterator) Close() error

func (*MapIterator) Next

type MonotonicallySerializable

type MonotonicallySerializable interface {
	MonotonicMarshal() []byte
	MonotonicUnmarshal([]byte) error
}

A type that implements this interface must have a MonotonicMarshal method, that has the property, that if x <= y (where <= is the less-equal relation defined on a certain type, for example lexicographical order on strings) then MonotonicMarshal(x) <= MonotonicMarshal(y) (where <= is the lexicographical order on []byte). Since in mathematics such a function is called Monotonous, thus the name. A MonotonicUnmarshal which is the inverse of MonotonicMarshal is also required.

type MultiSet

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

func NewMultiSet

func NewMultiSet(tx StateTransaction) *MultiSet

func (*MultiSet) Clear

func (set *MultiSet) Clear() error

func (*MultiSet) Contains

func (set *MultiSet) Contains(value octosql.Value) (bool, error)

func (*MultiSet) Erase

func (set *MultiSet) Erase(value octosql.Value) error

func (*MultiSet) GetCount

func (set *MultiSet) GetCount(value octosql.Value) (int, error)

func (*MultiSet) GetIterator

func (set *MultiSet) GetIterator() *MultiSetIterator

func (*MultiSet) Insert

func (set *MultiSet) Insert(value octosql.Value) error

func (*MultiSet) ReadAll

func (set *MultiSet) ReadAll() ([]octosql.Value, error)

type MultiSetIterator

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

func NewSetIterator

func NewSetIterator(it Iterator) *MultiSetIterator

func (*MultiSetIterator) Close

func (msi *MultiSetIterator) Close() error

func (*MultiSetIterator) Next

func (msi *MultiSetIterator) Next(value *octosql.Value) error

type StateTransaction

type StateTransaction interface {
	Set(key, value []byte) error
	Get(key []byte) (value []byte, err error)
	Delete(key []byte) error
	WithPrefix(prefix []byte) StateTransaction
	GetPrefixLength() int
	Iterator(opts ...IteratorOption) Iterator
	Commit() error
	Abort()
	GetUnderlyingStorage() Storage
	Prefix() string
}

func GetStateTransactionFromContext

func GetStateTransactionFromContext(ctx context.Context) StateTransaction

For now save in context

type Storage

type Storage interface {
	DropAll(prefix []byte) error
	BeginTransaction() StateTransaction
	WithPrefix(prefix []byte) Storage
	Subscribe(ctx context.Context) *Subscription
	Close() error
}

func GetTestStorage

func GetTestStorage(t *testing.T) Storage

type Subscription

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

A Subscription lets the client listen for changes in the given prefixed storage. Subscriptions must be closed when not needed anymore.

func ConcatSubscriptions

func ConcatSubscriptions(ctx context.Context, subs ...*Subscription) *Subscription

func NewSubscription

func NewSubscription(ctx context.Context, subscriptionFunc ChangesNotifierFunc) *Subscription

func (*Subscription) Close

func (sub *Subscription) Close() error

func (*Subscription) ListenForChanges

func (sub *Subscription) ListenForChanges(ctx context.Context) error

ListenForChanges returns nil in case a change has been detected. Otherwise it returns an error containing the cause of the termination.

type ValueState

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

func NewValueState

func NewValueState(tx StateTransaction) *ValueState

func (*ValueState) Clear

func (vs *ValueState) Clear() error

func (*ValueState) Get

func (vs *ValueState) Get(value proto.Message) error

func (*ValueState) Set

func (vs *ValueState) Set(value proto.Message) error

Jump to

Keyboard shortcuts

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