badger

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBlockCacheSize   = 268435456  // 256 MB — Badger's own default; sufficient for core nodes
	DefaultIndexCacheSize   = 0          // 0 = unlimited; Badger memory-maps the full index
	DefaultValueLogFileSize = 1073741824 // 1 GB
	DefaultMemTableSize     = 134217728  // 128 MB
	DefaultValueThreshold   = 1048576    // 1 MB
)

Default cache sizes for BadgerDB (in bytes).

Block cache is needed because we use Snappy compression. Badger's own default is 256 MB block cache and 0 (unlimited) index cache. Setting IndexCacheSize to 0 lets Badger memory-map the full index without eviction, which is preferable to capping it.

Operators can override via block-cache-size / index-cache-size CLI flags or YAML config.

Variables

This section is empty.

Functions

func NewFromCmdlineOptions added in v0.18.0

func NewFromCmdlineOptions() plugin.Plugin

Types

type BadgerLogger

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

BadgerLogger is a wrapper type to give our logger the expected interface

func NewBadgerLogger

func NewBadgerLogger(logger *slog.Logger) *BadgerLogger

func (*BadgerLogger) Debugf

func (b *BadgerLogger) Debugf(msg string, args ...any)

func (*BadgerLogger) Errorf

func (b *BadgerLogger) Errorf(msg string, args ...any)

func (*BadgerLogger) Infof

func (b *BadgerLogger) Infof(msg string, args ...any)

func (*BadgerLogger) Warningf

func (b *BadgerLogger) Warningf(msg string, args ...any)

type BlobStoreBadger

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

BlobStoreBadger stores all data in badger. Data may not be persisted

func New

New creates a new database. When deferOpen is set (via WithDeferOpen), Badger is not opened until Start() is called, allowing an injected logger (via SetLogger) to be used for Badger's startup logging.

func (*BlobStoreBadger) Close

func (d *BlobStoreBadger) Close() error

Close gets the database handle from our BlobStore and closes it

func (*BlobStoreBadger) DB

func (d *BlobStoreBadger) DB() *badger.DB

DB returns the database handle

func (*BlobStoreBadger) Delete added in v0.19.0

func (d *BlobStoreBadger) Delete(txn types.Txn, key []byte) error

Delete removes a key from badger within a transaction

func (*BlobStoreBadger) DeleteBlock added in v0.20.0

func (d *BlobStoreBadger) DeleteBlock(
	txn types.Txn,
	slot uint64,
	hash []byte,
	id uint64,
) error

DeleteBlock removes a block and its associated data

func (*BlobStoreBadger) DeleteTx added in v0.22.0

func (d *BlobStoreBadger) DeleteTx(
	txn types.Txn,
	txHash []byte,
) error

DeleteTx removes a transaction's offset data

func (*BlobStoreBadger) DeleteUtxo added in v0.20.0

func (d *BlobStoreBadger) DeleteUtxo(
	txn types.Txn,
	txId []byte,
	outputIdx uint32,
) error

DeleteUtxo removes a UTxO's data

func (*BlobStoreBadger) Get added in v0.19.0

func (d *BlobStoreBadger) Get(
	txn types.Txn,
	key []byte,
) ([]byte, error)

Get retrieves a value from badger within a transaction

func (*BlobStoreBadger) GetBlock added in v0.20.0

func (d *BlobStoreBadger) GetBlock(
	txn types.Txn,
	slot uint64,
	hash []byte,
) ([]byte, types.BlockMetadata, error)

GetBlock retrieves a block's CBOR data and metadata

func (*BlobStoreBadger) GetBlockURL added in v0.22.0

func (d *BlobStoreBadger) GetBlockURL(
	ctx context.Context,
	txn types.Txn,
	point ocommon.Point,
) (types.SignedURL, types.BlockMetadata, error)

func (*BlobStoreBadger) GetCommitTimestamp

func (b *BlobStoreBadger) GetCommitTimestamp() (int64, error)

func (*BlobStoreBadger) GetTx added in v0.22.0

func (d *BlobStoreBadger) GetTx(
	txn types.Txn,
	txHash []byte,
) ([]byte, error)

GetTx retrieves a transaction's offset data

func (*BlobStoreBadger) GetUtxo added in v0.20.0

func (d *BlobStoreBadger) GetUtxo(
	txn types.Txn,
	txId []byte,
	outputIdx uint32,
) ([]byte, error)

GetUtxo retrieves a UTxO's CBOR data

func (*BlobStoreBadger) NewIterator added in v0.19.0

func (d *BlobStoreBadger) NewIterator(
	txn types.Txn,
	opts types.BlobIteratorOptions,
) types.BlobIterator

