burrow: github.com/hyperledger/burrow/storage Index | Files

package storage

import "github.com/hyperledger/burrow/storage"

Index

Package Files

forest.go key_format.go kvstore.go prefix.go prefix_db.go rwtree.go sort_order.go storage.pb.go tree.go

Constants

const (
    DelimiterSegmentLength = -1
    VariadicSegmentLength  = 0
)

Variables

var (
    ErrInvalidLengthStorage        = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowStorage          = fmt.Errorf("proto: integer overflow")
    ErrUnexpectedEndOfGroupStorage = fmt.Errorf("proto: unexpected end of group")
)

func AddTreePrintTree Uses

func AddTreePrintTree(edge string, tree treeprint.Tree, rwt KVCallbackIterableReader)

func CompareKeys Uses

func CompareKeys(k1, k2 []byte) int

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

func EnsureKeyFormatStore Uses

func EnsureKeyFormatStore(ks interface{}) ([][]byte, error)

Checks that a struct containing KeyFormat fields has no collisions on prefix and so acts as a sane 'KeyFormatStore'

func KeyOrder Uses

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 Uses

func NormaliseDomain(low, high []byte) ([]byte, []byte)

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

type ByteSlicable Uses

type ByteSlicable interface {
    Bytes() []byte
}

type CommitID Uses

type CommitID struct {
    Version              int64    `protobuf:"varint,1,opt,name=Version,proto3" json:"Version,omitempty"`
    Hash                 []byte   `protobuf:"bytes,2,opt,name=Hash,proto3" json:"Hash,omitempty"`
    XXX_NoUnkeyedLiteral struct{} `json:"-"`
    XXX_unrecognized     []byte   `json:"-"`
    XXX_sizecache        int32    `json:"-"`
}

This is the object that is stored in the leaves of the commitsTree - it captures the sub-tree hashes so that the commitsTree's hash becomes a mixture of the hashes of all the sub-trees.

func (*CommitID) Descriptor Uses

func (*CommitID) Descriptor() ([]byte, []int)

func (*CommitID) GetHash Uses

func (m *CommitID) GetHash() []byte

func (*CommitID) GetVersion Uses

func (m *CommitID) GetVersion() int64

func (*CommitID) Marshal Uses

func (m *CommitID) Marshal() (dAtA []byte, err error)

func (*CommitID) MarshalBinary Uses

func (cid *CommitID) MarshalBinary() ([]byte, error)

func (*CommitID) MarshalTo Uses

func (m *CommitID) MarshalTo(dAtA []byte) (int, error)

func (*CommitID) MarshalToSizedBuffer Uses

func (m *CommitID) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CommitID) ProtoMessage Uses

func (*CommitID) ProtoMessage()

func (*CommitID) Reset Uses

func (m *CommitID) Reset()

func (*CommitID) Size Uses

func (m *CommitID) Size() (n int)

func (CommitID) String Uses

func (cid CommitID) String() string

func (*CommitID) Unmarshal Uses

func (m *CommitID) Unmarshal(dAtA []byte) error

func (*CommitID) UnmarshalBinary Uses

func (cid *CommitID) UnmarshalBinary(data []byte) error

func (*CommitID) XXX_DiscardUnknown Uses

func (m *CommitID) XXX_DiscardUnknown()

func (*CommitID) XXX_Marshal Uses

func (m *CommitID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CommitID) XXX_Merge Uses

func (m *CommitID) XXX_Merge(src proto.Message)

func (*CommitID) XXX_MessageName Uses

func (*CommitID) XXX_MessageName() string

func (*CommitID) XXX_Size Uses

func (m *CommitID) XXX_Size() int

func (*CommitID) XXX_Unmarshal Uses

func (m *CommitID) XXX_Unmarshal(b []byte) error

type ForestOption Uses

type ForestOption func(*ImmutableForest)
var WithOverwriting ForestOption = func(imf *ImmutableForest) { imf.overwriting = true }

type ForestReader Uses

type ForestReader interface {
    Reader(prefix []byte) (KVCallbackIterableReader, error)
}

Access the read path of a forest

type ImmutableForest Uses

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

ImmutableForest contains much of the implementation for MutableForest yet it's external API is immutable

func NewImmutableForest Uses

func NewImmutableForest(commitsTree KVCallbackIterableReader, treeDB dbm.DB, cacheSize int,
    options ...ForestOption) (*ImmutableForest, error)

func (*ImmutableForest) Dump Uses

func (imf *ImmutableForest) Dump() string

func (*ImmutableForest) Iterate Uses

func (imf *ImmutableForest) Iterate(start, end []byte, ascending bool, fn func(prefix []byte, tree KVCallbackIterableReader) error) error

