Documentation ¶
Overview ¶
Package database defines interfaces to key value type databases used by various components in go-spacemesh node
Index ¶
- Constants
- Variables
- type Batch
- type Database
- type Deleter
- type Getter
- type Iterator
- type LDBDatabase
- func (db *LDBDatabase) Close()
- func (db *LDBDatabase) Delete(key []byte) error
- func (db *LDBDatabase) Find(key []byte) Iterator
- func (db *LDBDatabase) Get(key []byte) ([]byte, error)
- func (db *LDBDatabase) Has(key []byte) (bool, error)
- func (db *LDBDatabase) Iterator() iterator.Iterator
- func (db *LDBDatabase) LDB() *leveldb.DB
- func (db *LDBDatabase) Meter(prefix string)
- func (db *LDBDatabase) NewBatch() Batch
- func (db *LDBDatabase) NewIterator() iterator.Iterator
- func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
- func (db *LDBDatabase) Path() string
- func (db *LDBDatabase) Put(key []byte, value []byte) error
- type Putter
- type Store
Constants ¶
const IdealBatchSize = 100 * 1024
IdealBatchSize is the best batch size Code using batches should try to add this much data to the batch. The value was determined empirically.
Variables ¶
var ErrNotFound = errors.ErrNotFound
ErrNotFound is special type error for not found in DB.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface { Putter Deleter ValueSize() int // amount of data in the batch Write() error // Reset resets the batch for reuse Reset() }
Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.
type Database ¶
type Database interface { Putter Deleter Get(key []byte) ([]byte, error) Has(key []byte) (bool, error) Close() NewBatch() Batch Find(key []byte) Iterator }
Database wraps all database operations. All methods are safe for concurrent use.
type Deleter ¶
Deleter wraps the database delete operation supported by both batches and regular databases.
type LDBDatabase ¶
type LDBDatabase struct {
// contains filtered or unexported fields
}
LDBDatabase is a wrapper for leveldb database with concurrent access.
func NewLDBDatabase ¶
NewLDBDatabase returns a LevelDB wrapped object.
func NewMemDatabase ¶
func NewMemDatabase() *LDBDatabase
NewMemDatabase returns a memory database instance.
func (*LDBDatabase) Close ¶
func (db *LDBDatabase) Close()
Close closes database, flushing writes and denying all new write requests.
func (*LDBDatabase) Delete ¶
func (db *LDBDatabase) Delete(key []byte) error
Delete deletes the key from the queue and database.
func (*LDBDatabase) Find ¶
func (db *LDBDatabase) Find(key []byte) Iterator
Find returns iterator to iterate over values with given prefix key.
func (*LDBDatabase) Get ¶
func (db *LDBDatabase) Get(key []byte) ([]byte, error)
Get returns the given key if it's present.
func (*LDBDatabase) Has ¶
func (db *LDBDatabase) Has(key []byte) (bool, error)
Has returns whether the db contains the key.
func (*LDBDatabase) Iterator ¶
func (db *LDBDatabase) Iterator() iterator.Iterator
Iterator returns iterator iterating over all database keys.
func (*LDBDatabase) LDB ¶
func (db *LDBDatabase) LDB() *leveldb.DB
LDB returns the actual inner leveldb struct reference.
func (*LDBDatabase) Meter ¶
func (db *LDBDatabase) Meter(prefix string)
Meter configures the database metrics collectors and.
func (*LDBDatabase) NewBatch ¶
func (db *LDBDatabase) NewBatch() Batch
NewBatch creates a new batch write struct, able to add multiple values in a single operation.
func (*LDBDatabase) NewIterator ¶
func (db *LDBDatabase) NewIterator() iterator.Iterator
NewIterator creates a new leveldb iterator struct compliant with Iterator interface.
func (*LDBDatabase) NewIteratorWithPrefix ¶
func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.
func (*LDBDatabase) Path ¶
func (db *LDBDatabase) Path() string
Path returns the path to the database directory.