NewIterator creates an iterator for badger within a transaction.

Important: items returned by the iterator's `Item()` must only be accessed while the transaction used to create the iterator is still active. Implementations may validate transaction state at access time (for example `ValueCopy` may fail if the transaction has been committed or rolled back). Typical usage iterates and accesses item values within the same transaction scope.

func (*BlobStoreBadger) NewTransaction

func (d *BlobStoreBadger) NewTransaction(update bool) types.Txn

NewTransaction creates a new badger transaction

func (*BlobStoreBadger) Set added in v0.19.0

func (d *BlobStoreBadger) Set(txn types.Txn, key, val []byte) error

Set stores a key-value pair in badger within a transaction

func (*BlobStoreBadger) SetBlock added in v0.20.0

func (d *BlobStoreBadger) SetBlock(
	txn types.Txn,
	slot uint64,
	hash []byte,
	cborData []byte,
	id uint64,
	blockType uint,
	height uint64,
	prevHash []byte,
) error

SetBlock stores a block with its metadata and index

func (*BlobStoreBadger) SetCommitTimestamp

func (b *BlobStoreBadger) SetCommitTimestamp(
	timestamp int64,
	txn types.Txn,
) error

func (*BlobStoreBadger) SetLogger added in v0.24.0

func (d *BlobStoreBadger) SetLogger(logger *slog.Logger)

func (*BlobStoreBadger) SetTx added in v0.22.0

func (d *BlobStoreBadger) SetTx(
	txn types.Txn,
	txHash []byte,
	offsetData []byte,
) error

SetTx stores a transaction's offset data

func (*BlobStoreBadger) SetUtxo added in v0.20.0

func (d *BlobStoreBadger) SetUtxo(
	txn types.Txn,
	txId []byte,
	outputIdx uint32,
	cborData []byte,
) error

SetUtxo stores a UTxO's CBOR data

func (*BlobStoreBadger) Start added in v0.18.0

func (d *BlobStoreBadger) Start() error

Start implements the plugin.Plugin interface. When the database was created with WithDeferOpen, Start opens Badger using the logger that was injected via SetLogger after construction.

func (*BlobStoreBadger) Stop added in v0.18.0

func (d *BlobStoreBadger) Stop() error

Stop implements the plugin.Plugin interface

type BlobStoreBadgerOptionFunc added in v0.18.0

type BlobStoreBadgerOptionFunc func(*BlobStoreBadger)

func WithBlockCacheSize added in v0.18.0

func WithBlockCacheSize(size uint64) BlobStoreBadgerOptionFunc

WithBlockCacheSize specifies the block cache size

func WithDataDir added in v0.18.0

func WithDataDir(dataDir string) BlobStoreBadgerOptionFunc

WithDataDir specifies the data directory to use for storage

func WithDeferOpen added in v0.24.0

func WithDeferOpen() BlobStoreBadgerOptionFunc

WithDeferOpen defers opening Badger until Start() is called. This allows a logger to be injected via SetLogger before Badger emits any startup logs.

func WithGc added in v0.18.0

func WithGc(enabled bool) BlobStoreBadgerOptionFunc

WithGc specifies whether garbage collection is enabled

func WithIndexCacheSize added in v0.18.0

func WithIndexCacheSize(size uint64) BlobStoreBadgerOptionFunc

WithIndexCacheSize specifies the index cache size

func WithLogger added in v0.18.0

func WithLogger(logger *slog.Logger) BlobStoreBadgerOptionFunc

WithLogger specifies the logger object to use for logging messages

func WithMemTableSize added in v0.20.0

func WithMemTableSize(size int64) BlobStoreBadgerOptionFunc

WithMemTableSize specifies the memtable size in bytes

func WithPromRegistry added in v0.18.0

func WithPromRegistry(
	registry prometheus.Registerer,
) BlobStoreBadgerOptionFunc

WithPromRegistry specifies the prometheus registry to use for metrics

func WithValueLogFileSize added in v0.20.0

func WithValueLogFileSize(size int64) BlobStoreBadgerOptionFunc

WithValueLogFileSize specifies the value log file size in bytes

func WithValueThreshold added in v0.20.0

func WithValueThreshold(threshold int64) BlobStoreBadgerOptionFunc

WithValueThreshold specifies the value threshold for keeping values in LSM tree

type Profile added in v0.24.0

type Profile string
const (
	ProfileCore Profile = "core"
	ProfileAPI  Profile = "api"
	ProfileLoad Profile = "load"
)

type ProfileSettings added in v0.24.0

type ProfileSettings struct {
	BlockCacheSize uint64
	IndexCacheSize uint64
	MemTableSize   uint64
}

Jump to

Keyboard shortcuts

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