store

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInconsistentState     = status.New(codes.Unknown, "inconsistent state").Err()
	ErrIndexNotFound         = status.New(codes.NotFound, "index not found").Err()
	ErrInvalidKey            = status.New(codes.InvalidArgument, "invalid key").Err()
	ErrInvalidReference      = status.New(codes.InvalidArgument, "invalid reference").Err()
	ErrInvalidKeyPrefix      = status.New(codes.InvalidArgument, "invalid key prefix").Err()
	ErrInvalidSet            = status.New(codes.InvalidArgument, "invalid set").Err()
	ErrInvalidOffset         = status.New(codes.InvalidArgument, "invalid offset").Err()
	ErrInvalidRootIndex      = status.New(codes.InvalidArgument, "invalid root index").Err()
	ErrObsoleteDataFormat    = status.New(codes.Unknown, "data format in which elements are written on disk is not up to date to the current version of immudb server. Please upgrade to access to complete functionalities").Err()
	ErrInconsistentDigest    = status.New(codes.Unknown, "insertion order index hash is not equal to the digest of the related value").Err()
	ErrIndexKeyMismatch      = status.New(codes.InvalidArgument, "mismatch between provided index and key").Err()
	ErrZAddIndexMissing      = status.New(codes.InvalidArgument, "zAdd index not provided").Err()
	ErrReferenceIndexMissing = status.New(codes.InvalidArgument, "reference index not provided").Err()
	ErrNoReferenceProvided   = status.New(codes.InvalidArgument, "provided argument is not a reference").Err()
)

immudb errors

View Source
var (
	// ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid
	// range.
	ErrValueLogSize = status.New(codes.Unknown, badger.ErrValueLogSize.Error()).Err()

	// ErrKeyNotFound is returned when key isn't found on a txn.Get.
	ErrKeyNotFound = status.New(codes.NotFound, badger.ErrKeyNotFound.Error()).Err()

	// ErrTxnTooBig is returned if too many writes are fit into a single transaction.
	ErrTxnTooBig = status.New(codes.Unknown, badger.ErrTxnTooBig.Error()).Err()

	// ErrConflict is returned when a transaction conflicts with another transaction. This can
	// happen if the read rows had been updated concurrently by another transaction.
	ErrConflict = status.New(codes.Unknown, badger.ErrConflict.Error()).Err()

	// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
	ErrReadOnlyTxn = status.New(codes.Unknown, badger.ErrReadOnlyTxn.Error()).Err()

	// ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
	ErrDiscardedTxn = status.New(codes.Unknown, badger.ErrDiscardedTxn.Error()).Err()

	// ErrEmptyKey is returned if an empty key is passed on an update function.
	ErrEmptyKey = status.New(codes.Unknown, badger.ErrEmptyKey.Error()).Err()

	// ErrRetry is returned when a log file containing the value is not found.
	// This usually indicates that it may have been garbage collected, and the
	// operation needs to be retried.
	ErrRetry = status.New(codes.Unknown, badger.ErrRetry.Error()).Err()

	// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
	// In such a case, GC can't be run.
	ErrThresholdZero = status.New(codes.Unknown, badger.ErrThresholdZero.Error()).Err()

	// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
	ErrNoRewrite = status.New(codes.Unknown, badger.ErrNoRewrite.Error()).Err()

	// ErrRejected is returned if a value log GC is called either while another GC is running, or
	// after DB::Close has been called.
	ErrRejected = status.New(codes.Unknown, badger.ErrRejected.Error()).Err()

	// ErrInvalidRequest is returned if the user request is invalid.
	ErrInvalidRequest = status.New(codes.Unknown, badger.ErrInvalidRequest.Error()).Err()

	// ErrManagedTxn is returned if the user tries to use an API which isn't
	// allowed due to external management of transactions, when using ManagedDB.
	ErrManagedTxn = status.New(codes.Unknown, badger.ErrManagedTxn.Error()).Err()

	// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
	ErrInvalidDump = status.New(codes.Unknown, badger.ErrInvalidDump.Error()).Err()

	// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
	ErrZeroBandwidth = status.New(codes.Unknown, badger.ErrZeroBandwidth.Error()).Err()

	// ErrInvalidLoadingMode is returned when opt.ValueLogLoadingMode option is not
	// within the valid range
	ErrInvalidLoadingMode = status.New(codes.Unknown, badger.ErrInvalidLoadingMode.Error()).Err()

	// ErrReplayNeeded is returned when opt.ReadOnly is set but the
	// database requires a value log replay.
	ErrReplayNeeded = status.New(codes.Unknown, badger.ErrReplayNeeded.Error()).Err()

	// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
	ErrWindowsNotSupported = status.New(codes.Unknown, badger.ErrWindowsNotSupported.Error()).Err()

	// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
	// corrupt data to allow Badger to run properly.
	ErrTruncateNeeded = status.New(codes.Unknown, badger.ErrTruncateNeeded.Error()).Err()

	// ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all
	// data from Badger, we stop accepting new writes, by returning this error.
	ErrBlockedWrites = status.New(codes.Unknown, badger.ErrBlockedWrites.Error()).Err()

	// ErrNilCallback is returned when subscriber's callback is nil.
	ErrNilCallback = status.New(codes.Unknown, badger.ErrNilCallback.Error()).Err()

	// ErrEncryptionKeyMismatch is returned when the storage key is not
	// matched with the key previously given.
	ErrEncryptionKeyMismatch = status.New(codes.Unknown, badger.ErrEncryptionKeyMismatch.Error()).Err()

	// ErrInvalidDataKeyID is returned if the datakey id is invalid.
	ErrInvalidDataKeyID = status.New(codes.Unknown, badger.ErrInvalidDataKeyID.Error()).Err()

	ErrInvalidEncryptionKey = status.New(codes.Unknown, badger.ErrInvalidEncryptionKey.Error()).Err()

	ErrGCInMemoryMode = status.New(codes.Unknown, badger.ErrGCInMemoryMode.Error()).Err()
)

fixme(leogr): review codes and fix/remove errors which do not make sense in this context, finally correct comments accordingly.

Functions

func AppendScoreToSet added in v0.8.1

func AppendScoreToSet(set []byte, score float64) []byte

AppendScore

func BuildSetKey added in v0.8.1

func BuildSetKey(key []byte, set []byte, score float64, index *schema.Index) (ik []byte)

BuildSetKey composes the key of the set {separator}{set}{separator}{score}{key}{bit index presence flag}{index}

func Bytes2float

func Bytes2float(bytes []byte) float64

Bytes2float ...

func Float642bytes

func Float642bytes(float float64) []byte

Float642bytes ...

func SetKeyScore added in v0.8.1

func SetKeyScore(key []byte, set []byte) (score float64)

SetKeyScore return the score of an item given key and set name

func UnwrapValueWithTS added in v0.8.1

func UnwrapValueWithTS(tsv []byte) ([]byte, uint64)

func UnwrapZIndexReference added in v0.8.1

func UnwrapZIndexReference(reference []byte) (key []byte, flag byte, idx uint64)

UnwrapZIndexReference returns the referenced key and the index of the key if provided in ZAdd or SafeZAdd operations

func WrapSeparatorToSet added in v0.8.1

func WrapSeparatorToSet(set []byte) []byte

WrapSeparatorToSet

func WrapValueWithTS added in v0.8.1

func WrapValueWithTS(v []byte, ts uint64) []byte

func WrapZIndexReference added in v0.8.1

func WrapZIndexReference(key []byte, index *schema.Index) []byte

WrapZIndexReference if index is not nil this method append to the key the timestamp at the end of the reference and a bit flag 1. If index is not provided it append a 0 uint64 and a bit flag 0. Flag is put at the end of the key to ensure lexicographical capabilities This is needed to maintain compatibility with solutions that are not using the resolution facilities with timestamp

Types

type Options

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

Options ...

func DefaultOptions

func DefaultOptions(path string, log logger.Logger) (Options, badger.Options)

DefaultOptions ...

type Store

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

Store ...

func Open

func Open(options Options, badgerOptions badger.Options) (*Store, error)

Open opens the store with the specified options

func (*Store) ByIndex

func (t *Store) ByIndex(index schema.Index) (item *schema.Item, err error)

ByIndex fetches the entry at the specified index

func (*Store) BySafeIndex

func (t *Store) BySafeIndex(options schema.SafeIndexOptions) (safeitem *schema.SafeItem, err error)

BySafeIndex fetches the entry at the specified index together with the inclusion proof for it and the consistency proof for the current root

func (*Store) Close

func (t *Store) Close() error

Close closes the store

func (*Store) ConsistencyProof

func (s *Store) ConsistencyProof(index schema.Index) (*schema.ConsistencyProof, error)

ConsistencyProof returns the consistency proof between the specified index and the current root

func (*Store) Count

func (t *Store) Count(prefix schema.KeyPrefix) (count *schema.ItemsCount, err error)

Count returns the number of entris having the specified key prefix

func (*Store) CountAll

func (t *Store) CountAll() (count uint64)

CountAll returns the total number of entries

func (*Store) CurrentRoot

func (t *Store) CurrentRoot() (root *schema.Root, err error)

CurrentRoot returns the index and the hash of the current tree root, if any. When the tree is empty and no root is available then the zerovalue for _schema.Root_ is returned instead.

func (*Store) DbSize

func (t *Store) DbSize() (int64, int64)

DbSize ...

func (*Store) Dump

func (t *Store) Dump(kvChan chan *pb.KVList) (err error)

Dump returns a dump of the database

func (*Store) ExecAllOps added in v0.8.1

func (t *Store) ExecAllOps(ops *schema.Ops, options ...WriteOption) (index *schema.Index, err error)