func (*ImmutableForest) Reader Uses

func (imf *ImmutableForest) Reader(prefix []byte) (KVCallbackIterableReader, error)

Get the tree at prefix for making reads

type ImmutableTree Uses

type ImmutableTree struct {
    *iavl.ImmutableTree
}

func (*ImmutableTree) Get Uses

func (imt *ImmutableTree) Get(key []byte) ([]byte, error)

func (*ImmutableTree) Has Uses

func (imt *ImmutableTree) Has(key []byte) (bool, error)

func (*ImmutableTree) Iterate Uses

func (imt *ImmutableTree) Iterate(start, end []byte, ascending bool, fn func(key []byte, value []byte) error) error

type KVCallbackIterable Uses

type KVCallbackIterable interface {
    // low must be lexicographically less than high. high is exclusive unless it is nil in which case it is inclusive.
    // ascending == false reverses order.
    Iterate(low, high []byte, ascending bool, fn func(key []byte, value []byte) error) error
}

Provides the native iteration for IAVLTree

type KVCallbackIterableReader Uses

type KVCallbackIterableReader interface {
    KVReader
    KVCallbackIterable
}

type KVIterable Uses

type KVIterable interface {
    // Iterator over a domain of keys in ascending order. high is exclusive.
    // low must be less than high, 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(low, high []byte) (KVIterator, error)

    // Iterator over a domain of keys in descending order. high is exclusive.
    //  must be less than high, 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(low, high []byte) (KVIterator, error)
}

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

type KVIterableReader Uses

type KVIterableReader interface {
    KVReader
    KVIterable
}

type KVIterator Uses

type KVIterator = dbm.Iterator

type KVReader Uses

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

type KVReaderWriter Uses

type KVReaderWriter interface {
    KVReader
    KVWriter
}

KVStore is a simple interface to get/set data

type KVStore Uses

type KVStore interface {
    KVReaderWriter
    KVIterable
}

type KVWriter Uses

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

type KeyFormat Uses

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

Provides a fixed-width lexicographically sortable []byte key format

func NewKeyFormat Uses

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 Uses

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 Uses

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

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 Uses

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 Uses

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) KeyNoPrefix Uses

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

Like Key but removes the prefix string

func (*KeyFormat) Layout Uses

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

func (*KeyFormat) NumSegments Uses

func (kf *KeyFormat) NumSegments() int

func (*KeyFormat) Prefix Uses

func (kf *KeyFormat) Prefix() Prefix

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

func (*KeyFormat) Scan Uses

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 Uses

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

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

func (*KeyFormat) ScanNoPrefix Uses

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

Like Scan but adds expects a key with the KeyFormat's prefix trimmed

func (*KeyFormat) String Uses

func (kf *KeyFormat) String() string

func (*KeyFormat) Unprefixed Uses

func (kf *KeyFormat) Unprefixed() *KeyFormat

type MustKeyFormat Uses

type MustKeyFormat struct {
    KeyFormat
}

MustKeyFormat for panicking early when a KeyFormat does not parse

func NewMustKeyFormat Uses

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

func (*MustKeyFormat) Fix Uses

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

func (*MustKeyFormat) Key Uses

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

func (*MustKeyFormat) KeyBytes Uses

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

func (*MustKeyFormat) KeyNoPrefix Uses

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

func (*MustKeyFormat) Unprefixed Uses

func (kf *MustKeyFormat) Unprefixed() *MustKeyFormat

type MutableForest Uses

type MutableForest struct {

    // Much of the implementation of MutableForest is contained in ImmutableForest which is embedded here and used
    // mutable via its private API. This embedded instance holds a reference to commitsTree above.
    *ImmutableForest
    // contains filtered or unexported fields
}

func NewMutableForest Uses

func NewMutableForest(db dbm.DB, cacheSize int) (*MutableForest, error)

func (*MutableForest) Delete Uses

func (muf *MutableForest) Delete(prefix []byte) (*CommitID, error)

Delete a tree - if the tree exists will return the CommitID of the latest saved version

func (*MutableForest) GetImmutable Uses

func (muf *MutableForest) GetImmutable(version int64) (*ImmutableForest, error)

func (*MutableForest) Hash Uses

func (muf *MutableForest) Hash() []byte

Get the current global hash for all trees in this forest

func (*MutableForest) IterateRWTree Uses

func (muf *MutableForest) IterateRWTree(start, end []byte, ascending bool, fn func(prefix []byte, tree *RWTree) error) error

func (*MutableForest) Load Uses

func (muf *MutableForest) Load(version int64) error

Load mutable forest from database

func (*MutableForest) Save Uses

func (muf *MutableForest) Save() (hash []byte, version int64, _ error)

