Documentation
¶
Index ¶
- Constants
- func RegisterProvider(host *hostplugin.Host) error
- type BadgerLogger
- type BlobStoreBadger
- func (d *BlobStoreBadger) Backup(ctx context.Context, w io.Writer) error
- func (d *BlobStoreBadger) Close() error
- func (d *BlobStoreBadger) DB() *badger.DB
- func (d *BlobStoreBadger) Delete(txn types.Txn, key []byte) error
- func (d *BlobStoreBadger) DeleteBlock(txn types.Txn, slot uint64, hash []byte, id uint64) error
- func (d *BlobStoreBadger) DeleteTx(txn types.Txn, txHash []byte) error
- func (d *BlobStoreBadger) DeleteUtxo(txn types.Txn, txId []byte, outputIdx uint32) error
- func (d *BlobStoreBadger) DiskSize() (int64, error)
- func (d *BlobStoreBadger) Get(txn types.Txn, key []byte) ([]byte, error)
- func (d *BlobStoreBadger) GetBlock(txn types.Txn, slot uint64, hash []byte) ([]byte, types.BlockMetadata, error)
- func (d *BlobStoreBadger) GetBlockURL(ctx context.Context, txn types.Txn, point ocommon.Point) (types.SignedURL, types.BlockMetadata, error)
- func (b *BlobStoreBadger) GetCommitTimestamp() (int64, error)
- func (d *BlobStoreBadger) GetTx(txn types.Txn, txHash []byte) ([]byte, error)
- func (d *BlobStoreBadger) GetUtxo(txn types.Txn, txId []byte, outputIdx uint32) ([]byte, error)
- func (d *BlobStoreBadger) NewIterator(txn types.Txn, opts types.BlobIteratorOptions) (iter types.BlobIterator)
- func (d *BlobStoreBadger) NewTransaction(update bool) types.Txn
- func (d *BlobStoreBadger) Restore(ctx context.Context, r io.Reader) (err error)
- func (d *BlobStoreBadger) Set(txn types.Txn, key, val []byte) error
- func (d *BlobStoreBadger) SetBlock(txn types.Txn, slot uint64, hash []byte, cborData []byte, id uint64, ...) error
- func (b *BlobStoreBadger) SetCommitTimestamp(timestamp int64, txn types.Txn) error
- func (d *BlobStoreBadger) SetLogger(logger *slog.Logger)
- func (d *BlobStoreBadger) SetTx(txn types.Txn, txHash []byte, offsetData []byte) error
- func (d *BlobStoreBadger) SetUtxo(txn types.Txn, txId []byte, outputIdx uint32, cborData []byte) error
- func (d *BlobStoreBadger) Start() error
- func (d *BlobStoreBadger) Stop() error
- func (d *BlobStoreBadger) Sync() error
- func (d *BlobStoreBadger) TombstoneBlock(txn types.Txn, slot uint64, hash []byte) error
- type BlobStoreBadgerOptionFunc
- func WithBlockCacheSize(size uint64) BlobStoreBadgerOptionFunc
- func WithCompactBlockMetadata(enabled bool) BlobStoreBadgerOptionFunc
- func WithCompressionEnabled(enabled bool) BlobStoreBadgerOptionFunc
- func WithCompressionLevel(level int) BlobStoreBadgerOptionFunc
- func WithDataDir(dataDir string) BlobStoreBadgerOptionFunc
- func WithDeferOpen() BlobStoreBadgerOptionFunc
- func WithGc(enabled bool) BlobStoreBadgerOptionFunc
- func WithIndexCacheSize(size uint64) BlobStoreBadgerOptionFunc
- func WithLogger(logger *slog.Logger) BlobStoreBadgerOptionFunc
- func WithMemTableSize(size int64) BlobStoreBadgerOptionFunc
- func WithPromRegistry(registry prometheus.Registerer) BlobStoreBadgerOptionFunc
- func WithValueLogFileSize(size int64) BlobStoreBadgerOptionFunc
- func WithValueThreshold(threshold int64) BlobStoreBadgerOptionFunc
- type Config
Constants ¶
const ( DefaultBlockCacheSize = 268435456 DefaultIndexCacheSize = 0 DefaultValueLogFileSize = 1073741824 DefaultMemTableSize = 134217728 DefaultValueThreshold = 1048576 DefaultCoreBlockCacheSize = 0 DefaultCoreIndexCacheSize = 0 DefaultCoreCompressionEnabled = false DefaultAPIBlockCacheSize = DefaultBlockCacheSize DefaultAPIIndexCacheSize = DefaultIndexCacheSize DefaultAPICompressionEnabled = true DefaultCompressionLevel = 1 )
Default cache and value sizes for BadgerDB, in bytes.
Variables ¶
This section is empty.
Functions ¶
func RegisterProvider ¶ added in v0.68.0
func RegisterProvider(host *hostplugin.Host) error
RegisterProvider registers the Badger blob provider with host.
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 ¶
func New(opts ...BlobStoreBadgerOptionFunc) (*BlobStoreBadger, error)
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) Backup ¶ added in v0.69.0
Backup streams a full, MVCC-consistent backup of the store to w. It does not block concurrent readers or writers.
Badger's own Backup has no context parameter and, once started, runs to completion regardless of ctx — checking ctx.Err() only here, before calling it, would let a cancellation request (see bark's CancelOperation) sit unnoticed for the entire duration of a large backup. Wrapping w in a contextWriter closes that gap: Badger calls Write repeatedly as it streams entries out, and each call re-checks ctx, so cancellation takes effect within a chunk or two rather than only between operations.
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
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
DeleteUtxo removes a UTxO's data
func (*BlobStoreBadger) DiskSize ¶ added in v0.29.0
func (d *BlobStoreBadger) DiskSize() (int64, error)
DiskSize returns the on-disk size of the Badger database in bytes (LSM tree size + value log size).
func (*BlobStoreBadger) Get ¶ added in v0.19.0
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 (*BlobStoreBadger) GetCommitTimestamp ¶
func (b *BlobStoreBadger) GetCommitTimestamp() (int64, error)
func (*BlobStoreBadger) NewIterator ¶ added in v0.19.0
func (d *BlobStoreBadger) NewIterator( txn types.Txn, opts types.BlobIteratorOptions, ) (iter 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) Restore ¶ added in v0.69.0
Restore replaces the store's contents by loading a backup stream produced by Backup. It must only be called against a freshly opened, empty store -- enforced below, unlike relying on callers to honor the contract unchecked. See Backup's doc comment for why r is wrapped the same way w is there: Badger's Load has no context parameter of its own.
Some malformed inputs make Badger's Load return a clean error (e.g. a proto-unmarshal failure), but others make it panic outright (observed with arbitrary garbage bytes: a corrupted length header produces a negative/oversized slice length inside Load, panicking on the allocation) — a real, previously-unhandled crash risk for a live node restoring an untrusted or corrupted snapshot. The recover below covers that, but not every failure mode: Load's length prefix is an unvalidated raw uint64 that it trusts unconditionally before allocating a buffer of that size, and a single-allocation failure large enough can produce a fatal, unrecoverable runtime OOM rather than a regular panic recover can catch — no defer can stop that from taking the whole process down. validateLoadRecordSizes below makes a cheap, allocation-bounded pass over the same record framing Load uses first, so an oversized declared length is rejected as a normal error before Load ever sees it, rather than only after it's already been trusted for the allocation.
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) 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
func (*BlobStoreBadger) Sync ¶ added in v0.69.0
func (d *BlobStoreBadger) Sync() error
Sync flushes committed writes to disk. Badger is opened with its default SyncWrites=false, so a committed transaction lives in the active memtable's WAL and the value log without an fsync; with a 128MiB default memtable and only a few MiB of blocks per hour at chain tip, an unclean shutdown can discard hours of committed blocks. badger.DB.Sync syncs both the memtable WAL and the value log, which is what makes those commits recoverable on reopen. It is a no-op for in-memory and read-only stores.
func (*BlobStoreBadger) TombstoneBlock ¶ added in v0.39.1
TombstoneBlock overwrites a block's CBOR with an expired-history marker. GetBlock reads the bp value, sees the marker, and returns types.ErrHistoryExpired so an archive proxy can intercept it.
What stays:
bi<id>: required by BlockByIndex (the chain iterator translates id→key here; no equivalent index exists in metadata).
bh<hash>: BlockByHash resolves only through this index and treats a missing entry as a hard miss (ErrBlockNotFound), so the entry must survive tombstoning to keep the block reachable by hash.
bp_metadata: kept so bark can populate models.Block.ID (and the other small metadata fields) when surfacing a CBOR fetched from the archive. Without this the chain iterator's BlockByIndex path gets ID=0 and immediately returns ErrIteratorChainTip.
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 WithCompactBlockMetadata ¶ added in v0.27.0
func WithCompactBlockMetadata(enabled bool) BlobStoreBadgerOptionFunc
WithCompactBlockMetadata enables a compact binary metadata format for blocks.
func WithCompressionEnabled ¶ added in v0.27.7
func WithCompressionEnabled(enabled bool) BlobStoreBadgerOptionFunc
WithCompressionEnabled controls ZSTD compression of SSTable blocks. Disabling compression allows block cache size 0 (pure mmap).
func WithCompressionLevel ¶ added in v0.51.0
func WithCompressionLevel(level int) BlobStoreBadgerOptionFunc
WithCompressionLevel sets the ZSTD compression level used when compression is enabled. Higher levels yield better compression ratios at the cost of throughput. Has no effect when compression is disabled.
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 Config ¶ added in v0.68.0
type Config struct {
// DataDir overrides the application-wide database path for this provider.
// An empty value uses ProviderDependencies.DataDir.
DataDir string `yaml:"dataDir"`
BlockCacheSize *uint64 `yaml:"blockCacheSize"`
IndexCacheSize *uint64 `yaml:"indexCacheSize"`
ValueLogFileSize uint64 `yaml:"valueLogFileSize"`
MemTableSize uint64 `yaml:"memTableSize"`
ValueThreshold uint64 `yaml:"valueThreshold"`
GC *bool `yaml:"gc"`
Compression *bool `yaml:"compression"`
CompressionLevel uint64 `yaml:"compressionLevel"`
}
Config contains Badger-specific configuration. Shared application settings such as the data directory and storage mode are supplied through Dependencies.