Documentation
¶
Index ¶
- func BytesPrefix(prefix []byte) *pebble.IterOptions
- func Options(cacheSizeMiB int) *pebble.Options
- type DB
- func (db *DB) BatchPut(pairs map[*database.Key][]byte) error
- func (db *DB) Begin() (database.Transaction, error)
- func (db *DB) BeginUnindexed() (database.Transaction, error)
- func (db *DB) Close() error
- func (db *DB) Compact() error
- func (db *DB) Cursor(bucket *database.Bucket) (database.Cursor, error)
- func (db *DB) Delete(key *database.Key) error
- func (db *DB) Get(key *database.Key) ([]byte, error)
- func (db *DB) Has(key *database.Key) (bool, error)
- func (db *DB) Put(key *database.Key, value []byte) error
- type DBCursor
- type DBTransaction
- func (tx *DBTransaction) BatchPut(pairs map[*database.Key][]byte) error
- func (tx *DBTransaction) Commit() error
- func (tx *DBTransaction) Cursor(bucket *database.Bucket) (database.Cursor, error)
- func (tx *DBTransaction) Delete(key *database.Key) error
- func (tx *DBTransaction) Get(key *database.Key) ([]byte, error)
- func (tx *DBTransaction) Has(key *database.Key) (bool, error)
- func (tx *DBTransaction) Put(key *database.Key, value []byte) error
- func (tx *DBTransaction) Rollback() error
- func (tx *DBTransaction) RollbackUnlessClosed() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesPrefix ¶
func BytesPrefix(prefix []byte) *pebble.IterOptions
BytesPrefix returns iterator options for keys with the given prefix, with a computed upper bound.
func Options ¶
Options returns a Pebble configuration heavily tuned for blockchain node workload:
- Very high rate of point lookups (UTXO spends, script/hash lookups, headers, etc.)
- Sustained high write throughput during IBD, catch-up sync and parallel block processing
- Assumes NVMe SSD + 16–64 GiB RAM class hardware in 2026
Key modern features (as of 2026 Pebble): - FormatMajorVersion: pebble.FormatNewest → enables columnar blocks (colblk) by default for faster point/range reads - Value separation → enabled by default (values ≥256 bytes stored in separate blob files) → major write-amp reduction - No need to set ValueSeparationPolicy unless customizing threshold
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB defines a thin wrapper around Pebble.
func NewPebbleDB ¶
NewPebbleDB opens a Pebble instance defined by the given path. It is meant for the node's own datadir: if pebble reports corruption, it deletes the directory and creates a fresh database, since pebble has no repair API. Offline tools must use OpenPebbleDB instead.
func OpenPebbleDB ¶
OpenPebbleDB opens a Pebble instance defined by the given path, and returns pebble's error when it cannot, including pebble.ErrCorruption. Unlike NewPebbleDB it never deletes anything.
Offline tools must use this. They are run on copies of datadirs, often because the node's data is suspect, and NewPebbleDB's recovery would silently wipe the very copy being investigated.
func (*DB) Begin ¶
func (db *DB) Begin() (database.Transaction, error)
Begin begins a new transaction. Its batch is indexed, so Get and Cursor see the transaction's own uncommitted writes. Maintaining that index costs work on every Put, and the cost grows with the number of keys the transaction touches, so a transaction that only writes should use BeginUnindexed instead.
func (*DB) BeginUnindexed ¶
func (db *DB) BeginUnindexed() (database.Transaction, error)
BeginUnindexed begins a new transaction backed by a plain batch. Get and Has still answer for keys this transaction has not itself written, by falling through to the database, but a key this transaction has already Put cannot be read back - Get returns an error saying so rather than a stale value - and Cursor is not available at all. Use it only for transactions that write and commit without reading their own writes.
func (*DB) Delete ¶
Delete deletes the value for the given key. Will not return an error if the key doesn't exist.
func (*DB) Get ¶
Get gets the value for the given key. It returns ErrNotFound if the given key does not exist.
type DBCursor ¶
type DBCursor struct {
// contains filtered or unexported fields
}
DBCursor is a thin wrapper around Pebble iterators.
func (*DBCursor) First ¶
First moves the iterator to the first key/value pair. It returns false if such a pair does not exist. Panics if the cursor is closed.
func (*DBCursor) Key ¶
Key returns the key of the current key/value pair, or ErrNotFound if done. Note that the key is trimmed to not include the prefix the cursor was opened with. The caller should not modify the contents of the returned slice, and its contents may change on the next call to Next.
func (*DBCursor) Next ¶
Next moves the iterator to the next key/value pair. It returns whether the iterator is exhausted. Panics if the cursor is closed.
type DBTransaction ¶
type DBTransaction struct {
// contains filtered or unexported fields
}
DBTransaction is a thin wrapper around Pebble batches. It supports both get and put. Tracks modified keys to support Has within the transaction.
func (*DBTransaction) BatchPut ¶
func (tx *DBTransaction) BatchPut(pairs map[*database.Key][]byte) error
func (*DBTransaction) Commit ¶
func (tx *DBTransaction) Commit() error
Commit commits whatever changes were made to the database within this transaction.
func (*DBTransaction) Delete ¶
func (tx *DBTransaction) Delete(key *database.Key) error
Delete deletes the value for the given key. Will not return an error if the key doesn't exist.
func (*DBTransaction) Get ¶
func (tx *DBTransaction) Get(key *database.Key) ([]byte, error)
Get gets the value for the given key. It returns ErrNotFound if the given key does not exist.
func (*DBTransaction) Has ¶
func (tx *DBTransaction) Has(key *database.Key) (bool, error)
Has returns true if the database or batch contains the given key.
func (*DBTransaction) Put ¶
func (tx *DBTransaction) Put(key *database.Key, value []byte) error
Put sets the value for the given key. It overwrites any previous value for that key.
func (*DBTransaction) Rollback ¶
func (tx *DBTransaction) Rollback() error
Rollback rolls back whatever changes were made to the database within this transaction.
func (*DBTransaction) RollbackUnlessClosed ¶
func (tx *DBTransaction) RollbackUnlessClosed() error
RollbackUnlessClosed rolls back changes that were made to the database within the transaction, unless the transaction had already been closed using either Rollback or Commit.