package cache

import "github.com/google/trillian/storage/cache"

Package cache provides subtree caching functionality.

Package cache is a generated GoMock package.

Index

Functions

func PopulateLogTile

func PopulateLogTile(st *storagepb.SubtreeProto, hasher merkle.LogHasher) error

PopulateLogTile re-creates a log tile's InternalNodes from the Leaves map.

This uses the compact Merkle tree to repopulate internal nodes, and so will handle imperfect (but left-hand dense) subtrees. Note that we only rebuild internal nodes when the subtree is fully populated. For an explanation of why see the comments below for prepareLogTile.

TODO(pavelkalinnikov): Unexport it after the refactoring.

Types

type GetSubtreesFunc

type GetSubtreesFunc func(ids [][]byte) ([]*storagepb.SubtreeProto, error)

GetSubtreesFunc describes a function which can return a number of Subtrees from storage.

type MockNodeStorage

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

MockNodeStorage is a mock of NodeStorage interface.

func NewMockNodeStorage

func NewMockNodeStorage(ctrl *gomock.Controller) *MockNodeStorage

NewMockNodeStorage creates a new mock instance.

func (*MockNodeStorage) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockNodeStorage) GetSubtree

func (m *MockNodeStorage) GetSubtree(arg0 []byte) (*storagepb.SubtreeProto, error)

GetSubtree mocks base method.

type MockNodeStorageMockRecorder

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

MockNodeStorageMockRecorder is the mock recorder for MockNodeStorage.

func (*MockNodeStorageMockRecorder) GetSubtree

func (mr *MockNodeStorageMockRecorder) GetSubtree(arg0 interface{}) *gomock.Call

GetSubtree indicates an expected call of GetSubtree.

type NodeStorage

type NodeStorage interface {
	GetSubtree(prefix []byte) (*storagepb.SubtreeProto, error)
}

NodeStorage provides an interface for storing and retrieving subtrees.

type SubtreeCache

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

SubtreeCache provides a caching access to Subtree storage. Currently there are assumptions in the code that all subtrees are multiple of 8 in depth and that log subtrees are always of depth 8. It is not possible to just change the constants above and have things still work. This is because of issues like byte packing of node IDs.

SubtreeCache is not thread-safe: GetNodes, SetNodes and Flush methods must be called sequentially.

func NewLogSubtreeCache

func NewLogSubtreeCache(hasher merkle.LogHasher) *SubtreeCache

NewLogSubtreeCache creates and returns a SubtreeCache appropriate for use with a log tree. The caller must supply a suitable LogHasher.

func (*SubtreeCache) GetNodes

func (s *SubtreeCache) GetNodes(ids []compact.NodeID, getSubtrees GetSubtreesFunc) ([]tree.Node, error)

GetNodes returns the requested nodes, calling the getSubtrees function if they are not already cached.

func (*SubtreeCache) SetNodes

func (s *SubtreeCache) SetNodes(nodes []tree.Node, getSubtrees GetSubtreesFunc) error

SetNodes sets hashes for the given nodes in the cache.

func (*SubtreeCache) UpdatedTiles

func (s *SubtreeCache) UpdatedTiles() ([]*storagepb.SubtreeProto, error)

UpdatedTiles returns all updated tiles that need to be written to storage.

Source Files

gen.go layout.go log_tile.go mock_node_storage.go subtree_cache.go suffix.go

Version
v1.7.1 (latest)
Published
Jan 9, 2025
Platform
linux/amd64
Imports
15 packages
Last checked
5 days ago

Tools for package owners.