trie

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanHistory

func CleanHistory(ctx context.Context, back *Backend, startCommitNum, limitCommitNum uint32) error

CleanHistory cleans history nodes within [startCommitNum, limitCommitNum).

Types

type Backend

type Backend struct {
	Store    kv.Store
	Cache    *Cache
	LeafBank *LeafBank
	HistSpace,
	DedupedSpace byte
	HistPtnFactor,
	DedupedPtnFactor uint32
	CachedNodeTTL uint16
}

Backend is the backend of the trie.

type Cache

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

Cache is the cache layer for trie.

func NewCache

func NewCache(sizeMB int, rootCap int) *Cache

NewCache creates a cache object with the given cache size.

func (*Cache) AddNodeBlob

func (c *Cache) AddNodeBlob(name string, seq sequence, path []byte, blob []byte, isCommitting bool)

AddNodeBlob adds node blob into the cache.

func (*Cache) AddRootNode

func (c *Cache) AddRootNode(name string, n trie.Node) bool

AddRootNode add the root node into the cache.

func (*Cache) GetNodeBlob

func (c *Cache) GetNodeBlob(name string, seq sequence, path []byte, peek bool, dst []byte) []byte

GetNodeBlob returns the cached node blob.

func (*Cache) GetRootNode

func (c *Cache) GetRootNode(name string, seq uint64, peek bool) (trie.Node, bool)

GetRootNode returns the cached root node.

type LeafBank

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

LeafBank records accumulated trie leaves to help accelerate trie leaf access according to VIP-212.

func NewLeafBank

func NewLeafBank(store kv.Store, space byte, slotCap int) *LeafBank

NewLeafBank creates a new LeafBank instance. The slotCap indicates the capacity of cached per-trie slots.

func (*LeafBank) LogDeletions

func (b *LeafBank) LogDeletions(putter kv.Putter, name string, keys []string, commitNum uint32) error

LogDeletions saves the journal of leaf-key deletions which issued by one trie-commit.

func (*LeafBank) Lookup

func (b *LeafBank) Lookup(name string, leafKey []byte) (rec *LeafRecord, err error)

Lookup lookups a leaf record by the given leafKey for the trie named by name. LeafRecord.Leaf might be nil if the leaf can't be determined.

func (*LeafBank) NewUpdater

func (b *LeafBank) NewUpdater(name string, baseCommitNum, targetCommitNum uint32) (*LeafUpdater, error)

NewUpdater creates a leaf-updater for a trie slot with the given name.

type LeafRecord

type LeafRecord struct {
	*trie.Leaf
	CommitNum     uint32 // which commit number the leaf was committed
	SlotCommitNum uint32 // up to which commit number this leaf is valid
}

LeafRecord presents the queried leaf record.

type LeafUpdater

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

LeafUpdater helps to record trie leaves.

func (*LeafUpdater) Commit

func (u *LeafUpdater) Commit() error

Commit commits updates into leafbank.

func (*LeafUpdater) Update

func (u *LeafUpdater) Update(leafKey []byte, leaf *trie.Leaf, leafCommitNum uint32) error

Update updates the leaf for the given key.

type Trie

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

Trie is the managed trie.

func New

func New(
	back *Backend,
	name string,
	root thor.Bytes32,
	commitNum uint32,
	distinctNum uint32,
	nonCrypto bool,
) *Trie

New creates a managed trie.

func (*Trie) Copy

func (t *Trie) Copy() *Trie

Copy make a copy of this trie.

func (*Trie) DumpLeaves

func (t *Trie) DumpLeaves(ctx context.Context, baseCommitNum, targetCommitNum uint32, transform func(*trie.Leaf) *trie.Leaf) error

DumpLeaves dumps leaves in the range of [baseCommitNum, targetCommitNum] into leaf bank. transform transforms leaves before passing into leaf bank.

func (*Trie) DumpNodes

func (t *Trie) DumpNodes(ctx context.Context, baseCommitNum uint32, handleLeaf func(*trie.Leaf)) error

DumpNodes dumps referenced nodes committed within [baseCommitNum, thisCommitNum], into the deduped space.

func (*Trie) FastGet

func (t *Trie) FastGet(key []byte, steadyCommitNum uint32) ([]byte, []byte, error)

FastGet uses a fast way to query the value for key stored in the trie. See VIP-212 for detail.

func (*Trie) Get

func (t *Trie) Get(key []byte) ([]byte, []byte, error)

Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.

func (*Trie) Name

func (t *Trie) Name() string

Name returns the trie name.

func (*Trie) NodeIterator

func (t *Trie) NodeIterator(start []byte, baseCommitNum uint32) trie.NodeIterator

NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at the key after the given start key

func (*Trie) SetNoFillCache

func (t *Trie) SetNoFillCache(b bool)

SetNoFillCache enable or disable cache filling.

func (*Trie) Stage

func (t *Trie) Stage(newCommitNum, newDistinctNum uint32) (root thor.Bytes32, commit func() error)

Stage processes trie updates and calculates the new root hash.

func (*Trie) Update

func (t *Trie) Update(key, val, meta []byte) error

Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.

The value bytes must not be modified by the caller while they are stored in the trie.

Jump to

Keyboard shortcuts

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