Documentation ¶
Index ¶
- Constants
- Variables
- func Copy(source KVStore, target KVStore) error
- func CopyBatched(source KVStore, target KVStore, batchSize ...int) error
- type BatchCollector
- type BatchWriteObject
- type BatchedMutations
- type BatchedWriter
- type IterDirection
- type IteratorKeyConsumerFunc
- type IteratorKeyValueConsumerFunc
- type KVStore
- type Key
- type KeyPrefix
- type Option
- type Options
- type Realm
- type Sequence
- type StoreHealthTracker
- func (s *StoreHealthTracker) CheckCorrectStoreVersion() (bool, error)
- func (s *StoreHealthTracker) Close() error
- func (s *StoreHealthTracker) Flush() error
- func (s *StoreHealthTracker) IsCorrupted() (bool, error)
- func (s *StoreHealthTracker) IsTainted() (bool, error)
- func (s *StoreHealthTracker) MarkCorrupted() error
- func (s *StoreHealthTracker) MarkHealthy() error
- func (s *StoreHealthTracker) MarkTainted() error
- func (s *StoreHealthTracker) StoreVersion() (byte, error)
- func (s *StoreHealthTracker) UpdateStoreVersion() (bool, error)
- type StoreVersionUpdateFunc
- type TypedStore
- func (t *TypedStore[K, V, KPtr, VPtr]) Delete(key K) (err error)
- func (t *TypedStore[K, V, KPtr, VPtr]) Get(key K) (value V, err error)
- func (t *TypedStore[K, V, KPtr, VPtr]) Iterate(prefix KeyPrefix, callback func(key K, value V) (advance bool), ...) (err error)
- func (t *TypedStore[K, V, KPtr, VPtr]) Set(key K, value V) (err error)
- type Value
Constants ¶
const ( // StoreVersionNone is used to load an existing store without a version check (e.g. in the tools). StoreVersionNone byte = 0 )
Variables ¶
var ( ErrStoreVersionCheckNotSupported = errors.New("store version check not supported") ErrStoreVersionUpdateFuncNotGiven = errors.New("store version update function not given") )
var ( // ErrKeyNotFound is returned when an op. doesn't find the given key. ErrKeyNotFound = errors.New("key not found") // ErrStoreClosed is returned when an op accesses the kvstore but it was already closed. ErrStoreClosed = errors.New("trying to access closed kvstore") EmptyPrefix = KeyPrefix{} )
Functions ¶
Types ¶
type BatchCollector ¶
type BatchCollector struct {
// contains filtered or unexported fields
}
BatchCollector is used to collect objects that should be written.
func (*BatchCollector) Add ¶
func (br *BatchCollector) Add(objectToPersist BatchWriteObject) (batchSizeReached bool)
Add adds an object to the batch. It returns true in case the batch size is reached.
func (*BatchCollector) Commit ¶
func (br *BatchCollector) Commit() error
Commit applies the collected mutations.
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, opts ...Option) *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) Flush ¶
func (bw *BatchedWriter) Flush()
Flush sends a signal to flush all the queued elements.
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 IterDirection ¶
type IterDirection byte
IterDirection specifies the direction for iterations.
const ( IterDirectionForward IterDirection = iota IterDirectionBackward )
func GetIterDirection ¶
func GetIterDirection(iterDirection ...IterDirection) IterDirection
GetIterDirection returns the direction to use for an iteration. If no direction is given, it defaults to IterDirectionForward.
type IteratorKeyConsumerFunc ¶
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 ¶
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 { // WithRealm is a factory method for using the same underlying storage with a different realm. WithRealm(realm Realm) (KVStore, error) // WithExtendedRealm is a factory method for using the same underlying storage with an realm appended to existing one. WithExtendedRealm(realm Realm) (KVStore, error) // Realm returns the configured realm. Realm() Realm // Iterate iterates over all keys and values with the provided prefix. You can pass kvstore.EmptyPrefix to iterate over all keys and values. // Optionally the direction for the iteration can be passed (default: IterDirectionForward). Iterate(prefix KeyPrefix, kvConsumerFunc IteratorKeyValueConsumerFunc, direction ...IterDirection) error // IterateKeys iterates over all keys with the provided prefix. You can pass kvstore.EmptyPrefix to iterate over all keys. // Optionally the direction for the iteration can be passed (default: IterDirectionForward). IterateKeys(prefix KeyPrefix, consumerFunc IteratorKeyConsumerFunc, direction ...IterDirection) 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 // Flush persists all outstanding write operations to disc. Flush() error // Close closes the database file handles. Close() error // Batched returns a BatchedMutations interface to execute batched mutations. Batched() (BatchedMutations, error) }
KVStore persists, deletes and retrieves data.
type Option ¶
type Option func(opts *Options)
Option is a function setting a BatchedWriter option.
func WithBatchSize ¶
WithBatchSize defines the maximum amount of elements in the batch.
func WithBatchTimeout ¶
WithBatchTimeout defines the timeout for collecting elements for the batch.
func WithQueueSize ¶
WithQueueSize defines the size of the batch queue.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options define options for the BatchedWriter.
type Sequence ¶
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 ¶
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.
type StoreHealthTracker ¶
type StoreHealthTracker struct {
// contains filtered or unexported fields
}
func NewStoreHealthTracker ¶
func NewStoreHealthTracker(store KVStore, storePrefixHealth []byte, storeVersion byte, storeVersionUpdateFunc StoreVersionUpdateFunc) (*StoreHealthTracker, error)
func (*StoreHealthTracker) CheckCorrectStoreVersion ¶
func (s *StoreHealthTracker) CheckCorrectStoreVersion() (bool, error)
func (*StoreHealthTracker) Close ¶
func (s *StoreHealthTracker) Close() error
func (*StoreHealthTracker) Flush ¶
func (s *StoreHealthTracker) Flush() error
func (*StoreHealthTracker) IsCorrupted ¶
func (s *StoreHealthTracker) IsCorrupted() (bool, error)
func (*StoreHealthTracker) IsTainted ¶
func (s *StoreHealthTracker) IsTainted() (bool, error)
func (*StoreHealthTracker) MarkCorrupted ¶
func (s *StoreHealthTracker) MarkCorrupted() error
func (*StoreHealthTracker) MarkHealthy ¶
func (s *StoreHealthTracker) MarkHealthy() error
func (*StoreHealthTracker) MarkTainted ¶
func (s *StoreHealthTracker) MarkTainted() error
func (*StoreHealthTracker) StoreVersion ¶
func (s *StoreHealthTracker) StoreVersion() (byte, error)
StoreVersion returns the store version.
func (*StoreHealthTracker) UpdateStoreVersion ¶
func (s *StoreHealthTracker) UpdateStoreVersion() (bool, error)
UpdateStoreVersion tries to migrate the existing data to the new store version. Returns true if the store needs to be updated / was updated.
type StoreVersionUpdateFunc ¶
type TypedStore ¶
type TypedStore[K, V any, KPtr serializer.MarshalablePtr[K], VPtr serializer.MarshalablePtr[V]] struct { // contains filtered or unexported fields }
TypedStore is a generically typed wrapper around a KVStore that abstracts serialization away.
func NewTypedStore ¶
func NewTypedStore[K, V any, KPtr serializer.MarshalablePtr[K], VPtr serializer.MarshalablePtr[V]](kv KVStore) *TypedStore[K, V, KPtr, VPtr]
NewTypedStore is the constructor for TypedStore.
func (*TypedStore[K, V, KPtr, VPtr]) Delete ¶
func (t *TypedStore[K, V, KPtr, VPtr]) Delete(key K) (err error)
Delete deletes the given key from the store.
func (*TypedStore[K, V, KPtr, VPtr]) Get ¶
func (t *TypedStore[K, V, KPtr, VPtr]) Get(key K) (value V, err error)
Get gets the given key or an error if an error occurred.
func (*TypedStore[K, V, KPtr, VPtr]) Iterate ¶
func (t *TypedStore[K, V, KPtr, VPtr]) Iterate(prefix KeyPrefix, callback func(key K, value V) (advance bool), direction ...IterDirection) (err error)
func (*TypedStore[K, V, KPtr, VPtr]) Set ¶
func (t *TypedStore[K, V, KPtr, VPtr]) Set(key K, value V) (err error)
Set sets the given key and value.