pebble

package
v0.34.0-crescendo-prev... Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MinLookupKeyLen defines the minimum length for a valid lookup key
	//
	// Lookup keys use the following format:
	//     [code] [owner] / [key] / [height]
	// Where:
	// - code: 1 byte indicating the type of data stored
	// - owner: optional variable length field
	// - key: optional variable length field
	// - height: 8 bytes representing the block height (uint64)
	// - separator: '/' is used to separate variable length fields (required 2)
	//
	// Therefore the minimum key would be 3 bytes + # of bytes for height
	//     [code] / / [height]
	MinLookupKeyLen = 3 + registers.HeightSuffixLen
)

Variables

View Source
var ErrAlreadyBootstrapped = errors.New("found latest key set on badger instance, DB is already bootstrapped")

ErrAlreadyBootstrapped is the sentinel error for an already bootstrapped pebble instance

Functions

func DefaultPebbleOptions

func DefaultPebbleOptions(cache *pebble.Cache, comparer *pebble.Comparer) *pebble.Options

DefaultPebbleOptions returns an optimized set of pebble options. This is mostly copied form pebble's nightly performance benchmark.

func IsBootstrapped

func IsBootstrapped(db *pebble.DB) (bool, error)

IsBootstrapped returns true if the db is bootstrapped otherwise return false it returns error if the db is corrupted or other exceptions

func NewBootstrappedRegistersWithPathForTest added in v0.32.7

func NewBootstrappedRegistersWithPathForTest(tb testing.TB, dir string, first, latest uint64) *pebble.DB

func OpenRegisterPebbleDB

func OpenRegisterPebbleDB(dir string) (*pebble.DB, error)

OpenRegisterPebbleDB opens the database

func ReadHeightsFromBootstrappedDB

func ReadHeightsFromBootstrappedDB(db *pebble.DB) (firstHeight uint64, latestHeight uint64, err error)

ReadHeightsFromBootstrappedDB reads the first and latest height from a bootstrapped register db If the register db is not bootstrapped, it returns storage.ErrNotBootstrapped If the register db is corrupted, it returns an error

func RunWithRegistersStorageAtInitialHeights

func RunWithRegistersStorageAtInitialHeights(tb testing.TB, first uint64, latest uint64, f func(r *Registers))

Types

type RegisterBootstrap

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

func NewRegisterBootstrap

func NewRegisterBootstrap(
	db *pebble.DB,
	checkpointFile string,
	rootHeight uint64,
	rootHash ledger.RootHash,
	log zerolog.Logger,
) (*RegisterBootstrap, error)

NewRegisterBootstrap creates the bootstrap object for reading checkpoint data and the height tracker in pebble This object must be initialized and RegisterBootstrap.IndexCheckpointFile must be run to have the pebble db instance in the correct state to initialize a Registers store.

func (*RegisterBootstrap) IndexCheckpointFile

func (b *RegisterBootstrap) IndexCheckpointFile(ctx context.Context, workerCount int) error

IndexCheckpointFile indexes the checkpoint file in the Dir provided

type Registers

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

Registers library that implements pebble storage for registers given a pebble instance with root block and root height populated

func NewBootstrappedRegistersWithPath

func NewBootstrappedRegistersWithPath(dir string) (*Registers, *pebble.DB, error)

NewBootstrappedRegistersWithPath initializes a new Registers instance with a pebble db if the database is not initialized, it close the database and return storage.ErrNotBootstrapped

func NewRegisters

func NewRegisters(db *pebble.DB) (*Registers, error)

NewRegisters takes a populated pebble instance with LatestHeight and FirstHeight set. return storage.ErrNotBootstrapped if they those two keys are unavailable as it implies a uninitialized state return other error if database is in a corrupted state

func (*Registers) FirstHeight

func (s *Registers) FirstHeight() uint64

FirstHeight first indexed height found in the store, typically root block for the spork

func (*Registers) Get

func (s *Registers) Get(
	reg flow.RegisterID,
	height uint64,
) (flow.RegisterValue, error)

Get returns the most recent updated payload for the given RegisterID. "most recent" means the updates happens most recent up the given height.

For example, if there are 2 values stored for register A at height 6 and 11, then GetPayload(13, A) would return the value at height 11.

- storage.ErrNotFound if no register values are found - storage.ErrHeightNotIndexed if the requested height is out of the range of stored heights

func (*Registers) LatestHeight

func (s *Registers) LatestHeight() uint64

LatestHeight Gets the latest height of complete registers available

func (*Registers) Store

func (s *Registers) Store(
	entries flow.RegisterEntries,
	height uint64,
) error

Store sets the given entries in a batch. This function is expected to be called at one batch per height, sequentially. Under normal conditions, it should be called wth the value of height set to LatestHeight + 1 CAUTION: This function is not safe for concurrent use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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