iavl

package module
v2.0.0-...-f0c4102 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorExportDone = fmt.Errorf("export done")

Functions

func EncodeBytes

func EncodeBytes(w io.Writer, bz []byte) error

func FindDbsInPath

func FindDbsInPath(path string) ([]string, error)

func NewIngestSnapshotConnection

func NewIngestSnapshotConnection(snapshotDbPath string) (*sqlite3.Conn, error)

Types

type Exporter

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

func (*Exporter) Next

func (e *Exporter) Next() (*SnapshotNode, error)

type Iterator

type Iterator interface {
	// Domain returns the start (inclusive) and end (exclusive) limits of the iterator.
	// CONTRACT: start, end readonly []byte
	Domain() (start []byte, end []byte)

	// Valid returns whether the current iterator is valid. Once invalid, the TreeIterator remains
	// invalid forever.
	Valid() bool

	// Next moves the iterator to the next key in the database, as defined by order of iteration.
	// If Valid returns false, this method will panic.
	Next()

	// Key returns the key at the current position. Panics if the iterator is invalid.
	// CONTRACT: key readonly []byte
	Key() (key []byte)

	// Value returns the value at the current position. Panics if the iterator is invalid.
	// CONTRACT: value readonly []byte
	Value() (value []byte)

	// Error returns the last error encountered by the iterator, if any.
	Error() error

	// Close closes the iterator, relasing any allocated resources.
	Close() error
}

type LeafIterator

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

func (*LeafIterator) Close

func (l *LeafIterator) Close() error

func (*LeafIterator) Domain

func (l *LeafIterator) Domain() (start []byte, end []byte)

func (*LeafIterator) Error

func (l *LeafIterator) Error() error

func (*LeafIterator) Key

func (l *LeafIterator) Key() (key []byte)

func (*LeafIterator) Next

func (l *LeafIterator) Next()

func (*LeafIterator) Valid

func (l *LeafIterator) Valid() bool

func (*LeafIterator) Value

func (l *LeafIterator) Value() (value []byte)

type MultiTree

type MultiTree struct {
	Trees map[string]*Tree
	// contains filtered or unexported fields
}

MultiTree encapsulates multiple IAVL trees, each with its own "store key" in the context of the Cosmos SDK. Within IAVL v2 is only used to test the IAVL v2 implementation, and for import/export of IAVL v2 state.

func ImportMultiTree

func ImportMultiTree(pool *NodePool, version int64, path string, treeOpts TreeOptions) (*MultiTree, error)

func NewMultiTree

func NewMultiTree(rootPath string, opts TreeOptions) *MultiTree

func (*MultiTree) Close

func (mt *MultiTree) Close() error

func (*MultiTree) Hash

func (mt *MultiTree) Hash() []byte

Hash is a stand in for code at https://github.com/cosmos/cosmos-sdk/blob/80dd55f79bba8ab675610019a5764470a3e2fef9/store/types/commit_info.go#L30 it used in testing. App chains should use the store hashing code referenced above instead.

func (*MultiTree) LoadVersion

func (mt *MultiTree) LoadVersion(version int64) error

func (*MultiTree) MountTree

func (mt *MultiTree) MountTree(storeKey string) error

func (*MultiTree) MountTrees

func (mt *MultiTree) MountTrees() error

func (*MultiTree) QueryReport

func (mt *MultiTree) QueryReport(bins int) error

func (*MultiTree) SaveVersion

func (mt *MultiTree) SaveVersion() ([]byte, int64, error)

func (*MultiTree) SaveVersionConcurrently

func (mt *MultiTree) SaveVersionConcurrently() ([]byte, int64, error)

func (*MultiTree) SnapshotConcurrently

func (mt *MultiTree) SnapshotConcurrently() error

func (*MultiTree) WarmLeaves

func (mt *MultiTree) WarmLeaves() error

type Node

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

Node represents a node in a Tree.

func IngestSnapshot

func IngestSnapshot(conn *sqlite3.Conn, prefix string, version int64, nextFn func() (*SnapshotNode, error)) (*Node, error)

func MakeNode

func MakeNode(pool *NodePool, nodeKey NodeKey, buf []byte) (*Node, error)

MakeNode constructs a *Node from an encoded byte slice.

func (*Node) Bytes

func (node *Node) Bytes() ([]byte, error)

func (*Node) GetHash

