Documentation ¶
Index ¶
- Constants
- func IsKeyInDomain(key, start, end []byte, isReverse bool) bool
- func NewDebugBatch(label string, bch Batch) debugBatch
- func NewDebugDB(label string, db DB) debugDB
- func NewDebugIterator(label string, itr Iterator) debugIterator
- func NewPrefixDB(db DB, prefix []byte) *prefixDB
- func PrefixToEnd(prefix []byte) []byte
- type BadgerDB
- func (db *BadgerDB) Close()
- func (db *BadgerDB) Del(key []byte) error
- func (db *BadgerDB) Delete(key []byte)
- func (db *BadgerDB) DeleteSync(key []byte)
- func (db *BadgerDB) Dir() string
- func (db *BadgerDB) Exist(key []byte) (bool, error)
- func (db *BadgerDB) Get(key []byte) []byte
- func (db *BadgerDB) Has(key []byte) bool
- func (db *BadgerDB) Iterator(start, end []byte) Iterator
- func (db *BadgerDB) Load(key []byte) ([]byte, error)
- func (db *BadgerDB) NewBatch() Batch
- func (db *BadgerDB) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *BadgerDB) Print()
- func (db *BadgerDB) Put(key []byte, val []byte) error
- func (db *BadgerDB) ReverseIterator(start, end []byte) Iterator
- func (db *BadgerDB) Set(key []byte, val []byte)
- func (db *BadgerDB) SetSync(key []byte, val []byte)
- func (db *BadgerDB) Stats() map[string]string
- type Batch
- type BoltDB
- func (db *BoltDB) Close()
- func (db *BoltDB) Del(key []byte) error
- func (db *BoltDB) Delete(key []byte)
- func (db *BoltDB) DeleteSync(key []byte)
- func (db *BoltDB) Dir() string
- func (db *BoltDB) Exist(key []byte) (bool, error)
- func (db *BoltDB) Get(key []byte) []byte
- func (db *BoltDB) Has(key []byte) bool
- func (db *BoltDB) Iterator(start, end []byte) Iterator
- func (db *BoltDB) Load(key []byte) ([]byte, error)
- func (db *BoltDB) NewBatch() Batch
- func (db *BoltDB) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *BoltDB) Print()
- func (db *BoltDB) Put(key []byte, val []byte) error
- func (db *BoltDB) ReverseIterator(start, end []byte) Iterator
- func (db *BoltDB) Set(key []byte, val []byte)
- func (db *BoltDB) SetSync(key []byte, val []byte)
- func (db *BoltDB) Stats() map[string]string
- type DB
- type DBBackendCounts
- type DBBackendType
- type FSDB
- func (db *FSDB) Close()
- func (db *FSDB) Del(key []byte) error
- func (db *FSDB) Delete(key []byte)
- func (db *FSDB) DeleteNoLock(key []byte)
- func (db *FSDB) DeleteNoLockNoPanic(key []byte) error
- func (db *FSDB) DeleteSync(key []byte)
- func (db *FSDB) Dir() string
- func (db *FSDB) Exist(key []byte) (bool, error)
- func (db *FSDB) Get(key []byte) []byte
- func (db *FSDB) Has(key []byte) bool
- func (db *FSDB) Iterator(start, end []byte) Iterator
- func (db *FSDB) Load(key []byte) ([]byte, error)
- func (db *FSDB) MakeIterator(start, end []byte, isReversed bool) Iterator
- func (db *FSDB) Mutex() *sync.Mutex
- func (db *FSDB) NewBatch() Batch
- func (db *FSDB) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *FSDB) Print()
- func (db *FSDB) Put(key []byte, value []byte) error
- func (db *FSDB) ReverseIterator(start, end []byte) Iterator
- func (db *FSDB) Set(key []byte, value []byte)
- func (db *FSDB) SetNoLock(key []byte, value []byte)
- func (db *FSDB) SetNoLockNoPanic(key []byte, value []byte) error
- func (db *FSDB) SetSync(key []byte, value []byte)
- func (db *FSDB) Stats() map[string]string
- type GoLevelDB
- func (db *GoLevelDB) Close()
- func (db *GoLevelDB) Del(key []byte) error
- func (db *GoLevelDB) Delete(key []byte)
- func (db *GoLevelDB) DeleteSync(key []byte)
- func (db *GoLevelDB) Dir() string
- func (db *GoLevelDB) Exist(key []byte) (bool, error)
- func (db *GoLevelDB) Get(key []byte) []byte
- func (db *GoLevelDB) Has(key []byte) bool
- func (db *GoLevelDB) Iterator(start, end []byte) Iterator
- func (db *GoLevelDB) Load(key []byte) ([]byte, error)
- func (db *GoLevelDB) NewBatch() Batch
- func (db *GoLevelDB) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *GoLevelDB) Print()
- func (db *GoLevelDB) Put(key []byte, value []byte) error
- func (db *GoLevelDB) ReverseIterator(start, end []byte) Iterator
- func (db *GoLevelDB) Set(key []byte, value []byte)
- func (db *GoLevelDB) SetSync(key []byte, value []byte)
- func (db *GoLevelDB) Stats() map[string]string
- type Iterator
- type MemDB
- func (db *MemDB) Close()
- func (db *MemDB) Del(key []byte) error
- func (db *MemDB) Delete(key []byte)
- func (db *MemDB) DeleteNoLock(key []byte)
- func (db *MemDB) DeleteNoLockSync(key []byte)
- func (db *MemDB) DeleteSync(key []byte)
- func (db *MemDB) Dir() string
- func (db *MemDB) Exist(key []byte) (bool, error)
- func (db *MemDB) Get(key []byte) []byte
- func (db *MemDB) Has(key []byte) bool
- func (db *MemDB) Iterator(start, end []byte) Iterator
- func (db *MemDB) Keys() [][]byte
- func (db *MemDB) Len() int
- func (db *MemDB) Load(key []byte) ([]byte, error)
- func (db *MemDB) Mutex() *sync.Mutex
- func (db *MemDB) NewBatch() Batch
- func (db *MemDB) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *MemDB) Print()
- func (db *MemDB) Put(key []byte, value []byte) error
- func (db *MemDB) ReverseIterator(start, end []byte) Iterator
- func (db *MemDB) Set(key []byte, value []byte)
- func (db *MemDB) SetNoLock(key []byte, value []byte)
- func (db *MemDB) SetNoLockSync(key []byte, value []byte)
- func (db *MemDB) SetSync(key []byte, value []byte)
- func (db *MemDB) Stats() map[string]string
- type Putter
- type SetDeleter
Constants ¶
const IdealBatchSize = 100 * 1024
Code using batches should try to add this much data to the batch. The value was determined empirically.
Variables ¶
This section is empty.
Functions ¶
func IsKeyInDomain ¶
See DB interface documentation for more information.
func NewDebugBatch ¶
For printing all operationgs to the console for debugging.
func NewDebugDB ¶
For printing all operationgs to the console for debugging.
func NewDebugIterator ¶
For printing all operationgs to the console for debugging.
func NewPrefixDB ¶
NewPrefixDB lets you namespace multiple DBs within a single DB.
func PrefixToEnd ¶
PrefixToEnd returns end that satisfy the given prefix. This only applicable for the standard 'bytes comparer'.
Types ¶
type BadgerDB ¶
type BadgerDB struct {
// contains filtered or unexported fields
}
func (*BadgerDB) NewIteratorWithPrefix ¶
func (*BadgerDB) ReverseIterator ¶
Implements DB.
type Batch ¶
type Batch interface { SetDeleter Write() Commit() error WriteSync() ValueSize() int // amount of data in the batch Reset() // Reset resets the batch for reuse }
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
func (*BoltDB) DeleteSync ¶
func (*BoltDB) NewIteratorWithPrefix ¶
func (*BoltDB) ReverseIterator ¶
type DB ¶
type DB interface { // Get returns nil iff key doesn't exist. // A nil key is interpreted as an empty byteslice. // CONTRACT: key, value readonly []byte Get([]byte) []byte Load([]byte) ([]byte, error) // Has checks if a key exists. // A nil key is interpreted as an empty byteslice. // CONTRACT: key, value readonly []byte Has(key []byte) bool Exist(key []byte) (bool, error) // Set sets the key. // A nil key is interpreted as an empty byteslice. // CONTRACT: key, value readonly []byte Set([]byte, []byte) Put([]byte, []byte) error SetSync([]byte, []byte) // Delete deletes the key. // A nil key is interpreted as an empty byteslice. // CONTRACT: key readonly []byte Delete([]byte) Del([]byte) error DeleteSync([]byte) // Iterate over a domain of keys in ascending order. End is exclusive. // Start must be less than end, or the Iterator is invalid. // A nil start is interpreted as an empty byteslice. // If end is nil, iterates up to the last item (inclusive). // CONTRACT: No writes may happen within a domain while an iterator exists over it. // CONTRACT: start, end readonly []byte Iterator(start, end []byte) Iterator // Iterate over a domain of keys in descending order. End is exclusive. // Start must be greater than end, or the Iterator is invalid. // If start is nil, iterates from the last/greatest item (inclusive). // If end is nil, iterates up to the first/least item (inclusive). // CONTRACT: No writes may happen within a domain while an iterator exists over it. // CONTRACT: start, end readonly []byte ReverseIterator(start, end []byte) Iterator NewIteratorWithPrefix(prefix []byte) Iterator Dir() string // Closes the connection. Close() // Creates a batch for atomic updates. NewBatch() Batch // For debugging Print() // Stats returns a map of property values for all keys and the size of the cache. Stats() map[string]string }
DBs are goroutine safe.
type DBBackendCounts ¶
type DBBackendCounts uint64
type DBBackendType ¶
type DBBackendType string
const ( LevelDBBackend DBBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc CLevelDBBackend DBBackendType = "cleveldb" GoLevelDBBackend DBBackendType = "goleveldb" MemDBBackend DBBackendType = "memdb" FSDBBackend DBBackendType = "fsdb" // using the filesystem naively BadgerBackend DBBackendType = "badger" // using badger BoltBackend DBBackendType = "bolt" // using bolt )
type FSDB ¶
type FSDB struct {
// contains filtered or unexported fields
}
It's slow.
func (*FSDB) DeleteNoLock ¶
NOTE: Implements atomicSetDeleter.
func (*FSDB) DeleteNoLockNoPanic ¶
func (*FSDB) DeleteSync ¶
func (*FSDB) MakeIterator ¶
func (*FSDB) NewIteratorWithPrefix ¶
func (*FSDB) ReverseIterator ¶
type GoLevelDB ¶
type GoLevelDB struct {
// contains filtered or unexported fields
}
func (*GoLevelDB) NewIteratorWithPrefix ¶
func (*GoLevelDB) ReverseIterator ¶
Implements DB.
type Iterator ¶
type Iterator interface { // The start & end (exclusive) limits to iterate over. // If end < start, then the Iterator goes in reverse order. // // A domain of ([]byte{12, 13}, []byte{12, 14}) will iterate // over anything with the prefix []byte{12, 13}. // // The smallest key is the empty byte array []byte{} - see BeginningKey(). // The largest key is the nil byte array []byte(nil) - see EndingKey(). // CONTRACT: start, end readonly []byte Domain() (start []byte, end []byte) // Valid returns whether the current position is valid. // Once invalid, an Iterator is forever invalid. Valid() bool // Next moves the iterator to the next sequential key in the database, as // defined by order of iteration. // // If Valid returns false, this method will panic. Next() bool // No panic when returned to false Seek(key []byte) bool // Key returns the key of the cursor. // If Valid returns false, this method will panic. // CONTRACT: key readonly []byte Key() (key []byte) // Value returns the value of the cursor. // If Valid returns false, this method will panic. // CONTRACT: value readonly []byte Value() (value []byte) // Close releases the Iterator. Close() }
Usage:
var itr Iterator = ... defer itr.Close()
for ; itr.Valid(); itr.Next() { k, v := itr.Key(); itr.Value() // ... }
func IteratePrefix ¶
IteratePrefix is a convenience function for iterating over a key domain restricted by prefix.
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
func (*MemDB) DeleteNoLockSync ¶
Implements atomicSetDeleter.
func (*MemDB) NewIteratorWithPrefix ¶
func (*MemDB) ReverseIterator ¶
Implements DB.
func (*MemDB) SetNoLockSync ¶
Implements atomicSetDeleter.
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.