kvstore

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *storage.Config

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry represents a value with its metadata.

func NewEntry

func NewEntry() *Entry

func (*Entry) Decode

func (e *Entry) Decode(buf []byte)

func (*Entry) Encode

func (e *Entry) Encode() []byte

func (*Entry) Key

func (e *Entry) Key() string

func (*Entry) SetKey

func (e *Entry) SetKey(key string)

func (*Entry) SetTTL

func (e *Entry) SetTTL(ttl int64)

func (*Entry) SetTimestamp

func (e *Entry) SetTimestamp(timestamp int64)

func (*Entry) SetValue

func (e *Entry) SetValue(value []byte)

func (*Entry) TTL

func (e *Entry) TTL() int64

func (*Entry) Timestamp

func (e *Entry) Timestamp() int64

func (*Entry) Value

func (e *Entry) Value() []byte

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) Check

func (kv *KVStore) Check(hkey uint64) bool

Check checks the key existence.

func (*KVStore) Close

func (kv *KVStore) Close() error

func (*KVStore) Compaction

func (kv *KVStore) Compaction() (bool, error)

func (*KVStore) Delete

func (kv *KVStore) Delete(hkey uint64) error

Delete deletes the value for the given key. Delete will not returns error if key doesn't exist.

func (*KVStore) Destroy

func (kv *KVStore) Destroy() error

func (*KVStore) Export

func (kv *KVStore) Export() ([]byte, error)

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) Fork

func (kv *KVStore) Fork(c *storage.Config) (storage.Engine, error)

Fork creates a new KVStore instance.

func (*KVStore) Get

func (kv *KVStore) Get(hkey uint64) (storage.Entry, error)

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

func (kv *KVStore) GetKey(hkey uint64) (string, error)

GetKey gets the key for the given hkey. It returns storage.ErrKeyNotFound if the DB does not contains the key.

func (*KVStore) GetRaw

func (kv *KVStore) GetRaw(hkey uint64) ([]byte, error)

GetRaw extracts encoded value for the given hkey. This is useful for merging tables.

func (*KVStore) GetTTL

func (kv *KVStore) GetTTL(hkey uint64) (int64, error)

GetTTL gets the timeout for the given key. It returns storage.ErrKeyNotFound if the DB does not contains the key.

func (*KVStore) Import

func (kv *KVStore) Import(data []byte) (storage.Engine, error)

Import gets the serialized data by Export and creates a new storage instance.

func (*KVStore) Name

func (kv *KVStore) Name() string

func (*KVStore) NewEntry

func (kv *KVStore) NewEntry() storage.Entry

func (*KVStore) Put

func (kv *KVStore) Put(hkey uint64, value storage.Entry) error

Put sets the value for the given key. It overwrites any previous value for that key

func (*KVStore) PutRaw

func (kv *KVStore) PutRaw(hkey uint64, value []byte) error

PutRaw sets the raw value for the given key.

func (*KVStore) Range

func (kv *KVStore) Range(f func(hkey uint64, entry storage.Entry) bool)

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.

func (*KVStore) SetConfig

func (kv *KVStore) SetConfig(c *storage.Config)

func (*KVStore) SetLogger

func (kv *KVStore) SetLogger(l *log.Logger)

func (*KVStore) Start

func (kv *KVStore) Start() error

func (*KVStore) Stats

func (kv *KVStore) Stats() storage.Stats

Stats is a function which provides memory allocation and garbage ratio of a storage instance.

func (*KVStore) UpdateTTL

func (kv *KVStore) UpdateTTL(hkey uint64, data storage.Entry) error

UpdateTTL updates the expiry for the given key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL