Documentation ¶
Index ¶
- type ConsistentDB
- func (cdb *ConsistentDB) AllLevelDBNodeByPath() map[string]*leveldb.DB
- func (cdb *ConsistentDB) Back(path string, ro *opt.ReadOptions) (key, value []byte, err error)
- func (cdb *ConsistentDB) Close() error
- func (cdb *ConsistentDB) CompactRange(router string, r util.Range) error
- func (cdb *ConsistentDB) Delete(router string, key []byte, wo *opt.WriteOptions) error
- func (cdb *ConsistentDB) Front(path string, ro *opt.ReadOptions) (key, value []byte, err error)
- func (cdb *ConsistentDB) GetProperty(router string, name string) (value string, err error)
- func (cdb *ConsistentDB) GetSnapshot(router string) (*leveldb.Snapshot, error)
- func (cdb *ConsistentDB) Has(router string, key []byte, ro *opt.ReadOptions) (ret bool, err error)
- func (cdb *ConsistentDB) Init(pathPrefix string, poolSize int, o *opt.Options) (err error)
- func (cdb *ConsistentDB) LevelDB(router string) (path string, db *leveldb.DB)
- func (cdb *ConsistentDB) NewIterator(router string, slice *util.Range, ro *opt.ReadOptions) iterator.Iterator
- func (cdb *ConsistentDB) OpenTransaction(router string) (*leveldb.Transaction, error)
- func (cdb *ConsistentDB) Put(router string, key, value []byte, wo *opt.WriteOptions) error
- func (cdb *ConsistentDB) SetReadOnly(router string) error
- func (cdb *ConsistentDB) SizeOf(router string, ranges []util.Range) (leveldb.Sizes, error)
- func (cdb *ConsistentDB) Stats(router string, s *leveldb.DBStats) error
- func (cdb *ConsistentDB) Subscribe() (<-chan interface{}, context.CancelFunc)
- func (cdb *ConsistentDB) Write(router string, batch *leveldb.Batch, wo *opt.WriteOptions) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsistentDB ¶
type ConsistentDB struct { PathPrefix string PoolSize int // contains filtered or unexported fields }
func NewConsistentDB ¶
func (*ConsistentDB) AllLevelDBNodeByPath ¶
func (cdb *ConsistentDB) AllLevelDBNodeByPath() map[string]*leveldb.DB
func (*ConsistentDB) Back ¶
func (cdb *ConsistentDB) Back(path string, ro *opt.ReadOptions) (key, value []byte, err error)
Back returns the last element of list l or nil if the list is empty.
func (*ConsistentDB) Close ¶
func (cdb *ConsistentDB) Close() error
func (*ConsistentDB) CompactRange ¶
func (cdb *ConsistentDB) CompactRange(router string, r util.Range) error
CompactRange compacts the underlying DB for the given key range. In particular, deleted and overwritten versions are discarded, and the data is rearranged to reduce the cost of operations needed to access the data. This operation should typically only be invoked by users who understand the underlying implementation.
A nil Range.Start is treated as a key before all keys in the DB. And a nil Range.Limit is treated as a key after all keys in the DB. Therefore if both is nil then it will compact entire DB.
func (*ConsistentDB) Delete ¶
func (cdb *ConsistentDB) Delete(router string, key []byte, wo *opt.WriteOptions) error
Delete deletes the value for the given key. Delete will not returns error if key doesn't exist. Write merge also applies for Delete, see Write.
It is safe to modify the contents of the arguments after Delete returns but not before.
func (*ConsistentDB) Front ¶
func (cdb *ConsistentDB) Front(path string, ro *opt.ReadOptions) (key, value []byte, err error)
Front returns the first element of list l or nil if the list is empty.
func (*ConsistentDB) GetProperty ¶
func (cdb *ConsistentDB) GetProperty(router string, name string) (value string, err error)
GetProperty returns value of the given property router.
Property names:
leveldb.num-files-at-level{n} Returns the number of files at level 'n'. leveldb.stats Returns statistics of the underlying DB. leveldb.iostats Returns statistics of effective disk read and write. leveldb.writedelay Returns cumulative write delay caused by compaction. leveldb.sstables Returns sstables list for each level. leveldb.blockpool Returns block pool stats. leveldb.cachedblock Returns size of cached block. leveldb.openedtables Returns number of opened tables. leveldb.alivesnaps Returns number of alive snapshots. leveldb.aliveiters Returns number of alive iterators.
func (*ConsistentDB) GetSnapshot ¶
func (cdb *ConsistentDB) GetSnapshot(router string) (*leveldb.Snapshot, error)
GetSnapshot returns a latest snapshot of the underlying DB. A snapshot is a frozen snapshot of a DB state at a particular point in time. The content of snapshot are guaranteed to be consistent.
The snapshot must be released after use, by calling Release method.
func (*ConsistentDB) Has ¶
func (cdb *ConsistentDB) Has(router string, key []byte, ro *opt.ReadOptions) (ret bool, err error)
Has returns true if the DB does contains the given key.
It is safe to modify the contents of the argument after Has returns.
func (*ConsistentDB) LevelDB ¶
func (cdb *ConsistentDB) LevelDB(router string) (path string, db *leveldb.DB)
func (*ConsistentDB) NewIterator ¶
func (cdb *ConsistentDB) NewIterator(router string, slice *util.Range, ro *opt.ReadOptions) iterator.Iterator
NewIterator returns an iterator for the latest snapshot of the underlying DB. The returned iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine. It is also safe to use an iterator concurrently with modifying its underlying DB. The resultant key/value pairs are guaranteed to be consistent.
Slice allows slicing the iterator to only contains keys in the given range. A nil Range.Start is treated as a key before all keys in the DB. And a nil Range.Limit is treated as a key after all keys in the DB.
WARNING: Any slice returned by iterator (e.g. slice returned by calling Iterator.Key() or Iterator.Key() methods), its content should not be modified unless noted otherwise.
The iterator must be released after use, by calling Release method.
Also read Iterator documentation of the leveldb/iterator package.
func (*ConsistentDB) OpenTransaction ¶
func (cdb *ConsistentDB) OpenTransaction(router string) (*leveldb.Transaction, error)
OpenTransaction opens an atomic DB transaction. Only one transaction can be opened at a time. Subsequent call to Write and OpenTransaction will be blocked until in-flight transaction is committed or discarded. The returned transaction handle is safe for concurrent use.
Transaction is expensive and can overwhelm compaction, especially if transaction size is small. Use with caution.
The transaction must be closed once done, either by committing or discarding the transaction. Closing the DB will discard open transaction.
func (*ConsistentDB) Put ¶
func (cdb *ConsistentDB) Put(router string, key, value []byte, wo *opt.WriteOptions) error
Put sets the value for the given key. It overwrites any previous value for that key; a DB is not a multi-map. Write merge also applies for Put, see Write.
It is safe to modify the contents of the arguments after Put returns but not before.
func (*ConsistentDB) SetReadOnly ¶
func (cdb *ConsistentDB) SetReadOnly(router string) error
SetReadOnly makes DB read-only. It will stay read-only until reopened.
func (*ConsistentDB) SizeOf ¶
SizeOf calculates approximate sizes of the given key ranges. The length of the returned sizes are equal with the length of the given ranges. The returned sizes measure storage space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size. The results may not include the sizes of recently written data.
func (*ConsistentDB) Stats ¶
func (cdb *ConsistentDB) Stats(router string, s *leveldb.DBStats) error
Stats populates s with database statistics.
func (*ConsistentDB) Subscribe ¶
func (cdb *ConsistentDB) Subscribe() (<-chan interface{}, context.CancelFunc)
Subscribe returns a channel that's closed when awoken by PublishSignal or PublishBroadcast in convenience function below.
func (*ConsistentDB) Write ¶
func (cdb *ConsistentDB) Write(router string, batch *leveldb.Batch, wo *opt.WriteOptions) error
Write apply the given batch to the DB. The batch records will be applied sequentially. Write might be used concurrently, when used concurrently and batch is small enough, write will try to merge the batches. Set NoWriteMerge option to true to disable write merge.
It is safe to modify the contents of the arguments after Write returns but not before. Write will not modify content of the batch.