Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractListUserKey(key []byte) []byte
- func IsListItemKey(key []byte) bool
- func IsListMetaKey(key []byte) bool
- func ListItemKey(userKey []byte, seq int64) []byte
- func ListMetaKey(userKey []byte) []byte
- func MarshalListMeta(meta ListMeta) ([]byte, error)
- type HybridClock
- type KVPair
- type KVPairMutation
- type ListMeta
- type MVCCStore
- type MVCCStoreOption
- type OpType
- type PebbleStoreOption
- type VersionedValue
Constants ¶
const ( ListMetaPrefix = "!lst|meta|" ListItemPrefix = "!lst|itm|" )
Variables ¶
var ErrExpired = errors.New("expired")
var ErrInvalidChecksum = errors.New("invalid checksum")
var ErrKeyNotFound = errors.New("not found")
var ErrNotSupported = errors.New("not supported")
var ErrUnknownOp = errors.New("unknown op")
var ErrWriteConflict = errors.New("write conflict")
var Tombstone = []byte{0x00}
Functions ¶
func ExtractListUserKey ¶
ExtractListUserKey returns the logical user key from a list meta or item key. If the key is not a list key, it returns nil.
func IsListItemKey ¶
func IsListMetaKey ¶
IsListMetaKey Exported helpers for other packages (e.g., Redis adapter).
func ListItemKey ¶
ListItemKey builds the item key for a user key and sequence number.
func ListMetaKey ¶
ListMetaKey builds the metadata key for a user key.
func MarshalListMeta ¶
MarshalListMeta encodes ListMeta into a fixed 24-byte binary format.
Types ¶
type HybridClock ¶
type HybridClock interface {
Now() uint64
}
HybridClock provides monotonically increasing timestamps (HLC).
type KVPairMutation ¶
type KVPairMutation struct {
Op OpType
Key []byte
Value []byte
// ExpireAt is an HLC timestamp; 0 means no TTL.
ExpireAt uint64
}
KVPairMutation is a small helper struct for MVCC mutation application.
type ListMeta ¶
func UnmarshalListMeta ¶
UnmarshalListMeta decodes ListMeta from the fixed 24-byte binary format.
type MVCCStore ¶
type MVCCStore interface {
// GetAt returns the newest version whose commit timestamp is <= ts.
GetAt(ctx context.Context, key []byte, ts uint64) ([]byte, error)
// ExistsAt reports whether a visible, non-tombstone version exists at ts.
ExistsAt(ctx context.Context, key []byte, ts uint64) (bool, error)
// ScanAt returns versions visible at the given timestamp.
ScanAt(ctx context.Context, start []byte, end []byte, limit int, ts uint64) ([]*KVPair, error)
// PutAt commits a value at the provided commit timestamp and optional expireAt.
PutAt(ctx context.Context, key []byte, value []byte, commitTS uint64, expireAt uint64) error
// DeleteAt commits a tombstone at the provided commit timestamp.
DeleteAt(ctx context.Context, key []byte, commitTS uint64) error
// PutWithTTLAt stores a value with a precomputed expireAt (HLC) at the given commit timestamp.
PutWithTTLAt(ctx context.Context, key []byte, value []byte, commitTS uint64, expireAt uint64) error
// ExpireAt sets/renews TTL using a precomputed expireAt (HLC) at the given commit timestamp.
ExpireAt(ctx context.Context, key []byte, expireAt uint64, commitTS uint64) error
// LatestCommitTS returns the commit timestamp of the newest version.
// The boolean reports whether the key has any version.
LatestCommitTS(ctx context.Context, key []byte) (uint64, bool, error)
// ApplyMutations atomically validates and appends the provided mutations.
// It must return ErrWriteConflict if any key has a newer commit timestamp
// than startTS.
ApplyMutations(ctx context.Context, mutations []*KVPairMutation, startTS, commitTS uint64) error
// LastCommitTS returns the highest commit timestamp applied on this node.
LastCommitTS() uint64
// Compact removes versions older than minTS that are no longer needed.
Compact(ctx context.Context, minTS uint64) error
Snapshot() (io.ReadWriter, error)
Restore(buf io.Reader) error
Close() error
}
MVCCStore extends Store with multi-version concurrency control helpers. The interface is timestamp-explicit; callers must supply the snapshot or commit timestamp for every operation.
func NewMVCCStore ¶
func NewMVCCStore(opts ...MVCCStoreOption) MVCCStore
NewMVCCStore creates a new MVCC-enabled in-memory store.
func NewPebbleStore ¶
func NewPebbleStore(dir string, opts ...PebbleStoreOption) (MVCCStore, error)
NewPebbleStore creates a new Pebble-backed MVCC store.
type MVCCStoreOption ¶
type MVCCStoreOption func(*mvccStore)
MVCCStoreOption configures the MVCCStore.
func WithLogger ¶
func WithLogger(l *slog.Logger) MVCCStoreOption
WithLogger sets a custom logger for the store.
type PebbleStoreOption ¶
type PebbleStoreOption func(*pebbleStore)
PebbleStoreOption configures the PebbleStore.
func WithPebbleLogger ¶
func WithPebbleLogger(l *slog.Logger) PebbleStoreOption
WithPebbleLogger sets a custom logger.