Conf configuration for `DB`
type Conf struct { DBPath string }
DB - a wrapper on an actual store
type DB struct {
// contains filtered or unexported fields
}
func CreateDB(conf *Conf) *DB
CreateDB constructs a `DB`
func (dbInst *DB) Close()
Close closes the underlying db
func (dbInst *DB) Delete(key []byte, sync bool) error
Delete deletes the given key
func (dbInst *DB) Get(key []byte) ([]byte, error)
Get returns the value for the given key
func (dbInst *DB) GetIterator(startKey []byte, endKey []byte) iterator.Iterator
GetIterator returns an iterator over key-value store. The iterator should be released after the use. The resultset contains all the keys that are present in the db between the startKey (inclusive) and the endKey (exclusive). A nil startKey represents the first available key and a nil endKey represent a logical key after the last available key
func (dbInst *DB) Open()
Open opens the underlying db
func (dbInst *DB) Put(key []byte, value []byte, sync bool) error
Put saves the key/value
func (dbInst *DB) WriteBatch(batch *leveldb.Batch, sync bool) error
WriteBatch writes a batch
DBHandle is an handle to a named db
type DBHandle struct {
// contains filtered or unexported fields
}
func (h *DBHandle) Delete(key []byte, sync bool) error
Delete deletes the given key
func (h *DBHandle) Get(key []byte) ([]byte, error)
Get returns the value for the given key
func (h *DBHandle) GetIterator(startKey []byte, endKey []byte) *Iterator
GetIterator gets an handle to iterator. The iterator should be released after the use. The resultset contains all the keys that are present in the db between the startKey (inclusive) and the endKey (exclusive). A nil startKey represents the first available key and a nil endKey represent a logical key after the last available key
func (h *DBHandle) Put(key []byte, value []byte, sync bool) error
Put saves the key/value
func (h *DBHandle) WriteBatch(batch *UpdateBatch, sync bool) error
WriteBatch writes a batch in an atomic way
FileLock encapsulate the DB that holds the file lock. As the FileLock to be used by a single process/goroutine, there is no need for the semaphore to synchronize the FileLock usage.
type FileLock struct {
// contains filtered or unexported fields
}
func NewFileLock(filePath string) *FileLock
NewFileLock returns a new file based lock manager.
func (f *FileLock) Lock() error
Lock acquire a file lock. We achieve this by opening a db for the given filePath. Internally, leveldb acquires a file lock while opening a db. If the db is opened again by the same or another process, error would be returned. When the db is closed or the owner process dies, the lock would be released and hence the other process can open the db. We exploit this leveldb functionality to acquire and release file lock as the leveldb supports this for Windows, Solaris, and Unix.
func (f *FileLock) Unlock()
Unlock releases a previously acquired lock. We achieve this by closing the previously opened db. FileUnlock can be called multiple times.
Iterator extends actual leveldb iterator
type Iterator struct { iterator.Iterator }
func (itr *Iterator) Key() []byte
Key wraps actual leveldb iterator method
Provider enables to use a single leveldb as multiple logical leveldbs
type Provider struct {
// contains filtered or unexported fields
}
func NewProvider(conf *Conf) *Provider
NewProvider constructs a Provider
func (p *Provider) Close()
Close closes the underlying leveldb
func (p *Provider) GetDBHandle(dbName string) *DBHandle
GetDBHandle returns a handle to a named db
UpdateBatch encloses the details of multiple `updates`
type UpdateBatch struct { KVs map[string][]byte }
func NewUpdateBatch() *UpdateBatch
NewUpdateBatch constructs an instance of a Batch
func (batch *UpdateBatch) Delete(key []byte)
Delete deletes a Key and associated value
func (batch *UpdateBatch) Len() int
Len returns the number of entries in the batch
func (batch *UpdateBatch) Put(key []byte, value []byte)
Put adds a KV