storage

package
v0.23.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const VariadicSegmentLength = 0

Variables

This section is empty.

Functions

func CompareKeys

func CompareKeys(k1, k2 []byte) int

Sorts the keys as if they were compared lexicographically with their KeyOrder prepended

func KeyOrder

func KeyOrder(key []byte) int

KeyOrder maps []byte{} -> -1, []byte(nil) -> 1, and everything else to 0. This encodes the assumptions of the KVIterator domain endpoints

func NormaliseDomain

func NormaliseDomain(start, end []byte, reverse bool) ([]byte, []byte)

NormaliseDomain encodes the assumption that when nil is used as a lower bound is interpreted as low rather than high

func Uniq

func Uniq(source KVIterator) *uniqueIterator

Types

type ByteSlicable

type ByteSlicable interface {
	Bytes() []byte
}

type CacheDB

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

func NewCacheDB

func NewCacheDB(backend KVIterableReader) *CacheDB

func (*CacheDB) Close

func (cdb *CacheDB) Close()

func (*CacheDB) Commit

func (cdb *CacheDB) Commit(writer KVWriter)

func (*CacheDB) Delete

func (cdb *CacheDB) Delete(key []byte)

func (*CacheDB) DeleteSync

func (cdb *CacheDB) DeleteSync(key []byte)

func (*CacheDB) Get

func (cdb *CacheDB) Get(key []byte) []byte

DB implementation

func (*CacheDB) Has

func (cdb *CacheDB) Has(key []byte) bool

func (*CacheDB) Iterator

func (cdb *CacheDB) Iterator(start, end []byte) KVIterator

func (*CacheDB) NewBatch

func (cdb *CacheDB) NewBatch() dbm.Batch

func (*CacheDB) Print

func (cdb *CacheDB) Print()

func (*CacheDB) ReverseIterator

func (cdb *CacheDB) ReverseIterator(start, end []byte) KVIterator

func (*CacheDB) Set

func (cdb *CacheDB) Set(key, value []byte)

func (*CacheDB) SetSync

func (cdb *CacheDB) SetSync(key, value []byte)

func (*CacheDB) Stats

func (cdb *CacheDB) Stats() map[string]string

type ChannelIterator

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

func NewChannelIterator

func NewChannelIterator(ch <-chan KVPair, start, end []byte) *ChannelIterator

ChannelIterator wraps a stream of kvp KVPairs over a channel as a stateful KVIterator. The start and end keys provided are purely indicative (for Domain()) and are assumed to be honoured by the input channel - they are not checked and keys are not sorted. NewChannelIterator will block until the first value is received over the channel.

func (*ChannelIterator) Close

func (it *ChannelIterator) Close()

func (*ChannelIterator) Domain

func (it *ChannelIterator) Domain() ([]byte, []byte)

func (*ChannelIterator) Key

func (it *ChannelIterator) Key() []byte

func (*ChannelIterator) Next

func (it *ChannelIterator) Next()

func (*ChannelIterator) Valid

func (it *ChannelIterator) Valid() bool

func (*ChannelIterator) Value

func (it *ChannelIterator) Value() []byte

type ContentAddressedStore

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

func NewContentAddressedStore

func NewContentAddressedStore(db dbm.DB) *ContentAddressedStore

func (*ContentAddressedStore) Get

func (cas *ContentAddressedStore) Get(hash []byte) ([]byte, error)

func (*ContentAddressedStore) Put

func (cas *ContentAddressedStore) Put(data []byte) ([]byte, error)

Put data in the database by saving data with a key that is its sha256 hash

type KVCache

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

func NewKVCache

func NewKVCache() *KVCache

Creates an in-memory cache wrapping a map that stores the provided tombstone value for deleted keys

func (*KVCache) Delete

func (kvc *KVCache) Delete(key []byte)

func (*KVCache) Get

func (kvc *KVCache) Get(key []byte) []byte

func (*KVCache) Has

func (kvc *KVCache) Has(key []byte) bool

func (*KVCache) Info

func (kvc *KVCache) Info(key []byte) (value []byte, deleted bool)

func (*KVCache) Iterator

func (kvc *KVCache) Iterator(start, end []byte) KVIterator

func (*KVCache) Reset

func (kvc *KVCache) Reset()

func (*KVCache) ReverseIterator