func (node *Node) GetHash() []byte

func (*Node) String

func (node *Node) String() string

func (*Node) WriteBytes

func (node *Node) WriteBytes(w io.Writer) error

type NodeKey

type NodeKey [12]byte

NodeKey represents a key of node in the DB.

func NewNodeKey

func NewNodeKey(version int64, sequence uint32) NodeKey

func (NodeKey) IsEmpty

func (nk NodeKey) IsEmpty() bool

func (NodeKey) Sequence

func (nk NodeKey) Sequence() uint32

func (NodeKey) String

func (nk NodeKey) String() string

String returns a string representation of the node key.

func (NodeKey) Version

func (nk NodeKey) Version() int64

type NodePool

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

func NewNodePool

func NewNodePool() *NodePool

func (*NodePool) Get

func (np *NodePool) Get() *Node

func (*NodePool) Put

func (np *NodePool) Put(node *Node)

type SnapshotNode

type SnapshotNode struct {
	Key     []byte
	Value   []byte
	Version int64
	Height  int8
}

type SnapshotOptions

type SnapshotOptions struct {
	StoreLeafValues   bool
	WriteCheckpoint   bool
	DontWriteSnapshot bool
	TraverseOrder     TraverseOrderType
}

type SqliteDb

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

func NewInMemorySqliteDb

func NewInMemorySqliteDb(pool *NodePool) (*SqliteDb, error)

func NewSqliteDb

func NewSqliteDb(pool *NodePool, opts SqliteDbOptions) (*SqliteDb, error)

func (*SqliteDb) Close

func (sql *SqliteDb) Close() error

func (*SqliteDb) Get

func (sql *SqliteDb) Get(nodeKey NodeKey) (*Node, error)

func (*SqliteDb) GetLatestLeaf

func (sql *SqliteDb) GetLatestLeaf(key []byte) ([]byte, error)

func (*SqliteDb) ImportMostRecentSnapshot

func (sql *SqliteDb) ImportMostRecentSnapshot(targetVersion int64, traverseOrder TraverseOrderType, loadLeaves bool) (*Node, int64, error)

func (*SqliteDb) ImportSnapshotFromTable

func (sql *SqliteDb) ImportSnapshotFromTable(version int64, traverseOrder TraverseOrderType, loadLeaves bool) (*Node, error)

func (*SqliteDb) LoadRoot

func (sql *SqliteDb) LoadRoot(version int64) (*Node, error)

func (*SqliteDb) ResetShardQueries

func (sql *SqliteDb) ResetShardQueries() error

func (*SqliteDb) Revert

func (sql *SqliteDb) Revert(version int) error

func (*SqliteDb) SaveRoot

func (sql *SqliteDb) SaveRoot(version int64, node *Node, isCheckpoint bool) error

func (*SqliteDb) Snapshot

func (sql *SqliteDb) Snapshot(ctx context.Context, tree *Tree) error

func (*SqliteDb) WarmLeaves

func (sql *SqliteDb) WarmLeaves() error

func (*SqliteDb) WriteLatestLeaves

func (sql *SqliteDb) WriteLatestLeaves(tree *Tree) (err error)

func (*SqliteDb) WriteSnapshot

func (sql *SqliteDb) WriteSnapshot(
	ctx context.Context, version int64, nextFn func() (*SnapshotNode, error), opts SnapshotOptions,
) (*Node, error)

type SqliteDbOptions

type SqliteDbOptions struct {
	Path       string
	Mode       int
	MmapSize   uint64
	WalSize    int
	CacheSize  int
	ConnArgs   string
	ShardTrees bool
	// contains filtered or unexported fields
}

func (SqliteDbOptions) EstimateMmapSize

func (opts SqliteDbOptions) EstimateMmapSize() (uint64, error)

type SqliteKVStore

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

SqliteKVStore is a generic KV store which uses sqlite as the backend and be used by applications to store and retrieve generic key-value pairs, probably for metadata.

func NewSqliteKVStore

func NewSqliteKVStore(opts SqliteDbOptions) (kv *SqliteKVStore, err error)

func (*SqliteKVStore) Delete

func (kv *SqliteKVStore) Delete(key []byte) error

func (*SqliteKVStore) Get

func (kv *SqliteKVStore) Get(key []byte) (value []byte, err error)

func (*SqliteKVStore) Set

