Documentation
¶
Overview ¶
Package store provides a high-level interface for key-value storage operations with advanced features like expiration, deletion scheduling, and unified error handling. It serves as an abstraction layer over the lower-level db.KVDB implementations, adding functionality such as write index management and standardized error reporting.
The package focuses on:
- A unified interface (IStore) for key-value operations across different backends
- Pluggable storage backend architecture through DBFactory pattern
Key Components:
IStore Interface: The core abstraction defining operations for interacting with a key-value store. All implementations share this common interface, allowing applications to switch between different storage backends without code changes. The interface methods return custom Error types that provide detailed information about operation results.
Error System: A structured error reporting mechanism using typed error codes and descriptive messages. This system allows applications to make informed decisions based on specific error conditions rather than generic errors.
DBFactory: A function type that abstracts the creation of underlying db.KVDB instances, providing dependency injection and flexible configuration of storage backends.
Implementations:
The package includes two implementations of the IStore interface: - Local Store (lstore): A simple, non-distributed implementation that directly utilizes a db.KVDB instance. It manages write index progression internally using atomic operations to ensure thread safety. This implementation is suitable for single-node applications where distributed consensus is not required. Available in the "github.com/ValentinKolb/dKV/lib/store/lstore" package. - Distributed Store (dstore): A implementation built on the Dragonboat RAFT consensus library. It distributes storage operations across multiple nodes with strong consistency guarantees. This implementation is appropriate for multi-node deployments requiring fault tolerance and high availability. Available in the "github.com/ValentinKolb/dKV/lib/store/dstore" package.
This interface-driven approach allows applications to:
- Switch between local and distributed storage depending on deployment requirements
- Handle errors in a consistent and type-safe manner across implementations
- Abstract storage implementation details from application logic
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBFactory ¶
DBFactory is a function type that creates a new db used by the store. This is used to abstract the creation of the db from the store implementation.
type Error ¶
Error is a custom error type that wraps a return code (of type RetCode) and an error message.
type IStore ¶
type IStore interface {
// Set inserts or updates a key–value pair.
Set(key string, value []byte) (err error)
// SetE inserts or updates a key–value pair with expiration and or deletion timestamps.
// A zero value for expireIn and deleteIn means no expiration or deletion.
SetE(key string, value []byte, expireIn, deleteIn uint64) (err error)
// SetEIfUnset inserts a key–value pair if the key does not exist.
// If the key already exists, the old value is not updated, no matter the value of expireIn and deleteIn.
// No error is returned if the key already exists.
SetEIfUnset(key string, value []byte, expireIn, deleteIn uint64) (err error)
// Expire expired the value for a key. The key should still be findable with the Has() method.
Expire(key string) (err error)
// Delete deletes a key–value pair. The key should be removed from the store.
Delete(key string) (err error)
// Get return the value for a key. The boolean return value indicates whether a value for the key was found.
Get(key string) (value []byte, loaded bool, err error)
// Has returns whether a key exists in the store. The method should return true even if the value for the key is expired.
Has(key string) (loaded bool, err error)
// GetDBInfo returns metadata about the database underlying the store.
// It is not guaranteed that all fields are filled in or that the information is up-to-date!
GetDBInfo() (info db.DatabaseInfo, err error)
}
IStore is the generic interface for interacting with a key–value store. All write operations return only a *Error (nil on success), while read operations return the requested data along with a *Error (nil on success).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dstore implements a distributed, fault-tolerant key-value store using the Dragonboat RAFT consensus library.
|
Package dstore implements a distributed, fault-tolerant key-value store using the Dragonboat RAFT consensus library. |
|
internal
Package internal provides the communication protocol structures and serialization logic for the dstore package.
|
Package internal provides the communication protocol structures and serialization logic for the dstore package. |
|
Package lstore implements a local, in-memory, single-node key-value store based on the store.IStore interface.
|
Package lstore implements a local, in-memory, single-node key-value store based on the store.IStore interface. |