store

package
v0.0.0-...-15eed02 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListMetaPrefix = "!lst|meta|"
	ListItemPrefix = "!lst|itm|"
)

Variables

View Source
var ErrExpired = errors.New("expired")
View Source
var ErrInvalidChecksum = errors.New("invalid checksum")
View Source
var ErrKeyNotFound = errors.New("not found")
View Source
var ErrNotSupported = errors.New("not supported")
View Source
var ErrUnknownOp = errors.New("unknown op")
View Source
var ErrWriteConflict = errors.New("write conflict")
View Source
var Tombstone = []byte{0x00}

Functions

func ExtractListUserKey

func ExtractListUserKey(key []byte) []byte

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 IsListItemKey(key []byte) bool

func IsListMetaKey

func IsListMetaKey(key []byte) bool

IsListMetaKey Exported helpers for other packages (e.g., Redis adapter).

func ListItemKey

func ListItemKey(userKey []byte, seq int64) []byte

ListItemKey builds the item key for a user key and sequence number.

func ListMetaKey

func ListMetaKey(userKey []byte) []byte

ListMetaKey builds the metadata key for a user key.

func MarshalListMeta

func MarshalListMeta(meta ListMeta) ([]byte, error)

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 KVPair

type KVPair struct {
	Key   []byte
	Value []byte
}

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

type ListMeta struct {
	Head int64 `json:"h"`
	Tail int64 `json:"t"`
	Len  int64 `json:"l"`
}

func UnmarshalListMeta

func UnmarshalListMeta(b []byte) (ListMeta, error)

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 OpType

type OpType int

OpType describes a mutation kind.

const (
	OpTypePut OpType = iota
	OpTypeDelete
)

type PebbleStoreOption

type PebbleStoreOption func(*pebbleStore)

PebbleStoreOption configures the PebbleStore.

func WithPebbleLogger

func WithPebbleLogger(l *slog.Logger) PebbleStoreOption

WithPebbleLogger sets a custom logger.

type VersionedValue

type VersionedValue struct {
	TS        uint64
	Value     []byte
	Tombstone bool
	ExpireAt  uint64 // HLC timestamp; 0 means no TTL
}

VersionedValue represents a single committed version in MVCC storage.

Jump to

Keyboard shortcuts

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