Documentation ¶
Index ¶
- Constants
- Variables
- func GetFuncIter(iter iterator.Iterator, listOrder ListOrder) func() bool
- func GetIterByID(db *LDBDatabase, prefix []byte, idxPrefix []byte, startID *types.PttID, ...) (iterator.Iterator, error)
- func IndexGetKey(theBytes []byte) ([]byte, error)
- func IndexGetKeys(theBytes []byte) ([][]byte, error)
- type Batch
- type DBable
- type Database
- type Deleter
- type Getter
- type Index
- type IndexWithStatus
- type KeyVal
- type LDBBatch
- func (b LDBBatch) DB() *LDBDatabase
- func (b LDBBatch) DBDelete(key []byte) error
- func (b LDBBatch) DBGet(key []byte) ([]byte, error)
- func (b LDBBatch) Delete(key []byte) error
- func (b *LDBBatch) DeleteAll(idxKey []byte) error
- func (b *LDBBatch) DeleteAllKeys(keys [][]byte) error
- func (b *LDBBatch) ForcePutAll(idxKey []byte, idx *Index, kvs []*KeyVal) ([][]byte, error)
- func (b *LDBBatch) GetBy2ndIdxKey(idxKey []byte) ([]byte, error)
- func (b *LDBBatch) GetByIdxKey(idxKey []byte, idx int) ([]byte, error)
- func (b *LDBBatch) GetKeyBy2ndIdxKey(idxKey []byte) ([]byte, error)
- func (b *LDBBatch) GetKeyByIdxKey(idxKey []byte, idx int) ([]byte, error)
- func (b LDBBatch) Put(key, value []byte) error
- func (b LDBBatch) Reset()
- func (b *LDBBatch) TryPutAll(idxKey []byte, idx *Index, kvs []*KeyVal, isDeleteOrig bool, isGetOrig bool) ([]*KeyVal, error)
- func (b LDBBatch) ValueSize() int
- func (b LDBBatch) Write() error
- 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) Name() string
- func (db *LDBDatabase) NewBatch() Batch
- func (db *LDBDatabase) NewIterator(listOrder ListOrder) iterator.Iterator
- func (db *LDBDatabase) NewIteratorWithPrefix(start []byte, prefix []byte, listOrder ListOrder) (iterator.Iterator, error)
- func (db *LDBDatabase) NewIteratorWithRange(r *util.Range, listOrder ListOrder) iterator.Iterator
- func (db *LDBDatabase) Path() string
- func (db *LDBDatabase) Pop(key []byte) ([]byte, error)
- func (db *LDBDatabase) Put(key []byte, value []byte) error
- func (db *LDBDatabase) RUnlockMap(key []byte) error
- func (db *LDBDatabase) TryLockMap(key []byte) error
- func (db *LDBDatabase) TryPut(key []byte, value []byte, updateTS types.Timestamp) ([]byte, error)
- func (db *LDBDatabase) TryRLockMap(key []byte) error
- func (db *LDBDatabase) UnlockMap(key []byte) error
- type ListOrder
- 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 Putter
Constants ¶
const ( // Code using batches should try to add this much data to the batch. // The value was determined empirically. IdealBatchSize = 100 * 1024 InfiniteQuota = 0 SizeDBKeyPrefix = 5 OffsetDBKeyPrefixPostfix = 3 )
const (
OpenFileLimit = 64
)
Variables ¶
var ( ErrInvalidPrefix = errors.New("invalid prefix") ErrInvalidDBable = errors.New("invalid dbable (no UT)") ErrInvalidUpdateTS = errors.New("invalid UT") ErrInvalidLock = errors.New("invalid db lock") ErrBusy = errors.New("db busy") ErrInvalidKeys = errors.New("invalid db keys") ErrInvalidIndex = errors.New("invalid db index") )
var (
ValueTrue = []byte{1}
)
Functions ¶
func GetIterByID ¶
func IndexGetKey ¶
func IndexGetKeys ¶
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 Index ¶
Index stores the information of index for ts-based records.
The 0th key is the key for the record.
The other keys are the secondary index-keys
type IndexWithStatus ¶
type IndexWithStatus struct { Keys [][]byte `json:"K"` UpdateTS types.Timestamp `json:"UT"` Status types.Status `json:"S"` }
func (*IndexWithStatus) Marshal ¶
func (i *IndexWithStatus) Marshal() ([]byte, error)
func (*IndexWithStatus) Unmarshal ¶
func (i *IndexWithStatus) Unmarshal(data []byte) error
type LDBBatch ¶
type LDBBatch struct {
// contains filtered or unexported fields
}
func NewLDBBatch ¶
func NewLDBBatch(db *LDBDatabase) (*LDBBatch, error)
func (LDBBatch) DB ¶
func (b LDBBatch) DB() *LDBDatabase
func (*LDBBatch) DeleteAll ¶
DeleteAll deletes all the records, including value and 2nd-indexing of the idxKey.
func (*LDBBatch) DeleteAllKeys ¶
func (*LDBBatch) ForcePutAll ¶
ForcePutAll tries to put all the key-vals with comparing the updateTS of the 1st item.
This is used when the real content is stored in ts-based key, but we want to refer the content directly from id-key.
This assumes 1-record per id-key. The original data will be deleted if id-key already exists.
idxKey, idx, and kvs intends to implement 2nd-indexing in leveldb.
Given the id-key and the data with updateTS, idxKey is the id-key, key is the key-with-updateTS, value is the corresponding data. Besides, we also have the 2nd-idx-keys to index by the 2nd-idx-keys. The value of the 2nd-idx-keys are key.
idx includes the key (in the 0th of idx.Keys) and 2nd-idx-keys kvs are the corresponding key-vals based on the order of idx.
func (*LDBBatch) GetBy2ndIdxKey ¶
GetBy2ndIdxKey gets the value based on the 2nd-idx-key.
func (*LDBBatch) GetByIdxKey ¶
GetByIdxKey gets the value (idx as 0) or the value of the corresponding 2nd-idx-key (should be the key).
func (*LDBBatch) GetKeyBy2ndIdxKey ¶
GetKeyBy2ndIdxKey gets the key based on the 2nd-idx-key.
func (*LDBBatch) GetKeyByIdxKey ¶
GetKeyByIdxKey gets the key (idx as 0) or the corresponding 2nd-idx-key.
func (*LDBBatch) TryPutAll ¶
func (b *LDBBatch) TryPutAll(idxKey []byte, idx *Index, kvs []*KeyVal, isDeleteOrig bool, isGetOrig bool) ([]*KeyVal, error)
TryPutAll tries to put all the key-vals with comparing the updateTS of the 1st item.
This is used when the real content is stored in ts-based key, but we want to refer the content directly from id-key.
This assumes 1-record per id-key. The old data will be deleted if id-key already exists.
idxKey, idx, and kvs intends to implement 2nd-indexing in leveldb.
Given the id-key and the data with updateTS, idxKey is the id-key, key is the key-with-updateTS, value is the corresponding data. Besides, we also have the 2nd-idx-keys to index by the 2nd-idx-keys. The value of the 2nd-idx-keys are key.
idx includes the key (in the 0th of idx.Keys) and 2nd-idx-keys kvs are the corresponding key-vals based on the order of idx.
type LDBDatabase ¶
type LDBDatabase struct {
// contains filtered or unexported fields
}
func NewLDBDatabase ¶
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) Name ¶
func (db *LDBDatabase) Name() string
func (*LDBDatabase) NewBatch ¶
func (db *LDBDatabase) NewBatch() Batch
func (*LDBDatabase) NewIterator ¶
func (db *LDBDatabase) NewIterator(listOrder ListOrder) iterator.Iterator
func (*LDBDatabase) NewIteratorWithPrefix ¶
func (db *LDBDatabase) NewIteratorWithPrefix(start []byte, prefix []byte, listOrder ListOrder) (iterator.Iterator, error)
NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.
func (*LDBDatabase) NewIteratorWithRange ¶
func (*LDBDatabase) Path ¶
func (db *LDBDatabase) Path() string
Path returns the path to the database directory.
func (*LDBDatabase) Put ¶
func (db *LDBDatabase) Put(key []byte, value []byte) error
Put puts the given key / value to the queue
func (*LDBDatabase) RUnlockMap ¶
func (db *LDBDatabase) RUnlockMap(key []byte) error
func (*LDBDatabase) TryLockMap ¶
func (db *LDBDatabase) TryLockMap(key []byte) error
func (*LDBDatabase) TryPut ¶
TryPut tries to put the key/val based on the updateTS of val.
Value is the jsonified bytes. the obj of the bytes needs to include UpdateTS.
func (*LDBDatabase) TryRLockMap ¶
func (db *LDBDatabase) TryRLockMap(key []byte) error
func (*LDBDatabase) UnlockMap ¶
func (db *LDBDatabase) UnlockMap(key []byte) error
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 NewMemDatabaseWithCap ¶
func NewMemDatabaseWithCap(size int) *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