ExecAllOps like SetBatch it permits many insertions at once. The difference is that is possible to to specify a list of a mix of key value set and zAdd insertions. If zAdd reference is not yet present on disk it's possible to add it as a regular key value and the reference is done onFly

func (*Store) FlushToDisk

func (t *Store) FlushToDisk()

FlushToDisk flushes cached data from memory to disk

func (*Store) Get

func (t *Store) Get(key schema.Key) (item *schema.Item, err error)

Get fetches the entry having the specified key or resolve the reference with the specified key

func (*Store) GetReference added in v0.8.1

func (t *Store) GetReference(key schema.Key) (item *schema.Item, err error)

GetReference fetches the reference having the specified key or index

func (*Store) GetTree added in v0.6.1

func (t *Store) GetTree() *schema.Tree

GetTree returns a structure that rapresents merkle tree. Every node is marked as in memory, root and with reference key.

func (*Store) HealthCheck

func (t *Store) HealthCheck() bool

HealthCheck ...

func (*Store) History

func (t *Store) History(options *schema.HistoryOptions) (list *schema.ItemList, err error)

History fetches the complete history of entries for the specified key

func (*Store) IScan

func (t *Store) IScan(options schema.IScanOptions) (list *schema.Page, err error)

IScan iterates over all entries by the insertion order

func (*Store) InclusionProof

func (s *Store) InclusionProof(index schema.Index) (*schema.InclusionProof, error)

InclusionProof returns the inclusion proof of the specified index in the current tree

func (*Store) Reference

func (t *Store) Reference(refOpts *schema.ReferenceOptions, options ...WriteOption) (index *schema.Index, err error)

Reference adds a new entry who's value is an existing key If the ReferenceOption.index is not provided the resolution will use only the key and last version of the item will be returned If ReferenceOption.index is provided key is optional

func (*Store) Restore

func (t *Store) Restore(kvChan chan *pb.KVList) (i uint64, err error)

Restore restores a database

func (*Store) SafeGet

func (t *Store) SafeGet(options schema.SafeGetOptions) (safeItem *schema.SafeItem, err error)

SafeGet fetches the entry having the specified key together with the inclusion proof for it and the consistency proof for the current root

func (*Store) SafeGetReference added in v0.8.1

func (t *Store) SafeGetReference(options schema.SafeGetOptions) (safeItem *schema.SafeItem, err error)

SafeGetReference fetches the reference having the specified key or index together with the inclusion proof for it and the consistency proof for the current root

func (*Store) SafeReference

func (t *Store) SafeReference(options schema.SafeReferenceOptions) (proof *schema.Proof, err error)

SafeReference adds a reference entry to an existing key and returns the inclusion proof for it and the consistency proof for the previous root

func (*Store) SafeSet

func (t *Store) SafeSet(options schema.SafeSetOptions) (proof *schema.Proof, err error)

SafeSet adds an entry and returns the inclusion proof for it and the consistency proof for the previous root

func (*Store) SafeZAdd

func (t *Store) SafeZAdd(options schema.SafeZAddOptions) (proof *schema.Proof, err error)

SafeZAdd adds the specified score and key to a sorted set and returns the inclusion proof for it and the consistency proof for the previous root As a parameter of SafeZAddOptions is possible to provide the associated index of the provided key. In this way, when resolving reference, the specified version of the key will be returned. If the index is not provided the resolution will use only the key and last version of the item will be returned If SafeZAddOptions.Zopts.index is provided key is optional

func (*Store) Scan

func (t *Store) Scan(options schema.ScanOptions) (list *schema.ItemList, err error)

Scan fetch the entries having the specified key prefix

func (*Store) Set

func (t *Store) Set(kv schema.KeyValue, options ...WriteOption) (index *schema.Index, err error)

Set adds a new entry

func (*Store) SetBatch

func (t *Store) SetBatch(list schema.KVList, options ...WriteOption) (index *schema.Index, err error)

SetBatch adds many entries at once

func (*Store) Wait

func (t *Store) Wait()

Wait ...

func (*Store) ZAdd

func (t *Store) ZAdd(zaddOpts schema.ZAddOptions, options ...WriteOption) (index *schema.Index, err error)

ZAdd adds a score for an existing key in a sorted set As a parameter of ZAddOptions is possible to provide the associated index of the provided key. In this way, when resolving reference, the specified version of the key will be returned. If the index is not provided the resolution will use only the key and last version of the item will be returned If ZAddOptions.index is provided key is optional

func (*Store) ZScan

func (t *Store) ZScan(options schema.ZScanOptions) (list *schema.ZItemList, err error)

ZScan The SCAN command is used in order to incrementally iterate over a collection of elements.

type WriteOption

type WriteOption func(*WriteOptions)

WriteOption ...

func WithAsyncCommit

func WithAsyncCommit(async bool) WriteOption

WithAsyncCommit ...

type WriteOptions

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

WriteOptions ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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