Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeBlockNumber(number uint64) []byte
- type Batch
- type Database
- type Deleter
- type Iterator
- type KeyValue
- 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() 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 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) NewIterator() iterator.Iterator
- func (db *MemDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
- func (db *MemDatabase) Put(key []byte, value []byte) error
- type MemIterator
- func (i *MemIterator) Error() error
- func (i *MemIterator) First() bool
- func (i *MemIterator) Key() []byte
- func (i *MemIterator) Last() bool
- func (i *MemIterator) Next() bool
- func (i *MemIterator) Prev() bool
- func (i *MemIterator) Release()
- func (i *MemIterator) Seek(key []byte) bool
- func (i *MemIterator) SetReleaser(releaser util.Releaser)
- func (i *MemIterator) Valid() bool
- func (i *MemIterator) Value() []byte
- type Putter
- type Tempdb
- func (db *Tempdb) Clear()
- func (db *Tempdb) Close()
- func (db *Tempdb) Delete(key []byte) error
- func (db *Tempdb) Get(key []byte) ([]byte, error)
- func (db *Tempdb) Has(key []byte) (bool, error)
- func (db *Tempdb) Len() int
- func (db *Tempdb) NewBatch() Batch
- func (db *Tempdb) NewIterator() iterator.Iterator
- func (db *Tempdb) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
- func (db *Tempdb) Put(key []byte, value []byte) error
- type TempdbIterator
- func (i *TempdbIterator) Error() error
- func (i *TempdbIterator) First() bool
- func (i *TempdbIterator) Key() []byte
- func (i *TempdbIterator) Last() bool
- func (i *TempdbIterator) Next() bool
- func (i *TempdbIterator) Prev() bool
- func (i *TempdbIterator) Release()
- func (i *TempdbIterator) Seek(key []byte) bool
- func (i *TempdbIterator) SetReleaser(releaser util.Releaser)
- func (i *TempdbIterator) Valid() bool
- func (i *TempdbIterator) Value() []byte
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 ( ErrReleased = errors.New("leveldb: resource already relesed") ErrHasReleaser = errors.New("leveldb: releaser already defined") )
var OpenFileLimit = 64
Functions ¶
func EncodeBlockNumber ¶
encodeBlockNumber encodes a block number as big endian uint64
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.
func NewTableBatch ¶
NewTableBatch returns a Batch object which prefixes all keys with a given string.
type Database ¶
type Database interface { Putter Deleter Get(key []byte) ([]byte, error) Has(key []byte) (bool, error) Close() NewBatch() Batch NewIterator() iterator.Iterator NewIteratorWithPrefix(prefix []byte) iterator.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
}
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 ¶
func (db *LDBDatabase) LDB() *leveldb.DB
func (*LDBDatabase) Meter ¶
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() iterator.Iterator
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.
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, error)
func NewMemDatabaseWithCap ¶
func NewMemDatabaseWithCap(size int) (*MemDatabase, error)
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
func (*MemDatabase) NewIterator ¶
func (db *MemDatabase) NewIterator() iterator.Iterator
func (*MemDatabase) NewIteratorWithPrefix ¶
func (db *MemDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.
type MemIterator ¶
type MemIterator struct {
// contains filtered or unexported fields
}
func (*MemIterator) Error ¶
func (i *MemIterator) Error() error
func (*MemIterator) Key ¶
func (i *MemIterator) Key() []byte
func (*MemIterator) Last ¶
func (i *MemIterator) Last() bool
func (*MemIterator) Next ¶
func (i *MemIterator) Next() bool
func (*MemIterator) Prev ¶
func (i *MemIterator) Prev() bool
func (*MemIterator) Release ¶
func (i *MemIterator) Release()
func (*MemIterator) Seek ¶
func (i *MemIterator) Seek(key []byte) bool
func (*MemIterator) SetReleaser ¶
func (i *MemIterator) SetReleaser(releaser util.Releaser)
func (*MemIterator) Valid ¶
func (i *MemIterator) Valid() bool
func (*MemIterator) Value ¶
func (i *MemIterator) Value() []byte
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.
type Tempdb ¶ added in v1.0.6
type Tempdb struct {
// contains filtered or unexported fields
}
func (*Tempdb) NewIterator ¶ added in v1.0.6
func (*Tempdb) NewIteratorWithPrefix ¶ added in v1.0.6
NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix. 这个最复杂,需要先去db数据库查询出map,然后把temp的列举出来,同样key的会被替换成新值,如果出现在del里面就删除,然后map转KeyValue数组
type TempdbIterator ¶ added in v1.0.6
type TempdbIterator struct {
// contains filtered or unexported fields
}
func (*TempdbIterator) Error ¶ added in v1.0.6
func (i *TempdbIterator) Error() error
func (*TempdbIterator) First ¶ added in v1.0.6
func (i *TempdbIterator) First() bool
implement iterator interface
func (*TempdbIterator) Key ¶ added in v1.0.6
func (i *TempdbIterator) Key() []byte
func (*TempdbIterator) Last ¶ added in v1.0.6
func (i *TempdbIterator) Last() bool
func (*TempdbIterator) Next ¶ added in v1.0.6
func (i *TempdbIterator) Next() bool
func (*TempdbIterator) Prev ¶ added in v1.0.6
func (i *TempdbIterator) Prev() bool
func (*TempdbIterator) Release ¶ added in v1.0.6
func (i *TempdbIterator) Release()
func (*TempdbIterator) Seek ¶ added in v1.0.6
func (i *TempdbIterator) Seek(key []byte) bool
func (*TempdbIterator) SetReleaser ¶ added in v1.0.6
func (i *TempdbIterator) SetReleaser(releaser util.Releaser)
func (*TempdbIterator) Valid ¶ added in v1.0.6
func (i *TempdbIterator) Valid() bool
func (*TempdbIterator) Value ¶ added in v1.0.6
func (i *TempdbIterator) Value() []byte