kvstore

package
Version: v0.0.0-...-1974178 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BatchWriterQueueSize    = BatchWriterBatchSize
	BatchWriterBatchSize    = 10000
	BatchWriterBatchTimeout = 500 * time.Millisecond
)

Variables

View Source
var (
	// ErrKeyNotFound is returned when an op. doesn't find the given key.
	ErrKeyNotFound = errors.New("key not found")

	EmptyPrefix = KeyPrefix{}
)
View Source
var CommandNames = map[Command]string{
	ShutdownCommand:     "Shutdown",
	IterateCommand:      "Iterate",
	IterateKeysCommand:  "IterateKeys",
	ClearCommand:        "Clear",
	GetCommand:          "Get",
	SetCommand:          "Set",
	HasCommand:          "Has",
	DeleteCommand:       "Delete",
	DeletePrefixCommand: "DeletePrefix",
}

CommandNames contains a map from the command to its human readable name.

Functions

This section is empty.

Types

type AccessCallback

type AccessCallback func(command Command, parameters ...[]byte)

AccessCallback is the type of the callback function that can be used to hook the access to the callback.

type BatchWriteObject

type BatchWriteObject interface {
	// BatchWrite mashalls the object and adds it to the BatchedMutations.
	BatchWrite(batchedMuts BatchedMutations)
	// BatchWriteDone is called after the object was persisted.
	BatchWriteDone()
	// BatchWriteScheduled returns true if the object is already scheduled for a BatchWrite operation.
	BatchWriteScheduled() bool
	// ResetBatchWriteScheduled resets the flag that the object is scheduled for a BatchWrite operation.
	ResetBatchWriteScheduled()
}

BatchWriteObject is an object that can be persisted to the KVStore in batches using the BatchedWriter.

type BatchedMutations

type BatchedMutations interface {

	// Set sets the given key and value.
	Set(key Key, value Value) error

	// Delete deletes the entry for the given key.
	Delete(key Key) error

	// Cancel cancels the batched mutations.
	Cancel()

	// Commit commits/flushes the mutations.
	Commit() error
}

BatchedMutations represents batched mutations to the storage.

type BatchedWriter

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

BatchedWriter persists BatchWriteObjects in batches to a KVStore.

func NewBatchedWriter

func NewBatchedWriter(store KVStore) *BatchedWriter

NewBatchedWriter creates a new BatchedWriter instance.

func (*BatchedWriter) Enqueue

func (bw *BatchedWriter) Enqueue(object BatchWriteObject)

Enqueue adds a BatchWriteObject to the write queue. It also starts the batch writer if not done yet.

func (*BatchedWriter) KVStore

func (bw *BatchedWriter) KVStore() KVStore

KVStore returns the underlying KVStore.

func (*BatchedWriter) StopBatchWriter

func (bw *BatchedWriter) StopBatchWriter()

StopBatchWriter stops the batch writer and waits until all enqueued objects are written.

type Command

type Command = bitmask.BitMask

Command is a type that represents a specific method in the KVStore.

const (
	// IterateCommand represents a call to the Iterate method of the store.
	IterateCommand Command = 1 << iota

	// IterateKeysCommand represents a call to the IterateKeys method of the store.
	IterateKeysCommand

	// ClearCommand represents a call to the Clear method of the store.
	ClearCommand

	// GetCommand represents a call to the Get method of the store.
	GetCommand

	// SetCommand represents a call to the Set method of the store.
	SetCommand

	// HasCommand represents a call to the Has method of the store.
	HasCommand

	// DeleteCommand represents a call to the Delete method of the store.
	DeleteCommand

	// DeletePrefixCommand represents a call to the DeletePrefix method of the store.
	DeletePrefixCommand

	// AllCommands represents the collection of all commands.
	AllCommands = IterateCommand | IterateKeysCommand | ClearCommand | GetCommand | SetCommand | HasCommand | DeleteCommand | DeletePrefixCommand

	// ShutdownCommand represents a call to the Shutdown method of the store.
	ShutdownCommand Command = 0
)

type IteratorKeyConsumerFunc

type IteratorKeyConsumerFunc func(key Key) bool

IteratorKeyConsumerFunc is a consumer function for an iterating function which iterates only over keys. They key must not be prefixed with the realm. Returning false from this function indicates to abort the iteration.

type IteratorKeyValueConsumerFunc

type IteratorKeyValueConsumerFunc func(key Key, value Value) bool

IteratorKeyValueConsumerFunc is a consumer function for an iterating function which iterates over keys and values. They key must not be prefixed with the realm. Returning false from this function indicates to abort the iteration.

type KVStore

type KVStore interface {
	// AccessCallback configures the store to pass all requests to the KVStore to the given callback.
	// This can for example be used for debugging and to examine what the KVStore is doing.
	AccessCallback(callback AccessCallback, commandsFilter ...Command)

	// WithRealm is a factory method for using the same underlying storage with a different realm.
	WithRealm(realm Realm) KVStore

	// Realm returns the configured realm.
	Realm() Realm

	// Shutdown marks the store as shutdown.
	Shutdown()

	// Iterate iterates over all keys and values with the provided prefix. You can pass kvstore.EmptyPrefix to iterate over all keys and values.
	Iterate(prefix KeyPrefix, kvConsumerFunc IteratorKeyValueConsumerFunc) error

	// IterateKeys iterates over all keys with the provided prefix. You can pass kvstore.EmptyPrefix to iterate over all keys.
	IterateKeys(prefix KeyPrefix, consumerFunc IteratorKeyConsumerFunc) error

	// Clear clears the realm.
	Clear() error

	// Get gets the given key or nil if it doesn't exist or an error if an error occurred.
	Get(key Key) (value Value, err error)

	// Set sets the given key and value.
	Set(key Key, value Value) error

	// Has checks whether the given key exists.
	Has(key Key) (bool, error)

	// Delete deletes the entry for the given key.
	Delete(key Key) error

	// DeletePrefix deletes all the entries matching the given key prefix.
	DeletePrefix(prefix KeyPrefix) error

	// Batched returns a BatchedMutations interface to execute batched mutations.
	Batched() BatchedMutations

	// Flush persists all outstanding write operations to disc.
	Flush() error

	// Close closes the database file handles.
	Close() error
}

KVStore persists, deletes and retrieves data.

type Key

type Key = []byte

type KeyPrefix

type KeyPrefix = []byte

type Realm

type Realm = []byte

type Sequence

type Sequence struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Sequence represents a simple integer sequence backed by a KVStore. A Sequence can be used to get a list of monotonically increasing integers.

func NewSequence

func NewSequence(store KVStore, key []byte, interval uint64) (*Sequence, error)

NewSequence initiates a new sequence object backed by the provided store. The interval value defines how many Next() requests can be served from memory without an access to the store. Multiple sequences can be created by providing different keys.

func (*Sequence) Next

func (seq *Sequence) Next() (uint64, error)

Next returns the next integer in the sequence.

func (*Sequence) Release

func (seq *Sequence) Release() error

Release the leased sequence to avoid wasted integers.

type Value

type Value = []byte

Directories

Path Synopsis
Package mapdb provides a map implementation of a key value store.
Package mapdb provides a map implementation of a key value store.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL