pebble

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: ISC Imports: 15 Imported by: 0

Documentation

Index

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

func Options(cacheSizeMiB int) *pebble.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

func NewPebbleDB(path string, cacheSizeMiB int) (*DB, error)

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

func OpenPebbleDB(path string, cacheSizeMiB int) (*DB, error)

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) BatchPut

func (db *DB) BatchPut(pairs map[*database.Key][]byte) error

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) Close

func (db *DB) Close() error

Close closes the Pebble instance and all associated cursors.

func (*DB) Compact

func (db *DB) Compact() error

Compact compacts the Pebble instance (full range).

func (*DB) Cursor

func (db *DB) Cursor(bucket *database.Bucket) (database.Cursor, error)

Cursor begins a new cursor over the given prefix.

func (*DB) Delete

func (db *DB) 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 (*DB) Get

func (db *DB) 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 (*DB) Has

func (db *DB) Has(key *database.Key) (bool, error)

Has returns true if the database contains the given key.

func (*DB) Put

func (db *DB) Put(key *database.Key, value []byte) error

Put sets the value for the given key. It overwrites any previous value for that key.

type DBCursor

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

DBCursor is a thin wrapper around Pebble iterators.

func (*DBCursor) Close

func (c *DBCursor) Close() error

Close releases associated resources.

func (*DBCursor) First

func (c *DBCursor) First() bool

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

func (c *DBCursor) Key() (*database.Key, error)

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

func (c *DBCursor) Next() bool

Next moves the iterator to the next key/value pair. It returns whether the iterator is exhausted. Panics if the cursor is closed.

func (*DBCursor) Seek

func (c *DBCursor) Seek(key *database.Key) error

Seek moves the iterator to the first key/value pair whose key is greater than or equal to the given key. It returns ErrNotFound if such pair does not exist.

func (*DBCursor) Value

func (c *DBCursor) Value() ([]byte, error)

Value returns the value of the current key/value pair, or ErrNotFound if done. The caller should not modify the contents of the returned slice, and its contents may change on the next call to Next.

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) Cursor

func (tx *DBTransaction) Cursor(bucket *database.Bucket) (database.Cursor, error)

Cursor begins a new cursor over the given bucket.

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.

Jump to

Keyboard shortcuts

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