Documentation ¶
Index ¶
- Constants
- Variables
- func FormatSegmentFilename(blockNumber uint64) string
- func KeyBlockNumber(key []byte) (num uint64, ok bool)
- func ParseSegmentFilename(filename string) (uint64, error)
- type Batch
- type Database
- type DatabaseSegment
- type LDBDatabase
- func (db *LDBDatabase) Close()
- func (db *LDBDatabase) Delete(key []byte) error
- func (db *LDBDatabase) Get(key []byte) ([]byte, error)
- func (db *LDBDatabase) Has(key []byte) (bool, error)
- func (db *LDBDatabase) LDB() *leveldb.DB
- func (db *LDBDatabase) Meter(prefix string)
- func (db *LDBDatabase) NewBatch() Batch
- func (db *LDBDatabase) NewIterator(slice *util.Range, ro *opt.ReadOptions) iterator.Iterator
- func (db *LDBDatabase) Path() string
- func (db *LDBDatabase) Put(key []byte, value []byte) error
- type MemDatabase
- func (db *MemDatabase) Close()
- func (db *MemDatabase) Delete(key []byte) error
- func (db *MemDatabase) Get(key []byte) ([]byte, error)
- func (db *MemDatabase) Has(key []byte) (bool, error)
- func (db *MemDatabase) Keys() [][]byte
- func (db *MemDatabase) Len() int
- func (db *MemDatabase) NewBatch() Batch
- func (db *MemDatabase) Put(key []byte, value []byte) error
- type NewDatabaseFunc
- type NewDatabaseOptions
- type Putter
- type SegmentedDatabase
- func (db *SegmentedDatabase) Close()
- func (db *SegmentedDatabase) CreateSegmentIfNotExists(num uint64) (*DatabaseSegment, error)
- func (db *SegmentedDatabase) Delete(key []byte) error
- func (db *SegmentedDatabase) Get(key []byte) ([]byte, error)
- func (db *SegmentedDatabase) Has(key []byte) (bool, error)
- func (db *SegmentedDatabase) Put(key, value []byte) error
- func (db *SegmentedDatabase) Segment(num uint64) *DatabaseSegment
Constants ¶
const IdealBatchSize = 100 * 1024
Code using batches should try to add this much data to the batch. The value was determined empirically.
Variables ¶
var (
ErrInvalidSegmentFilename = errors.New("invalid segment filename")
)
var OpenFileLimit = 64
Functions ¶
func FormatSegmentFilename ¶
FormatSegmentFilename returns a segment filename.
func KeyBlockNumber ¶
KeyBlockNumber returns the block number for a given key and returns ok true. If the key does not encode the block number then ok is false.
func ParseSegmentFilename ¶
ParseSegmentFilename returns a block number for a given segment filename.
Types ¶
type Batch ¶
type Batch interface { Putter 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.
func NewTableBatch ¶
NewTableBatch returns a Batch object which prefixes all keys with a given string.
type Database ¶
type Database interface { Putter Get(key []byte) ([]byte, error) Has(key []byte) (bool, error) Delete(key []byte) error Close() NewBatch() Batch }
Database wraps all database operations. All methods are safe for concurrent use.
type DatabaseSegment ¶
type DatabaseSegment struct {
// contains filtered or unexported fields
}
DatabaseSegment represents data for single block number.
func NewDatabaseSegment ¶
func NewDatabaseSegment(blockNumber uint64, db Database) *DatabaseSegment
NewDatabaseSegment returns a new instance of DatabaseSegment.
type LDBDatabase ¶
type LDBDatabase struct {
// contains filtered or unexported fields
}
func NewLDBDatabase ¶
func NewLDBDatabase(file string, cache int, handles int) (*LDBDatabase, error)
NewLDBDatabase returns a LevelDB wrapped object.
func (*LDBDatabase) Close ¶
func (db *LDBDatabase) Close()
func (*LDBDatabase) Delete ¶
func (db *LDBDatabase) Delete(key []byte) error
Delete deletes the key from the queue and database
func (*LDBDatabase) Get ¶
func (db *LDBDatabase) Get(key []byte) ([]byte, error)
Get returns the given key if it's present.
func (*LDBDatabase) LDB ¶ added in v0.9.34
func (db *LDBDatabase) LDB() *leveldb.DB
func (*LDBDatabase) Meter ¶ added in v0.9.38
func (db *LDBDatabase) Meter(prefix string)
Meter configures the database metrics collectors and
func (*LDBDatabase) NewBatch ¶
func (db *LDBDatabase) NewBatch() Batch
func (*LDBDatabase) NewIterator ¶
func (db *LDBDatabase) NewIterator(slice *util.Range, ro *opt.ReadOptions) iterator.Iterator
func (*LDBDatabase) Path ¶
func (db *LDBDatabase) Path() string
Path returns the path to the database directory.
type MemDatabase ¶
type MemDatabase struct {
// contains filtered or unexported fields
}
* This is a test memory database. Do not use for any production it does not get persisted
func NewMemDatabase ¶
func NewMemDatabase() *MemDatabase
func (*MemDatabase) Close ¶
func (db *MemDatabase) Close()
func (*MemDatabase) Delete ¶
func (db *MemDatabase) Delete(key []byte) error
func (*MemDatabase) Keys ¶
func (db *MemDatabase) Keys() [][]byte
func (*MemDatabase) Len ¶
func (db *MemDatabase) Len() int
func (*MemDatabase) NewBatch ¶
func (db *MemDatabase) NewBatch() Batch
type NewDatabaseFunc ¶
type NewDatabaseFunc func(NewDatabaseOptions) (Database, error)
NewDatabaseFunc represents a function for generating a new database.
type NewDatabaseOptions ¶
type NewDatabaseOptions struct {
Path string // on-disk path
}
NewDatabaseOptions represents options passed to NewDatabaseFunc.
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.
type SegmentedDatabase ¶
type SegmentedDatabase struct { // Filename of the root database directory. Path string // Generates a new instance of Database for a segment. NewDatabase NewDatabaseFunc // contains filtered or unexported fields }
SegmentedDatabase represents a database segmented by block number. Each segment contains data for a different block number.
func NewSegmentedDatabase ¶
func NewSegmentedDatabase(path string) (*SegmentedDatabase, error)
NewSegmentedDatabase returns a new instance of SegmentedDatabase.
func (*SegmentedDatabase) Close ¶
func (db *SegmentedDatabase) Close()
Close closes all global and segment databases.
func (*SegmentedDatabase) CreateSegmentIfNotExists ¶
func (db *SegmentedDatabase) CreateSegmentIfNotExists(num uint64) (*DatabaseSegment, error)
CreateSegmentIfNotExists finds or creates a segment by block number.
func (*SegmentedDatabase) Delete ¶
func (db *SegmentedDatabase) Delete(key []byte) error
Delete deletes the key from database.
func (*SegmentedDatabase) Get ¶
func (db *SegmentedDatabase) Get(key []byte) ([]byte, error)
Get returns the value of a given key.
func (*SegmentedDatabase) Has ¶
func (db *SegmentedDatabase) Has(key []byte) (bool, error)
Has returns true if key exists.
func (*SegmentedDatabase) Put ¶
func (db *SegmentedDatabase) Put(key, value []byte) error
Put writes the key/value pair to the database.
func (*SegmentedDatabase) Segment ¶
func (db *SegmentedDatabase) Segment(num uint64) *DatabaseSegment
Segment finds a segment by block number.