Documentation ¶
Overview ¶
Package kvstore implements a GC friendly in-memory storage engine by using built-in maps and byte slices. It also supports compaction.
Index ¶
- func DefaultConfig() *storage.Config
- type Entry
- func (e *Entry) Decode(buf []byte)
- func (e *Entry) Encode() []byte
- func (e *Entry) Key() string
- func (e *Entry) SetKey(key string)
- func (e *Entry) SetTTL(ttl int64)
- func (e *Entry) SetTimestamp(timestamp int64)
- func (e *Entry) SetValue(value []byte)
- func (e *Entry) TTL() int64
- func (e *Entry) Timestamp() int64
- func (e *Entry) Value() []byte
- type KVStore
- func (kv *KVStore) Check(hkey uint64) bool
- func (kv *KVStore) Close() error
- func (kv *KVStore) Compaction() (bool, error)
- func (kv *KVStore) Delete(hkey uint64) error
- func (kv *KVStore) Destroy() error
- func (kv *KVStore) Export() ([]byte, error)
- func (kv *KVStore) Fork(c *storage.Config) (storage.Engine, error)
- func (kv *KVStore) Get(hkey uint64) (storage.Entry, error)
- func (kv *KVStore) GetKey(hkey uint64) (string, error)
- func (kv *KVStore) GetRaw(hkey uint64) ([]byte, error)
- func (kv *KVStore) GetTTL(hkey uint64) (int64, error)
- func (kv *KVStore) Import(data []byte) (storage.Engine, error)
- func (kv *KVStore) Name() string
- func (kv *KVStore) NewEntry() storage.Entry
- func (kv *KVStore) Put(hkey uint64, value storage.Entry) error
- func (kv *KVStore) PutRaw(hkey uint64, value []byte) error
- func (kv *KVStore) Range(f func(hkey uint64, entry storage.Entry) bool)
- func (kv *KVStore) RegexMatchOnKeys(expr string, f func(hkey uint64, entry storage.Entry) bool) error
- func (kv *KVStore) SetConfig(c *storage.Config)
- func (kv *KVStore) SetLogger(l *log.Logger)
- func (kv *KVStore) Start() error
- func (kv *KVStore) Stats() storage.Stats
- func (kv *KVStore) UpdateTTL(hkey uint64, data storage.Entry) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfig ¶
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry represents a value with its metadata.
func (*Entry) SetTimestamp ¶
type KVStore ¶
type KVStore struct {
// contains filtered or unexported fields
}
KVStore implements a new off-heap data store which uses built-in map to keep metadata and mmap syscall for allocating memory to store values. The allocated memory is not a subject of Golang's GC.
func (*KVStore) Compaction ¶
func (*KVStore) Delete ¶
Delete deletes the value for the given key. Delete will not returns error if key doesn't exist.
func (*KVStore) Export ¶
Export serializes underlying data structes into a byte slice. It may return ErrFragmented if the tables are fragmented. If you get this error, you should try to call Export again some time later.
func (*KVStore) Get ¶
Get gets the value for the given key. It returns storage.ErrKeyNotFound if the DB does not contains the key. The returned Entry is its own copy, it is safe to modify the contents of the returned slice.
func (*KVStore) GetKey ¶
GetKey gets the key for the given hkey. It returns storage.ErrKeyNotFound if the DB does not contains the key.
func (*KVStore) GetRaw ¶
GetRaw extracts encoded value for the given hkey. This is useful for merging tables.
func (*KVStore) GetTTL ¶
GetTTL gets the timeout for the given key. It returns storage.ErrKeyNotFound if the DB does not contains the key.
func (*KVStore) Import ¶
Import gets the serialized data by Export and creates a new storage instance.
func (*KVStore) Put ¶
Put sets the value for the given key. It overwrites any previous value for that key
func (*KVStore) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration. Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
func (*KVStore) RegexMatchOnKeys ¶
func (kv *KVStore) RegexMatchOnKeys(expr string, f func(hkey uint64, entry storage.Entry) bool) error
RegexMatchOnKeys calls a regular expression on keys and provides an iterator.