func (kvc *KVCache) ReverseIterator(start, end []byte) KVIterator

func (*KVCache) Set

func (kvc *KVCache) Set(key, value []byte)

func (*KVCache) SortedKeys

func (kvc *KVCache) SortedKeys(reverse bool) [][]byte

func (*KVCache) SortedKeysInDomain

func (kvc *KVCache) SortedKeysInDomain(start, end []byte) [][]byte

func (*KVCache) WriteTo

func (kvi *KVCache) WriteTo(writer KVWriter)

Writes contents of cache to backend without flushing the cache

type KVCacheIterator

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

func (*KVCacheIterator) Close

func (kvi *KVCacheIterator) Close()

func (*KVCacheIterator) Domain

func (kvi *KVCacheIterator) Domain() ([]byte, []byte)

func (*KVCacheIterator) Info

func (kvi *KVCacheIterator) Info() (key, value []byte, deleted bool)

func (*KVCacheIterator) Key

func (kvi *KVCacheIterator) Key() []byte

func (*KVCacheIterator) Next

func (kvi *KVCacheIterator) Next()

func (*KVCacheIterator) Valid

func (kvi *KVCacheIterator) Valid() bool

func (*KVCacheIterator) Value

func (kvi *KVCacheIterator) Value() []byte

type KVCascade

type KVCascade []KVIterableReader

func (KVCascade) Get

func (kvc KVCascade) Get(key []byte) []byte

func (KVCascade) Has

func (kvc KVCascade) Has(key []byte) bool

func (KVCascade) Iterator

func (kvc KVCascade) Iterator(start, end []byte) KVIterator

func (KVCascade) ReverseIterator

func (kvc KVCascade) ReverseIterator(start, end []byte) KVIterator

type KVIterable

type KVIterable interface {
	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	Iterator(start, end []byte) KVIterator

	// Iterator over a domain of keys in descending order. End is exclusive.
	// Start must be greater than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	ReverseIterator(start, end []byte) KVIterator
}

This is partially extrated from Cosmos SDK for alignment but is more minimal, we should suggest this becomes an embedded interface

type KVIterableReader

type KVIterableReader interface {
	KVReader
	KVIterable
}

type KVIterator

type KVIterator = dbm.Iterator

type KVPair

type KVPair struct {
	Key   []byte
	Value []byte
}

func (KVPair) String

func (kv KVPair) String() string

type KVPairs

type KVPairs []KVPair

func (KVPairs) Len

func (kvp KVPairs) Len() int

func (KVPairs) Less

func (kvp KVPairs) Less(i, j int) bool

func (KVPairs) Sorted

func (kvp KVPairs) Sorted() KVPairs

func (KVPairs) Swap

func (kvp KVPairs) Swap(i, j int)

type KVReader

type KVReader interface {
	// Get returns nil iff key doesn't exist. Panics on nil key.
	Get(key []byte) []byte
	// Has checks if a key exists. Panics on nil key.
	Has(key []byte) bool
}

type KVReaderWriter

type KVReaderWriter interface {
	KVReader
	KVWriter
}

KVStore is a simple interface to get/set data

type KVStore

type KVStore interface {
	KVReaderWriter
	KVIterable
}

type KVWriter

type KVWriter interface {
	// Set sets the key. Panics on nil key.
	Set(key, value []byte)
	// Delete deletes the key. Panics on nil key.
	Delete(key []byte)
}

type KeyFormat

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

Provides a fixed-width lexicograph}ically sortable []byte key format

func NewKeyFormat

func NewKeyFormat(prefix string, layout ...int) (*KeyFormat, error)

Create a []byte key format based on a single byte prefix and fixed width key segments each of whose length is specified by by the corresponding element of layout. A final segment length of 0 can be used to indicate a variadic final element that may be of arbitrary length.

For example, to store keys that could index some objects by a version number and their SHA256 hash using the form: 'c<version uint64><hash [32]byte>' then you would define the KeyFormat with:

var keyFormat = NewKeyFormat('c', 8, 32)

Then you can create a key with:

func ObjectKey(version uint64, objectBytes []byte) []byte {
	hasher := sha256.New()
	hasher.Sum(nil)
	return keyFormat.Key(version, hasher.Sum(nil))
}}

func (*KeyFormat) Fix

func (kf *KeyFormat) Fix(args ...interface{}) (*KeyFormat, error)

Fixes the first args many segments as the prefix of a new KeyFormat by using the args to generate a key that becomes that prefix. Any remaining unassigned segments become the layout of the new KeyFormat.

func (*KeyFormat) Iterator

func (kf *KeyFormat) Iterator(iterable KVIterable, start, end []byte, reverse ...bool) KVIterator

Returns an iterator over the underlying iterable using this KeyFormat's prefix. This is to support proper iteration over the prefix in the presence of nil start or end which requests iteration to the inclusive edges of the domain. An optional argument for reverse can be passed to get reverse iteration.

func (*KeyFormat) Key

func (kf *KeyFormat) Key(args ...interface{}) ([]byte, error)

Format the args passed into the key format - will panic if the arguments passed do not match the length of the segment to which they correspond. When called with no arguments returns the raw prefix (useful as a start element of the entire keys space when sorted lexicographically).

func (*KeyFormat) KeyBytes

func (kf *KeyFormat) KeyBytes(segments ...[]byte) ([]byte, error)

Format the byte segments into the key format - will panic if the segment lengths do not match the layout.

func (*KeyFormat) Layout

func (kf *KeyFormat) Layout() []int

func (*KeyFormat) NumSegments

func (kf *KeyFormat) NumSegments() int

func (*KeyFormat) Prefix

func (kf *KeyFormat) Prefix(args ...interface{}) (Prefix, error)

Return the Key as a prefix - may just be the literal prefix, or an entire key

func (*KeyFormat) Scan

func (kf *KeyFormat) Scan(key []byte, args ...interface{}) error

Extracts the segments into the values pointed to by each of args. Each arg must be a pointer to int64, uint64, or []byte, and the width of the args must match layout.

func (*KeyFormat) ScanBytes

func (kf *KeyFormat) ScanBytes(key []byte) [][]byte

Reads out the bytes associated with each segment of the key format from key.

func (*KeyFormat) String

func (kf *KeyFormat) String() string

func (*KeyFormat) Suffix

func (kf *KeyFormat) Suffix(args ...interface{}) (Prefix, error)

func (*KeyFormat) Unprefixed

func (kf *KeyFormat) Unprefixed() *KeyFormat

type MultiIterator

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

func NewMultiIterator

func NewMultiIterator(reverse bool, iterators ...KVIterator) *MultiIterator

MultiIterator iterates in order over a series o

func (*MultiIterator) Close

func (mi *MultiIterator) Close()

func (*MultiIterator) Domain

func (mi *MultiIterator) Domain() ([]byte, []byte)

func (*MultiIterator) Key

func (mi *MultiIterator) Key() []byte

func (*MultiIterator) Len

func (mi *MultiIterator) Len() int

sort.Interface implementation

func (*MultiIterator) Less

func (mi *MultiIterator) Less(i, j int) bool

func (*MultiIterator) Next

func (mi *MultiIterator) Next()

func (*MultiIterator) Peek

func (mi *MultiIterator) Peek() KVIterator

func (*MultiIterator) Pop

func (mi *MultiIterator) Pop() interface{}

func (*MultiIterator) Push

func (mi *MultiIterator) Push(x interface{})

func (*MultiIterator) Swap

func (mi *MultiIterator) Swap(i, j int)

func (*MultiIterator) Valid

func (mi *MultiIterator) Valid() bool

func (*MultiIterator) Value

func (mi *MultiIterator) Value() []byte

type MustKeyFormat

type MustKeyFormat struct {
	KeyFormat
}

func NewMustKeyFormat

func NewMustKeyFormat(prefix string, layout ...int) *MustKeyFormat

func (*MustKeyFormat) Fix

func (kf *MustKeyFormat) Fix(args ...interface{}) *MustKeyFormat

func (*MustKeyFormat) Key

func (kf *MustKeyFormat) Key(args ...interface{}) []byte

func (*MustKeyFormat) KeyBytes

func (kf *MustKeyFormat) KeyBytes(segments ...[]byte) []byte

func (*MustKeyFormat) Prefix

func (kf *MustKeyFormat) Prefix(args ...interface{}) Prefix

func (*MustKeyFormat) Scan

func (kf *MustKeyFormat) Scan(key []byte, args ...interface{})

func (*MustKeyFormat) Suffix

func (kf *MustKeyFormat) Suffix(args ...interface{}) Prefix

type Prefix

type Prefix []byte

func NewPrefix

func NewPrefix(p string) Prefix

func (Prefix) Above

func (p Prefix) Above() []byte

Get the lexicographical sibling above this prefix (i.e. the fixed length integer plus one)

func (Prefix) Below

func (p Prefix) Below() []byte

Get the lexicographical sibling below this prefix (i.e. the fixed length integer minus one)

func (Prefix) HexString

func (p Prefix) HexString() string

func (Prefix) Iterable

func (p Prefix) Iterable(source KVIterable) KVIterable

func (Prefix) Iterator

func (p Prefix) Iterator(iteratorFn func(start, end []byte) dbm.Iterator, start, end []byte) KVIterator

func (Prefix) Key

func (p Prefix) Key(key []byte) []byte

func (Prefix) Length

func (p Prefix) Length() int

func (Prefix) ReverseIterator

func (p Prefix) ReverseIterator(iteratorFn func(start, end []byte) dbm.Iterator, start, end []byte) KVIterator

func (Prefix) Store

func (p Prefix) Store(source KVStore) KVStore

func (Prefix) String

func (p Prefix) String() string

func (Prefix) Suffix

func (p Prefix) Suffix(key []byte) []byte

type PrefixDB

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

func NewPrefixDB

func NewPrefixDB(db dbm.DB, prefix string) *PrefixDB

func (*PrefixDB) Close

func (pdb *PrefixDB) Close()

func (*PrefixDB) Delete

func (pdb *PrefixDB) Delete(key []byte)

func (*PrefixDB) DeleteSync

func (pdb *PrefixDB) DeleteSync(key []byte)

func (*PrefixDB) Get

func (pdb *PrefixDB) Get(key []byte) []byte

DB implementation

func (*PrefixDB) Has

func (pdb *PrefixDB) Has(key []byte) bool

func (*PrefixDB) Iterator

func (pdb *PrefixDB) Iterator(start, end []byte) dbm.Iterator

func (*PrefixDB) NewBatch

func (pdb *PrefixDB) NewBatch() dbm.Batch

func (*PrefixDB) Print

func (pdb *PrefixDB) Print()

func (*PrefixDB) ReverseIterator

func (pdb *PrefixDB) ReverseIterator(start, end []byte) dbm.Iterator

func (*PrefixDB) Set

func (pdb *PrefixDB) Set(key, value []byte)

func (*PrefixDB) SetSync

func (pdb *PrefixDB) SetSync(key, value []byte)

func (*PrefixDB) Stats

func (pdb *PrefixDB) Stats() map[string]string

type RWTree

type RWTree struct {
	// Values not reassigned
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRWTree

func NewRWTree(db dbm.DB, cacheSize int) *RWTree

func (*RWTree) Delete

func (rwt *RWTree) Delete(key []byte)

func (*RWTree) Get

func (rwt *RWTree) Get(key []byte) []byte

func (*RWTree) Has

func (rwt *RWTree) Has(key []byte) bool

func (*RWTree) Hash

func (rwt *RWTree) Hash() []byte

func (*RWTree) IterateRange

func (rwt *RWTree) IterateRange(start, end []byte, ascending bool, fn func(key []byte, value []byte) bool) (stopped bool)

func (*RWTree) Iterator

func (rwt *RWTree) Iterator(start, end []byte) dbm.Iterator

func (*RWTree) Load

func (rwt *RWTree) Load(version int64) error

Tries to load the execution state from DB, returns nil with no error if no state found

func (*RWTree) ReverseIterator

func (rwt *RWTree) ReverseIterator(start, end []byte) dbm.Iterator

func (*RWTree) Save

func (rwt *RWTree) Save() ([]byte, int64, error)

Save the current write tree making writes accessible from read tree.

func (*RWTree) Set

func (rwt *RWTree) Set(key, value []byte)

type Trie

type Trie struct {
	Root *TrieNode
}

func NewTrie

func NewTrie() *Trie

type TrieNode

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

func (*TrieNode) Insert

func (tn *TrieNode) Insert(key, value []byte)

Jump to

Keyboard shortcuts

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