func (kv *SqliteKVStore) Set(key []byte, value []byte) error

type TraverseOrderType

type TraverseOrderType uint8

TraverseOrderType is the type of the order in which the tree is traversed.

const (
	PreOrder TraverseOrderType = iota
	PostOrder
)

type Tree

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

func NewTree

func NewTree(sql *SqliteDb, pool *NodePool, opts TreeOptions) *Tree

func (*Tree) Close

func (tree *Tree) Close() error

func (*Tree) DeleteVersionsTo

func (tree *Tree) DeleteVersionsTo(toVersion int64) error

func (*Tree) Export

func (tree *Tree) Export(order TraverseOrderType) *Exporter

func (*Tree) Get

func (tree *Tree) Get(key []byte) ([]byte, error)

func (*Tree) Has

func (tree *Tree) Has(key []byte) (bool, error)

func (*Tree) Hash

func (tree *Tree) Hash() []byte

func (*Tree) Height

func (tree *Tree) Height() int8

func (*Tree) Iterator

func (tree *Tree) Iterator(start, end []byte, inclusive bool) (itr Iterator, err error)

func (*Tree) LoadSnapshot

func (tree *Tree) LoadSnapshot(version int64, traverseOrder TraverseOrderType) (err error)

func (*Tree) LoadVersion

func (tree *Tree) LoadVersion(version int64) (err error)

func (*Tree) NewNode

func (tree *Tree) NewNode(key []byte, value []byte) *Node

NewNode returns a new node from a key, value and version.

func (*Tree) Remove

func (tree *Tree) Remove(key []byte) ([]byte, bool, error)

Remove removes a key from the working tree. The given key byte slice should not be modified after this call, since it may point to data stored inside IAVL.

func (*Tree) ReverseIterator

func (tree *Tree) ReverseIterator(start, end []byte) (itr Iterator, err error)

func (*Tree) SaveSnapshot

func (tree *Tree) SaveSnapshot() (err error)

func (*Tree) SaveVersion

func (tree *Tree) SaveVersion() ([]byte, int64, error)

func (*Tree) Set

func (tree *Tree) Set(key, value []byte) (updated bool, err error)

Set sets a key in the working tree. Nil values are invalid. The given key/value byte slices must not be modified after this call, since they point to slices stored within IAVL. It returns true when an existing value was updated, while false means it was a new key.

func (*Tree) SetShouldCheckpoint

func (tree *Tree) SetShouldCheckpoint()

func (*Tree) Size

func (tree *Tree) Size() int64

func (*Tree) Version

func (tree *Tree) Version() int64

func (*Tree) WorkingBytes

func (tree *Tree) WorkingBytes() uint64

func (*Tree) WriteLatestLeaves

func (tree *Tree) WriteLatestLeaves() (err error)

type TreeIterator

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

func (*TreeIterator) Close

func (i *TreeIterator) Close() error

func (*TreeIterator) Domain

func (i *TreeIterator) Domain() (start []byte, end []byte)

func (*TreeIterator) Error

func (i *TreeIterator) Error() error

func (*TreeIterator) Key

func (i *TreeIterator) Key() (key []byte)

func (*TreeIterator) Next

func (i *TreeIterator) Next()

func (*TreeIterator) Valid

func (i *TreeIterator) Valid() bool

func (*TreeIterator) Value

func (i *TreeIterator) Value() (value []byte)

type TreeOptions

type TreeOptions struct {
	CheckpointInterval int64
	CheckpointMemory   uint64
	StateStorage       bool
	HeightFilter       int8
	EvictionDepth      int8
	MetricsProxy       metrics.Proxy
}

func DefaultTreeOptions

func DefaultTreeOptions() TreeOptions

type VersionRange

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

func (*VersionRange) Add

func (r *VersionRange) Add(version int64) error

func (*VersionRange) Find

func (r *VersionRange) Find(version int64) int64

Find returns the shard that contains the given version by binary searching the version range. If the version is after the last shard, -1 is returned.

func (*VersionRange) FindMemoized

func (r *VersionRange) FindMemoized(version int64) int64

func (*VersionRange) FindPrevious

func (r *VersionRange) FindPrevious(version int64) int64

func (*VersionRange) Last

func (r *VersionRange) Last() int64

func (*VersionRange) Len

func (r *VersionRange) Len() int

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

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