Documentation
¶
Overview ¶
Package ethdb defines the interfaces for an Ethereum data store.
Index ¶
- Constants
- Variables
- func Bytesmask(fixedbits int) (fixedbytes int, mask byte)
- func CustomCmpFunc(tx *lmdb.Txn, dbi lmdb.DBI) dbutils.CmpFunc
- func CustomDupCmpFunc(tx *lmdb.Txn, dbi lmdb.DBI) dbutils.CmpFunc
- func DefaultBucketConfigs(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg
- func ForEach(c Cursor, walker func(k, v []byte) (bool, error)) error
- func Get(tx Tx, bucket string, key []byte) ([]byte, error)
- func InspectDatabase(db Database) error
- func KeyCmpBackward(key1, key2 []byte) (int, bool)
- func MultiPut(tx Tx, tuples ...[]byte) error
- func MultiWalk(c Cursor, startkeys [][]byte, fixedbits []int, ...) error
- func NewRemote() remoteOpts
- func NewSnapshot2KV() snapshotOpts2
- func NewSplitCursor(c Cursor, startkey []byte, matchBits int, part1end, part2start, part3start int) *splitCursor
- func SetStorageModeIfNotExist(db Database, sm StorageMode) error
- func Walk(c Cursor, startkey []byte, fixedbits int, ...) error
- func WarmUp(tx Tx, bucket string, logEvery *time.Ticker, quit <-chan struct{}) error
- type Backend
- type BucketConfigsFunc
- type BucketMigrator
- type BucketsMigrator
- type Closer
- type Cursor
- type CursorDupSort
- type DBCounterStats
- type Database
- type DbCopier
- type DbProvider
- type DbWithPendingMutations
- type Deleter
- type Getter
- type GetterPutter
- type HasKV
- type HasNetInterface
- type HasStats
- type HasTx
- type KV
- type KvData
- type LmdbCursor
- func (c *LmdbCursor) Append(k []byte, v []byte) error
- func (c *LmdbCursor) Close()
- func (c *LmdbCursor) Count() (uint64, error)
- func (c *LmdbCursor) Current() ([]byte, []byte, error)
- func (c *LmdbCursor) Delete(k, v []byte) error
- func (c *LmdbCursor) DeleteCurrent() error
- func (c *LmdbCursor) First() ([]byte, []byte, error)
- func (c *LmdbCursor) Last() ([]byte, []byte, error)
- func (c *LmdbCursor) Next() (k, v []byte, err error)
- func (c *LmdbCursor) Prefetch(v uint) Cursor
- func (c *LmdbCursor) Prefix(v []byte) Cursor
- func (c *LmdbCursor) Prev() (k, v []byte, err error)
- func (c *LmdbCursor) Put(key []byte, value []byte) error
- func (c *LmdbCursor) PutCurrent(key []byte, value []byte) error
- func (c *LmdbCursor) PutNoOverwrite(key []byte, value []byte) error
- func (c *LmdbCursor) Reserve(k []byte, n int) ([]byte, error)
- func (c *LmdbCursor) Seek(seek []byte) (k, v []byte, err error)
- func (c *LmdbCursor) SeekExact(key []byte) ([]byte, []byte, error)
- type LmdbDupSortCursor
- func (c *LmdbDupSortCursor) Append(k []byte, v []byte) error
- func (c *LmdbDupSortCursor) AppendDup(k []byte, v []byte) error
- func (c *LmdbDupSortCursor) CountDuplicates() (uint64, error)
- func (c *LmdbDupSortCursor) DeleteCurrentDuplicates() error
- func (c *LmdbDupSortCursor) DeleteExact(k1, k2 []byte) error
- func (c *LmdbDupSortCursor) FirstDup() ([]byte, error)
- func (c *LmdbDupSortCursor) LastDup(k []byte) ([]byte, error)
- func (c *LmdbDupSortCursor) NextDup() ([]byte, []byte, error)
- func (c *LmdbDupSortCursor) NextNoDup() ([]byte, []byte, error)
- func (c *LmdbDupSortCursor) PrevDup() ([]byte, []byte, error)
- func (c *LmdbDupSortCursor) PrevNoDup() ([]byte, []byte, error)
- func (c *LmdbDupSortCursor) PutCurrent(k, v []byte) error
- func (c *LmdbDupSortCursor) PutNoDupData(key, value []byte) error
- func (c *LmdbDupSortCursor) SeekBothExact(key, value []byte) ([]byte, []byte, error)
- func (c *LmdbDupSortCursor) SeekBothRange(key, value []byte) ([]byte, []byte, error)
- type LmdbKV
- func (db *LmdbKV) AllBuckets() dbutils.BucketsCfg
- func (db *LmdbKV) AllDBI() map[string]dbutils.DBI
- func (db *LmdbKV) Begin(_ context.Context, flags TxFlags) (txn Tx, err error)
- func (db *LmdbKV) Close()
- func (db *LmdbKV) CollectMetrics()
- func (db *LmdbKV) DiskSize(_ context.Context) (uint64, error)
- func (db *LmdbKV) Env() *lmdb.Env
- func (db *LmdbKV) NewDbWithTheSameParameters() *ObjectDatabase
- func (db *LmdbKV) Update(ctx context.Context, f func(tx Tx) error) (err error)
- func (db *LmdbKV) View(ctx context.Context, f func(tx Tx) error) (err error)
- type LmdbOpts
- func (opts LmdbOpts) Exclusive() LmdbOpts
- func (opts LmdbOpts) Flags(f func(uint) uint) LmdbOpts
- func (opts LmdbOpts) InMem() LmdbOpts
- func (opts LmdbOpts) MapSize(sz datasize.ByteSize) LmdbOpts
- func (opts LmdbOpts) MaxFreelistReuse(pages uint) LmdbOpts
- func (opts LmdbOpts) MustOpen() KV
- func (opts LmdbOpts) Open() (kv KV, err error)
- func (opts LmdbOpts) Path(path string) LmdbOpts
- func (opts LmdbOpts) Set(opt LmdbOpts) LmdbOpts
- func (opts LmdbOpts) WithBucketsConfig(f BucketConfigsFunc) LmdbOpts
- type MinDatabase
- type MultiPutTuples
- type MutationItem
- type ObjectDatabase
- func MustOpen(path string) *ObjectDatabase
- func NewDatabaseWithFreezer(db *ObjectDatabase, dir, suffix string) (*ObjectDatabase, error)
- func NewMemDatabase() *ObjectDatabase
- func NewMemoryDatabase() *ObjectDatabase
- func NewObjectDatabase(kv KV) *ObjectDatabase
- func Open(path string, readOnly bool) (*ObjectDatabase, error)
- func (db *ObjectDatabase) Ancients() (uint64, error)
- func (db *ObjectDatabase) Append(bucket string, key []byte, value []byte) error
- func (db *ObjectDatabase) AppendDup(bucket string, key []byte, value []byte) error
- func (db *ObjectDatabase) Begin(ctx context.Context, flags TxFlags) (DbWithPendingMutations, error)
- func (db *ObjectDatabase) BucketExists(name string) (bool, error)
- func (db *ObjectDatabase) ClearBuckets(buckets ...string) error
- func (db *ObjectDatabase) Close()
- func (db *ObjectDatabase) Delete(bucket string, k, v []byte) error
- func (db *ObjectDatabase) DiskSize(ctx context.Context) (uint64, error)
- func (db *ObjectDatabase) DropBuckets(buckets ...string) error
- func (db *ObjectDatabase) Get(bucket string, key []byte) ([]byte, error)
- func (db *ObjectDatabase) Has(bucket string, key []byte) (bool, error)
- func (db *ObjectDatabase) IdealBatchSize() int
- func (db *ObjectDatabase) KV() KV
- func (db *ObjectDatabase) Keys() ([][]byte, error)
- func (db *ObjectDatabase) Last(bucket string) ([]byte, []byte, error)
- func (db *ObjectDatabase) MemCopy() *ObjectDatabase
- func (db *ObjectDatabase) MultiPut(tuples ...[]byte) (uint64, error)
- func (db *ObjectDatabase) NewBatch() DbWithPendingMutations
- func (db *ObjectDatabase) Put(bucket string, key []byte, value []byte) error
- func (db *ObjectDatabase) Reserve(bucket string, key []byte, i int) ([]byte, error)
- func (db *ObjectDatabase) Sequence(bucket string, amount uint64) (res uint64, err error)
- func (db *ObjectDatabase) SetKV(kv KV)
- func (db *ObjectDatabase) TruncateAncients(items uint64) error
- func (db *ObjectDatabase) Walk(bucket string, startkey []byte, fixedbits int, ...) error
- type Putter
- type RWCounterDecorator
- func (d *RWCounterDecorator) Delete(bucket string, k, v []byte) error
- func (d *RWCounterDecorator) Get(bucket string, key []byte) ([]byte, error)
- func (d *RWCounterDecorator) Has(bucket string, key []byte) (bool, error)
- func (d *RWCounterDecorator) MultiPut(tuples ...[]byte) (uint64, error)
- func (d *RWCounterDecorator) NewBatch() DbWithPendingMutations
- func (d *RWCounterDecorator) Put(bucket string, key, value []byte) error
- func (d *RWCounterDecorator) Walk(bucket string, startkey []byte, fixedbits int, ...) error
- type RemoteBackend
- type RemoteKV
- func (db *RemoteKV) AllBuckets() dbutils.BucketsCfg
- func (db *RemoteKV) Begin(ctx context.Context, flags TxFlags) (Tx, error)
- func (db *RemoteKV) Close()
- func (db *RemoteKV) CollectMetrics()
- func (db *RemoteKV) DiskSize(ctx context.Context) (uint64, error)
- func (db *RemoteKV) Update(ctx context.Context, f func(tx Tx) error) (err error)
- func (db *RemoteKV) View(ctx context.Context, f func(tx Tx) error) (err error)
- type SnapshotKV2
- func (s *SnapshotKV2) AllBuckets() dbutils.BucketsCfg
- func (s *SnapshotKV2) Begin(ctx context.Context, flags TxFlags) (Tx, error)
- func (s *SnapshotKV2) Close()
- func (s *SnapshotKV2) CollectMetrics()
- func (s *SnapshotKV2) Update(ctx context.Context, f func(tx Tx) error) error
- func (s *SnapshotKV2) View(ctx context.Context, f func(tx Tx) error) error
- type StorageMode
- type Tx
- type TxDb
- func (m *TxDb) Ancients() (uint64, error)
- func (m *TxDb) Append(bucket string, key []byte, value []byte) error
- func (m *TxDb) AppendDup(bucket string, key []byte, value []byte) error
- func (m *TxDb) BatchSize() int
- func (m *TxDb) Begin(ctx context.Context, flags TxFlags) (DbWithPendingMutations, error)
- func (m *TxDb) BucketExists(name string) (bool, error)
- func (m *TxDb) ClearBuckets(buckets ...string) error
- func (m *TxDb) Close()
- func (m *TxDb) Commit() (uint64, error)
- func (m *TxDb) CommitAndBegin(ctx context.Context) error
- func (m *TxDb) Delete(bucket string, k, v []byte) error
- func (m *TxDb) DiskSize(ctx context.Context) (common.StorageSize, error)
- func (m *TxDb) DropBuckets(buckets ...string) error
- func (m *TxDb) Get(bucket string, key []byte) ([]byte, error)
- func (m *TxDb) Has(bucket string, key []byte) (bool, error)
- func (m *TxDb) IdealBatchSize() int
- func (m *TxDb) KV() KV
- func (m *TxDb) Keys() ([][]byte, error)
- func (m *TxDb) Last(bucket string) ([]byte, []byte, error)
- func (m *TxDb) MultiPut(tuples ...[]byte) (uint64, error)
- func (m *TxDb) NewBatch() DbWithPendingMutations
- func (m *TxDb) Put(bucket string, key []byte, value []byte) error
- func (m *TxDb) Reserve(bucket string, key []byte, i int) ([]byte, error)
- func (m *TxDb) Rollback()
- func (m *TxDb) RollbackAndBegin(ctx context.Context) error
- func (m *TxDb) Sequence(bucket string, amount uint64) (res uint64, err error)
- func (m *TxDb) TruncateAncients(items uint64) error
- func (m *TxDb) Tx() Tx
- func (m *TxDb) Walk(bucket string, startkey []byte, fixedbits int, ...) error
- type TxFlags
Constants ¶
const (
NonExistingDBI dbutils.DBI = 999_999_999
)
Variables ¶
var ( ErrAttemptToDeleteNonDeprecatedBucket = errors.New("only buckets from dbutils.DeprecatedBuckets can be deleted") ErrUnknownBucket = errors.New("unknown bucket. add it to dbutils.Buckets") )
var ( LMDBDefaultMapSize = 2 * datasize.TB LMDBDefaultMaxFreelistReuse = uint(1000) // measured in pages )
var DefaultStorageMode = StorageMode{History: true, Receipts: true, TxIndex: true, CallTraces: false}
var DeletedValue = []byte("it is deleted value")
var EndSuffix = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
var ErrKeyNotFound = errors.New("db: key not found")
ErrKeyNotFound is returned when key isn't found in the database.
Functions ¶
func DefaultBucketConfigs ¶
func DefaultBucketConfigs(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg
func InspectDatabase ¶
func KeyCmpBackward ¶
func MultiWalk ¶
func MultiWalk(c Cursor, startkeys [][]byte, fixedbits []int, walker func(int, []byte, []byte) error) error
MultiWalk is similar to multiple Walk calls folded into one.
func NewSnapshot2KV ¶
func NewSnapshot2KV() snapshotOpts2
func NewSplitCursor ¶
func SetStorageModeIfNotExist ¶
func SetStorageModeIfNotExist(db Database, sm StorageMode) error
Types ¶
type BucketConfigsFunc ¶
type BucketConfigsFunc func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg
type BucketMigrator ¶
type BucketMigrator interface {
DropBucket(string) error
CreateBucket(string) error
ExistsBucket(string) bool
ClearBucket(string) error
ExistingBuckets() ([]string, error)
}
Interface used for buckets migration, don't use it in usual app code
type BucketsMigrator ¶
type Cursor ¶
type Cursor interface {
First() ([]byte, []byte, error) // First - position at first key/data item
Seek(seek []byte) ([]byte, []byte, error) // Seek - position at first key greater than or equal to specified key
SeekExact(key []byte) ([]byte, []byte, error) // SeekExact - position at first key greater than or equal to specified key
Next() ([]byte, []byte, error) // Next - position at next key/value (can iterate over DupSort key/values automatically)
Prev() ([]byte, []byte, error) // Prev - position at previous key
Last() ([]byte, []byte, error) // Last - position at last key and last possible value
Current() ([]byte, []byte, error) // Current - return key/data at current cursor position
Put(k, v []byte) error // Put - based on order
Append(k []byte, v []byte) error // Append - append the given key/data pair to the end of the database. This option allows fast bulk loading when keys are already known to be in the correct order.
Delete(k, v []byte) error // Delete - short version of SeekExact+DeleteCurrent or SeekBothExact+DeleteCurrent
// DeleteCurrent This function deletes the key/data pair to which the cursor refers.
// This does not invalidate the cursor, so operations such as MDB_NEXT
// can still be used on it.
// Both MDB_NEXT and MDB_GET_CURRENT will return the same record after
// this operation.
DeleteCurrent() error
// PutNoOverwrite(key, value []byte) error
Reserve(k []byte, n int) ([]byte, error)
// PutCurrent - replace the item at the current cursor position.
PutCurrent(key, value []byte) error
Count() (uint64, error) // Count - fast way to calculate amount of keys in bucket. It counts all keys even if Prefix was set.
Close()
}
Cursor - class for navigating through a database CursorDupSort are inherit this class
If methods (like First/Next/Seek) return error, then returned key SHOULD not be nil (can be []byte{} for example). Then looping code will look as: c := kv.Cursor(bucketName)
for k, v, err := c.First(); k != nil; k, v, err = c.Next() {
if err != nil {
return err
}
... logic
}
type CursorDupSort ¶
type CursorDupSort interface {
Cursor
// SeekBothExact -
// second parameter can be nil only if searched key has no duplicates, or return error
SeekBothExact(key, value []byte) ([]byte, []byte, error)
SeekBothRange(key, value []byte) ([]byte, []byte, error)
FirstDup() ([]byte, error) // FirstDup - position at first data item of current key
NextDup() ([]byte, []byte, error) // NextDup - position at next data item of current key
NextNoDup() ([]byte, []byte, error) // NextNoDup - position at first data item of next key
LastDup(k []byte) ([]byte, error) // LastDup - position at last data item of current key
CountDuplicates() (uint64, error) // CountDuplicates - number of duplicates for the current key
DeleteCurrentDuplicates() error // DeleteCurrentDuplicates - deletes all of the data items for the current key
AppendDup(key, value []byte) error // AppendDup - same as Append, but for sorted dup data
}
type DBCounterStats ¶
type Database ¶
type Database interface {
Getter
Putter
Deleter
Closer
// MultiPut inserts or updates multiple entries.
// Entries are passed as an array:
// bucket0, key0, val0, bucket1, key1, val1, ...
MultiPut(tuples ...[]byte) (uint64, error)
// NewBatch - starts in-mem batch
//
// Common pattern:
//
// batch := db.NewBatch()
// defer batch.Rollback()
// ... some calculations on `batch`
// batch.Commit()
//
NewBatch() DbWithPendingMutations //
Begin(ctx context.Context, flags TxFlags) (DbWithPendingMutations, error) // starts db transaction
Last(bucket string) ([]byte, []byte, error)
// IdealBatchSize defines the size of the data batches should ideally add in one write.
IdealBatchSize() int
Keys() ([][]byte, error)
Append(bucket string, key, value []byte) error
AppendDup(bucket string, key, value []byte) error
Sequence(bucket string, amount uint64) (uint64, error)
}
Database wraps all database operations. All methods are safe for concurrent use.
type DbCopier ¶
type DbCopier interface {
NewDbWithTheSameParameters() *ObjectDatabase
}
type DbWithPendingMutations ¶
type DbWithPendingMutations interface {
Database
// Commit - commits transaction (or flush data into underlying db object in case of `mutation`)
//
// Common pattern:
//
// tx := db.Begin()
// defer tx.Rollback()
// ... some calculations on `tx`
// tx.Commit()
//
Commit() (uint64, error)
// CommitAndBegin - commits and starts new transaction inside same db object.
// useful for periodical commits implementation.
//
// Common pattern:
//
// tx := db.Begin()
// defer tx.Rollback()
// for {
// ... some calculations on `tx`
// tx.CommitAndBegin()
// // defer here - is not useful, because 'tx' object is reused and first `defer` will work perfectly
// }
// tx.Commit()
//
CommitAndBegin(ctx context.Context) error
Rollback()
BatchSize() int
Reserve(bucket string, key []byte, i int) ([]byte, error)
}
DbWithPendingMutations is an extended version of the Database, where all changes are first made in memory. Later they can either be committed to the database or rolled back.
type Deleter ¶
type Deleter interface {
// Delete removes a single entry.
Delete(bucket string, k, v []byte) error
}
Deleter wraps the database delete operations.
type Getter ¶
type Getter interface {
// Get returns the value for a given key if it's present.
Get(bucket string, key []byte) ([]byte, error)
// Has indicates whether a key exists in the database.
Has(bucket string, key []byte) (bool, error)
// Walk iterates over entries with keys greater or equal to startkey.
// Only the keys whose first fixedbits match those of startkey are iterated over.
// walker is called for each eligible entry.
// If walker returns false or an error, the walk stops.
Walk(bucket string, startkey []byte, fixedbits int, walker func(k, v []byte) (bool, error)) error
}
Getter wraps the database read operations.
type GetterPutter ¶
type HasNetInterface ¶
type HasNetInterface interface {
DB() Database
}
type KV ¶
type KV interface {
View(ctx context.Context, f func(tx Tx) error) error
Update(ctx context.Context, f func(tx Tx) error) error
Close()
// Begin - creates transaction
// tx may be discarded by .Rollback() method
//
// A transaction and its cursors must only be used by a single
// thread (not goroutine), and a thread may only have a single transaction at a time.
// It happen automatically by - because this method calls runtime.LockOSThread() inside (Rollback/Commit releases it)
// By this reason application code can't call runtime.UnlockOSThread() - it leads to undefined behavior.
//
// If this `parent` is non-NULL, the new transaction
// will be a nested transaction, with the transaction indicated by parent
// as its parent. Transactions may be nested to any level. A parent
// transaction and its cursors may not issue any other operations than
// Commit and Rollback while it has active child transactions.
Begin(ctx context.Context, flags TxFlags) (Tx, error)
AllBuckets() dbutils.BucketsCfg
CollectMetrics()
}
KV low-level database interface - main target is - to provide common abstraction over top of LMDB and RemoteKV.
Common pattern for short-living transactions:
if err := db.View(ctx, func(tx ethdb.Tx) error {
... code which uses database in transaction
}); err != nil {
return err
}
Common pattern for long-living transactions:
tx, err := db.Begin(ethdb.RW)
if err != nil {
return err
}
defer tx.Rollback()
... code which uses database in transaction
err := tx.Commit()
if err != nil {
return err
}
func GenStateData ¶
type LmdbCursor ¶
type LmdbCursor struct {
// contains filtered or unexported fields
}
func (*LmdbCursor) Append ¶
func (c *LmdbCursor) Append(k []byte, v []byte) error
Append - speedy feature of lmdb which is not part of KV interface. Cast your cursor to *LmdbCursor to use this method. Return error - if provided data will not sorted (or bucket have old records which mess with new in sorting manner).
func (*LmdbCursor) Close ¶
func (c *LmdbCursor) Close()
func (*LmdbCursor) Count ¶
func (c *LmdbCursor) Count() (uint64, error)
func (*LmdbCursor) Current ¶
func (c *LmdbCursor) Current() ([]byte, []byte, error)
Current - return key/data at current cursor position
func (*LmdbCursor) Delete ¶
func (c *LmdbCursor) Delete(k, v []byte) error
func (*LmdbCursor) DeleteCurrent ¶
func (c *LmdbCursor) DeleteCurrent() error
DeleteCurrent This function deletes the key/data pair to which the cursor refers. This does not invalidate the cursor, so operations such as MDB_NEXT can still be used on it. Both MDB_NEXT and MDB_GET_CURRENT will return the same record after this operation.
func (*LmdbCursor) Next ¶
func (c *LmdbCursor) Next() (k, v []byte, err error)
func (*LmdbCursor) Prefetch ¶
func (c *LmdbCursor) Prefetch(v uint) Cursor
func (*LmdbCursor) Prefix ¶
func (c *LmdbCursor) Prefix(v []byte) Cursor
func (*LmdbCursor) Prev ¶
func (c *LmdbCursor) Prev() (k, v []byte, err error)
func (*LmdbCursor) PutCurrent ¶
func (c *LmdbCursor) PutCurrent(key []byte, value []byte) error
func (*LmdbCursor) PutNoOverwrite ¶
func (c *LmdbCursor) PutNoOverwrite(key []byte, value []byte) error
type LmdbDupSortCursor ¶
type LmdbDupSortCursor struct {
*LmdbCursor
}
func (*LmdbDupSortCursor) AppendDup ¶
func (c *LmdbDupSortCursor) AppendDup(k []byte, v []byte) error
func (*LmdbDupSortCursor) CountDuplicates ¶
func (c *LmdbDupSortCursor) CountDuplicates() (uint64, error)
Count returns the number of duplicates for the current key. See mdb_cursor_count
func (*LmdbDupSortCursor) DeleteCurrentDuplicates ¶
func (c *LmdbDupSortCursor) DeleteCurrentDuplicates() error
DeleteCurrentDuplicates - delete all of the data items for the current key.
func (*LmdbDupSortCursor) DeleteExact ¶
func (c *LmdbDupSortCursor) DeleteExact(k1, k2 []byte) error
DeleteExact - does delete
func (*LmdbDupSortCursor) FirstDup ¶
func (c *LmdbDupSortCursor) FirstDup() ([]byte, error)
func (*LmdbDupSortCursor) NextDup ¶
func (c *LmdbDupSortCursor) NextDup() ([]byte, []byte, error)
NextDup - iterate only over duplicates of current key
func (*LmdbDupSortCursor) NextNoDup ¶
func (c *LmdbDupSortCursor) NextNoDup() ([]byte, []byte, error)
NextNoDup - iterate with skipping all duplicates
func (*LmdbDupSortCursor) PrevNoDup ¶
func (c *LmdbDupSortCursor) PrevNoDup() ([]byte, []byte, error)
func (*LmdbDupSortCursor) PutCurrent ¶
func (c *LmdbDupSortCursor) PutCurrent(k, v []byte) error
Warning! this method doesn't check order of keys, it means you can insert key in wrong place of bucket
The key parameter must still be provided, and must match it. If using sorted duplicates (#MDB_DUPSORT) the data item must still sort into the same place. This is intended to be used when the new data is the same size as the old. Otherwise it will simply perform a delete of the old record followed by an insert.
func (*LmdbDupSortCursor) PutNoDupData ¶
func (c *LmdbDupSortCursor) PutNoDupData(key, value []byte) error
func (*LmdbDupSortCursor) SeekBothExact ¶
func (c *LmdbDupSortCursor) SeekBothExact(key, value []byte) ([]byte, []byte, error)
func (*LmdbDupSortCursor) SeekBothRange ¶
func (c *LmdbDupSortCursor) SeekBothRange(key, value []byte) ([]byte, []byte, error)
type LmdbKV ¶
type LmdbKV struct {
// contains filtered or unexported fields
}
func (*LmdbKV) AllBuckets ¶
func (db *LmdbKV) AllBuckets() dbutils.BucketsCfg
func (*LmdbKV) Close ¶
func (db *LmdbKV) Close()
Close closes db All transactions must be closed before closing the database.
func (*LmdbKV) CollectMetrics ¶
func (db *LmdbKV) CollectMetrics()
func (*LmdbKV) NewDbWithTheSameParameters ¶
func (db *LmdbKV) NewDbWithTheSameParameters() *ObjectDatabase
type LmdbOpts ¶
type LmdbOpts struct {
// contains filtered or unexported fields
}
func (LmdbOpts) MaxFreelistReuse ¶
func (LmdbOpts) WithBucketsConfig ¶
func (opts LmdbOpts) WithBucketsConfig(f BucketConfigsFunc) LmdbOpts
type MinDatabase ¶
type MinDatabase interface {
Get(bucket string, key []byte) ([]byte, error)
Put(bucket string, key, value []byte) error
Delete(bucket string, k, v []byte) error
}
MinDatabase is a minimalistic version of the Database interface.
type MultiPutTuples ¶
type MultiPutTuples [][]byte
Type which expecting sequence of triplets: dbi, key, value, .... It sorts entries by dbi name, then inside dbi clusters sort by keys
func (MultiPutTuples) Len ¶
func (t MultiPutTuples) Len() int
func (MultiPutTuples) Less ¶
func (t MultiPutTuples) Less(i, j int) bool
func (MultiPutTuples) Swap ¶
func (t MultiPutTuples) Swap(i, j int)
type MutationItem ¶
type MutationItem struct {
// contains filtered or unexported fields
}
type ObjectDatabase ¶
type ObjectDatabase struct {
// contains filtered or unexported fields
}
ObjectDatabase - is an object-style interface of DB accessing
func MustOpen ¶
func MustOpen(path string) *ObjectDatabase
func NewDatabaseWithFreezer ¶
func NewDatabaseWithFreezer(db *ObjectDatabase, dir, suffix string) (*ObjectDatabase, error)
func NewMemDatabase ¶
func NewMemDatabase() *ObjectDatabase
func NewMemoryDatabase ¶
func NewMemoryDatabase() *ObjectDatabase
NewMemoryDatabase is just an alias to simplify rebasing (the same name as `rawdb.NewMemoryDatabase` in vanilla geth)
func NewObjectDatabase ¶
func NewObjectDatabase(kv KV) *ObjectDatabase
NewObjectDatabase returns a AbstractDB wrapper.
func Open ¶
func Open(path string, readOnly bool) (*ObjectDatabase, error)
Open - main method to open database. Choosing driver based on path suffix. If env TEST_DB provided - choose driver based on it. Some test using this method to open non-in-memory db
func (*ObjectDatabase) Ancients ¶
func (db *ObjectDatabase) Ancients() (uint64, error)
[TURBO-GETH] Freezer support (not implemented yet) Ancients returns an error as we don't have a backing chain freezer.
func (*ObjectDatabase) Append ¶
func (db *ObjectDatabase) Append(bucket string, key []byte, value []byte) error
Append appends a single entry to the end of the bucket.
func (*ObjectDatabase) AppendDup ¶
func (db *ObjectDatabase) AppendDup(bucket string, key []byte, value []byte) error
AppendDup appends a single entry to the end of the bucket.
func (*ObjectDatabase) Begin ¶
func (db *ObjectDatabase) Begin(ctx context.Context, flags TxFlags) (DbWithPendingMutations, error)
func (*ObjectDatabase) BucketExists ¶
func (db *ObjectDatabase) BucketExists(name string) (bool, error)
func (*ObjectDatabase) ClearBuckets ¶
func (db *ObjectDatabase) ClearBuckets(buckets ...string) error
func (*ObjectDatabase) Close ¶
func (db *ObjectDatabase) Close()
func (*ObjectDatabase) Delete ¶
func (db *ObjectDatabase) Delete(bucket string, k, v []byte) error
Delete deletes the key from the queue and database
func (*ObjectDatabase) DiskSize ¶
func (db *ObjectDatabase) DiskSize(ctx context.Context) (uint64, error)
func (*ObjectDatabase) DropBuckets ¶
func (db *ObjectDatabase) DropBuckets(buckets ...string) error
func (*ObjectDatabase) Get ¶
func (db *ObjectDatabase) Get(bucket string, key []byte) ([]byte, error)
Get returns the value for a given key if it's present.
func (*ObjectDatabase) IdealBatchSize ¶
func (db *ObjectDatabase) IdealBatchSize() int
IdealBatchSize defines the size of the data batches should ideally add in one write.
func (*ObjectDatabase) KV ¶
func (db *ObjectDatabase) KV() KV
func (*ObjectDatabase) Keys ¶
func (db *ObjectDatabase) Keys() ([][]byte, error)
func (*ObjectDatabase) MemCopy ¶
func (db *ObjectDatabase) MemCopy() *ObjectDatabase
func (*ObjectDatabase) MultiPut ¶
func (db *ObjectDatabase) MultiPut(tuples ...[]byte) (uint64, error)
MultiPut - requirements: input must be sorted and without duplicates
func (*ObjectDatabase) NewBatch ¶
func (db *ObjectDatabase) NewBatch() DbWithPendingMutations
func (*ObjectDatabase) Put ¶
func (db *ObjectDatabase) Put(bucket string, key []byte, value []byte) error
Put inserts or updates a single entry.
func (*ObjectDatabase) Sequence ¶
func (db *ObjectDatabase) Sequence(bucket string, amount uint64) (res uint64, err error)
func (*ObjectDatabase) SetKV ¶
func (db *ObjectDatabase) SetKV(kv KV)
func (*ObjectDatabase) TruncateAncients ¶
func (db *ObjectDatabase) TruncateAncients(items uint64) error
TruncateAncients returns an error as we don't have a backing chain freezer.
type Putter ¶
type Putter interface {
// Put inserts or updates a single entry.
Put(bucket string, key, value []byte) error
}
Putter wraps the database write operations.
type RWCounterDecorator ¶
type RWCounterDecorator struct {
Database
DBCounterStats
}
func NewRWDecorator ¶
func NewRWDecorator(db Database) *RWCounterDecorator
func (*RWCounterDecorator) Delete ¶
func (d *RWCounterDecorator) Delete(bucket string, k, v []byte) error
func (*RWCounterDecorator) Get ¶
func (d *RWCounterDecorator) Get(bucket string, key []byte) ([]byte, error)
func (*RWCounterDecorator) Has ¶
func (d *RWCounterDecorator) Has(bucket string, key []byte) (bool, error)
func (*RWCounterDecorator) MultiPut ¶
func (d *RWCounterDecorator) MultiPut(tuples ...[]byte) (uint64, error)
func (*RWCounterDecorator) NewBatch ¶
func (d *RWCounterDecorator) NewBatch() DbWithPendingMutations
type RemoteBackend ¶
type RemoteBackend struct {
// contains filtered or unexported fields
}
func (*RemoteBackend) AddLocal ¶
func (back *RemoteBackend) AddLocal(signedTx []byte) ([]byte, error)
func (*RemoteBackend) NetVersion ¶
func (back *RemoteBackend) NetVersion() (uint64, error)
func (*RemoteBackend) Subscribe ¶
func (back *RemoteBackend) Subscribe(onNewEvent func(*remote.SubscribeReply)) error
type RemoteKV ¶
type RemoteKV struct {
// contains filtered or unexported fields
}
func (*RemoteKV) AllBuckets ¶
func (db *RemoteKV) AllBuckets() dbutils.BucketsCfg
func (*RemoteKV) Close ¶
func (db *RemoteKV) Close()
Close All transactions must be closed before closing the database.
func (*RemoteKV) CollectMetrics ¶
func (db *RemoteKV) CollectMetrics()
type SnapshotKV2 ¶
type SnapshotKV2 struct {
// contains filtered or unexported fields
}
func (*SnapshotKV2) AllBuckets ¶
func (s *SnapshotKV2) AllBuckets() dbutils.BucketsCfg
func (*SnapshotKV2) Close ¶
func (s *SnapshotKV2) Close()
func (*SnapshotKV2) CollectMetrics ¶
func (s *SnapshotKV2) CollectMetrics()
type StorageMode ¶
func GetStorageModeFromDB ¶
func GetStorageModeFromDB(db Database) (StorageMode, error)
func StorageModeFromString ¶
func StorageModeFromString(flags string) (StorageMode, error)
func (StorageMode) ToString ¶
func (m StorageMode) ToString() string
type Tx ¶
type Tx interface {
// Cursor - creates cursor object on top of given bucket. Type of cursor - depends on bucket configuration.
// If bucket was created with lmdb.DupSort flag, then cursor with interface CursorDupSort created
// Otherwise - object of interface Cursor created
//
// Cursor, also provides a grain of magic - it can use a declarative configuration - and automatically break
// long keys into DupSort key/values. See docs for `bucket.go:BucketConfigItem`
Cursor(bucket string) Cursor
CursorDupSort(bucket string) CursorDupSort // CursorDupSort - can be used if bucket has lmdb.DupSort flag
GetOne(bucket string, key []byte) (val []byte, err error)
HasOne(bucket string, key []byte) (bool, error)
Commit(ctx context.Context) error // Commit all the operations of a transaction into the database.
Rollback() // Rollback - abandon all the operations of the transaction instead of saving them.
BucketSize(name string) (uint64, error)
Comparator(bucket string) dbutils.CmpFunc
Cmp(bucket string, a, b []byte) int
DCmp(bucket string, a, b []byte) int
// Allows to create a linear sequence of unique positive integers for each table.
// Can be called for a read transaction to retrieve the current sequence value, and the increment must be zero.
// Sequence changes become visible outside the current write transaction after it is committed, and discarded on abort.
// Starts from 0.
Sequence(bucket string, amount uint64) (uint64, error)
CHandle() unsafe.Pointer // Pointer to the underlying C transaction handle (e.g. *C.MDB_txn)
}
type TxDb ¶
type TxDb struct {
// contains filtered or unexported fields
}
TxDb - provides Database interface around ethdb.Tx It's not thread-safe! TxDb not usable after .Commit()/.Rollback() call, but usable after .CommitAndBegin() call you can put unlimited amount of data into this class, call IdealBatchSize is unnecessary Walk and MultiWalk methods - work outside of Tx object yet, will implement it later
func NewTxDbWithoutTransaction ¶
NewTxDbWithoutTransaction creates TxDb object without opening transaction, such TxDb not usable before .Begin() call on it It allows inject TxDb object into class hierarchy, but open write transaction later
func (*TxDb) Ancients ¶
[TURBO-GETH] Freezer support (not implemented yet) Ancients returns an error as we don't have a backing chain freezer.
func (*TxDb) ClearBuckets ¶
func (*TxDb) DropBuckets ¶
func (*TxDb) IdealBatchSize ¶
IdealBatchSize defines the size of the data batches should ideally add in one write.
func (*TxDb) NewBatch ¶
func (m *TxDb) NewBatch() DbWithPendingMutations
func (*TxDb) TruncateAncients ¶
TruncateAncients returns an error as we don't have a backing chain freezer.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal/lmdbarch
Package lmdbarch contains some architecture detection constants.
|
Package lmdbarch contains some architecture detection constants. |
|
Code generated by go generate; DO NOT EDIT.
|
Code generated by go generate; DO NOT EDIT. |
|
internal
command
|