cache

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: Apache-2.0 Imports: 16 Imported by: 25

Documentation

Overview

Package cache provides subtree caching functionality.

Package cache is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogPopulateFunc

func LogPopulateFunc(hasher hashers.LogHasher) tree.PopulateSubtreeFunc

LogPopulateFunc obtains a log storage population function based on a supplied LogHasher. This is intended for use by storage utilities.

Types

type GetSubtreeFunc

type GetSubtreeFunc func(id tree.NodeID) (*storagepb.SubtreeProto, error)

GetSubtreeFunc describes a function which can return a Subtree from storage.

type GetSubtreesFunc

type GetSubtreesFunc func(ids []tree.NodeID) ([]*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 tree.NodeID) (*storagepb.SubtreeProto, error)

GetSubtree mocks base method

func (*MockNodeStorage) SetSubtrees

func (m *MockNodeStorage) SetSubtrees(arg0 context.Context, arg1 []*storagepb.SubtreeProto) error

SetSubtrees 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

func (*MockNodeStorageMockRecorder) SetSubtrees

func (mr *MockNodeStorageMockRecorder) SetSubtrees(arg0, arg1 interface{}) *gomock.Call

SetSubtrees indicates an expected call of SetSubtrees

type NodeStorage

type NodeStorage interface {
	GetSubtree(n tree.NodeID) (*storagepb.SubtreeProto, error)
	SetSubtrees(ctx context.Context, s []*storagepb.SubtreeProto) error
}

NodeStorage provides an interface for storing and retrieving subtrees.

type SetSubtreesFunc

type SetSubtreesFunc func(ctx context.Context, s []*storagepb.SubtreeProto) error

SetSubtreesFunc describes a function which can store a collection of Subtrees into storage.

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.

The cache is optimized for the following use-cases (see sync.Map type for more details):

  1. Parallel readers/writers working on non-intersecting subsets of subtrees/nodes.
  2. Subtrees/nodes are rarely written, and mostly read.

func NewLogSubtreeCache

func NewLogSubtreeCache(logStrata []int, hasher hashers.LogHasher) *SubtreeCache

NewLogSubtreeCache creates and returns a SubtreeCache appropriate for use with a log tree. The caller must supply the strata depths to be used and a suitable LogHasher.

func NewMapSubtreeCache

func NewMapSubtreeCache(mapStrata []int, treeID int64, hasher hashers.MapHasher) *SubtreeCache

NewMapSubtreeCache creates and returns a SubtreeCache appropriate for use with a map tree. The caller must supply the strata depths to be used, the treeID and a suitable MapHasher.

func NewSubtreeCache

func NewSubtreeCache(strataDepths []int, populateSubtree tree.PopulateSubtreeFunc, prepareSubtreeWrite tree.PrepareSubtreeWriteFunc) *SubtreeCache

NewSubtreeCache returns a newly intialised cache ready for use. populateSubtree is a function which knows how to populate a subtree's internal nodes given its leaves, and will be called for each subtree loaded from storage.

func (*SubtreeCache) Flush

func (s *SubtreeCache) Flush(ctx context.Context, setSubtrees SetSubtreesFunc) error

Flush causes the cache to write all dirty Subtrees back to storage.

func (*SubtreeCache) GetNodes

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

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

func (*SubtreeCache) SetNodeHash

func (s *SubtreeCache) SetNodeHash(id tree.NodeID, h []byte, getSubtree GetSubtreeFunc) error

SetNodeHash sets a node hash in the cache.

Jump to

Keyboard shortcuts

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