func (*MutableForest) Version Uses

func (muf *MutableForest) Version() int64

Get the current global version for all versions of all trees in this forest

func (*MutableForest) Writer Uses

func (muf *MutableForest) Writer(prefix []byte) (*RWTree, error)

Calls to writer should be serialised as should writes to the tree

type MutableTree Uses

type MutableTree struct {
    *iavl.MutableTree
}

We wrap IAVL's tree types in order to implement standard DB interface and iteration helpers

func NewMutableTree Uses

func NewMutableTree(db dbm.DB, cacheSize int) (*MutableTree, error)

func (*MutableTree) Get Uses

func (mut *MutableTree) Get(key []byte) ([]byte, error)

func (*MutableTree) GetImmutable Uses

func (mut *MutableTree) GetImmutable(version int64) (*ImmutableTree, error)

func (*MutableTree) Has Uses

func (mut *MutableTree) Has(key []byte) (bool, error)

func (*MutableTree) Iterate Uses

func (mut *MutableTree) Iterate(start, end []byte, ascending bool, fn func(key []byte, value []byte) error) error

func (*MutableTree) IterateWriteTree Uses

func (mut *MutableTree) IterateWriteTree(start, end []byte, ascending bool, fn func(key []byte, value []byte) error) error

func (*MutableTree) Load Uses

func (mut *MutableTree) Load(version int64, overwriting bool) error

type Prefix Uses

type Prefix []byte

func NewPrefix Uses

func NewPrefix(bs []byte) Prefix

func (Prefix) Above Uses

func (p Prefix) Above() []byte

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

func (Prefix) Below Uses

func (p Prefix) Below() []byte

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

func (Prefix) CallbackIterable Uses

func (p Prefix) CallbackIterable(source KVCallbackIterable) *prefixCallbackIterable

func (Prefix) HexString Uses

func (p Prefix) HexString() string

func (Prefix) Iterable Uses

func (p Prefix) Iterable(source KVIterable) KVIterable

func (Prefix) Iterator Uses

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

func (Prefix) Key Uses

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

func (Prefix) Length Uses

func (p Prefix) Length() int

func (Prefix) Store Uses

func (p Prefix) Store(source KVStore) KVStore

func (Prefix) String Uses

func (p Prefix) String() string

func (Prefix) Suffix Uses

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

type PrefixDB Uses

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

func NewPrefixDB Uses

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

func (*PrefixDB) Close Uses

func (pdb *PrefixDB) Close() error

func (*PrefixDB) Delete Uses

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

func (*PrefixDB) DeleteSync Uses

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

func (*PrefixDB) Get Uses

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

DB implementation

func (*PrefixDB) Has Uses

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

func (*PrefixDB) Iterator Uses

func (pdb *PrefixDB) Iterator(low, high []byte) (KVIterator, error)

func (*PrefixDB) NewBatch Uses

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

func (*PrefixDB) Print Uses

func (pdb *PrefixDB) Print() error

func (*PrefixDB) ReverseIterator Uses

func (pdb *PrefixDB) ReverseIterator(low, high []byte) (KVIterator, error)

func (*PrefixDB) Set Uses

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

func (*PrefixDB) SetSync Uses

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

func (*PrefixDB) Stats Uses

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

type RWTree Uses

type RWTree struct {

    // Read-only tree serving previous state
    *ImmutableTree
    // contains filtered or unexported fields
}

RWTree provides an abstraction over IAVL that maintains separate read and write paths. Reads are routed to the most recently saved version of the tree - which provides immutable access. Writes are routed to a working tree that is mutable. On save the working tree is saved to DB, frozen, and replaces the previous immutable read tree.

func NewRWTree Uses

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

Creates a concurrency safe version of an IAVL tree whereby reads are routed to the last saved tree. Writes must be serialised (as they are within a commit for example).

func (*RWTree) Delete Uses

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

func (*RWTree) Dump Uses

func (rwt *RWTree) Dump() string

func (*RWTree) GetImmutable Uses

func (rwt *RWTree) GetImmutable(version int64) (*ImmutableTree, error)

func (*RWTree) IterateWriteTree Uses

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

func (*RWTree) Load Uses

func (rwt *RWTree) Load(version int64, overwriting bool) error

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

func (*RWTree) Save Uses

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

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

func (*RWTree) Set Uses

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

func (*RWTree) Updated Uses

func (rwt *RWTree) Updated() bool

Returns true if there have been any writes since last save

type SortOrder Uses

type SortOrder byte
const (
    AscendingSort SortOrder = iota
    DescendingSort
)

Package storage imports 16 packages (graph) and is imported by 16 packages. Updated 2020-04-26. Refresh now. Tools for package owners.