kv

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = &KeyNotFoundError{}

ErrKeyNotFound is returned when a key doesn't exist

View Source
var ErrNestedTransaction = &NestedTransactionError{}

ErrNestedTransaction is returned when attempting to create nested transactions

Functions

func CreatePool

func CreatePool(dataPath, metaPath string) error

CreatePool initializes the global KV store pool

func DrainPool

func DrainPool() error

DrainPool closes the global pool

Types

type BadgerBatch

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

BadgerBatch implements atomic batch operations

func (*BadgerBatch) Delete

func (b *BadgerBatch) Delete(key []byte) error

func (*BadgerBatch) Flush

func (b *BadgerBatch) Flush() error

func (*BadgerBatch) Reset

func (b *BadgerBatch) Reset()

func (*BadgerBatch) Set

func (b *BadgerBatch) Set(key, value []byte) error

type BadgerItem

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

BadgerItem wraps BadgerDB item

func (*BadgerItem) Key

func (i *BadgerItem) Key() []byte

func (*BadgerItem) KeyCopy

func (i *BadgerItem) KeyCopy() []byte

func (*BadgerItem) Value

func (i *BadgerItem) Value() ([]byte, error)

func (*BadgerItem) ValueCopy

func (i *BadgerItem) ValueCopy() ([]byte, error)

type BadgerIterator

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

BadgerIterator wraps BadgerDB iterator

func (*BadgerIterator) Close

func (i *BadgerIterator) Close() error

func (*BadgerIterator) Item

func (i *BadgerIterator) Item() Item

func (*BadgerIterator) Next

func (i *BadgerIterator) Next()

func (*BadgerIterator) Rewind

func (i *BadgerIterator) Rewind()

func (*BadgerIterator) Seek

func (i *BadgerIterator) Seek(key []byte)

func (*BadgerIterator) Valid

func (i *BadgerIterator) Valid() bool

type BadgerStore

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

BadgerStore implements Store interface using BadgerDB

func NewBadgerStore

func NewBadgerStore(path string) (*BadgerStore, error)

NewBadgerStore creates a new BadgerDB-backed store

func (*BadgerStore) Begin

func (s *BadgerStore) Begin(writable bool) (Transaction, error)

func (*BadgerStore) Close

func (s *BadgerStore) Close() error

func (*BadgerStore) Delete

func (s *BadgerStore) Delete(ctx context.Context, key []byte) error

func (*BadgerStore) Get

func (s *BadgerStore) Get(ctx context.Context, key []byte) ([]byte, error)

func (*BadgerStore) NewBatch

func (s *BadgerStore) NewBatch() Batch

func (*BadgerStore) NewIterator

func (s *BadgerStore) NewIterator(opts IteratorOptions) Iterator

func (*BadgerStore) PrefixScan added in v0.1.0

func (s *BadgerStore) PrefixScan(ctx context.Context, prefix []byte) (map[string][]byte, error)

func (*BadgerStore) Put

func (s *BadgerStore) Put(ctx context.Context, key, value []byte) error

func (*BadgerStore) Size

func (s *BadgerStore) Size() (int64, error)

func (*BadgerStore) Sync

func (s *BadgerStore) Sync() error

type BadgerTransaction

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

BadgerTransaction wraps BadgerDB transaction

func (*BadgerTransaction) Begin

func (t *BadgerTransaction) Begin(writable bool) (Transaction, error)

func (*BadgerTransaction) Close

func (t *BadgerTransaction) Close() error

func (*BadgerTransaction) Commit

func (t *BadgerTransaction) Commit() error

func (*BadgerTransaction) Delete

func (t *BadgerTransaction) Delete(ctx context.Context, key []byte) error

func (*BadgerTransaction) Discard

func (t *BadgerTransaction) Discard()

func (*BadgerTransaction) Get

func (t *BadgerTransaction) Get(ctx context.Context, key []byte) ([]byte, error)

func (*BadgerTransaction) IterateHistory added in v0.2.0

func (t *BadgerTransaction) IterateHistory(ctx context.Context, key []byte) *badger.Iterator

func (*BadgerTransaction) IterateHistoryReverse added in v0.2.0

func (t *BadgerTransaction) IterateHistoryReverse(ctx context.Context, key []byte) *badger.Iterator

func (*BadgerTransaction) NewBatch

func (t *BadgerTransaction) NewBatch() Batch

func (*BadgerTransaction) NewIterator

func (t *BadgerTransaction) NewIterator(opts IteratorOptions) Iterator

func (*BadgerTransaction) PrefixScan added in v0.1.0

func (t *BadgerTransaction) PrefixScan(ctx context.Context, prefix []byte) (map[string][]byte, error)

func (*BadgerTransaction) Put

func (t *BadgerTransaction) Put(ctx context.Context, key, value []byte) error

func (*BadgerTransaction) Size

func (t *BadgerTransaction) Size() (int64, error)

func (*BadgerTransaction) Sync

func (t *BadgerTransaction) Sync() error

type BadgerTxnBatch

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

BadgerTxnBatch implements batch operations within a transaction

func (*BadgerTxnBatch) Delete

func (b *BadgerTxnBatch) Delete(key []byte) error

func (*BadgerTxnBatch) Flush

func (b *BadgerTxnBatch) Flush() error

func (*BadgerTxnBatch) Reset

func (b *BadgerTxnBatch) Reset()

func (*BadgerTxnBatch) Set

func (b *BadgerTxnBatch) Set(key, value []byte) error

type Batch

type Batch interface {
	Set(key, value []byte) error
	Delete(key []byte) error
	Flush() error
	Reset()
}

Batch provides atomic batch operations

type Item

type Item interface {
	Key() []byte
	KeyCopy() []byte
	Value() ([]byte, error)
	ValueCopy() ([]byte, error)
}

Item represents a key-value pair during iteration

type Iterator

type Iterator interface {
	io.Closer

	// Navigation
	Rewind()
	Seek(key []byte)
	Next()
	Valid() bool

	// Data access
	Item() Item
}

Iterator provides ordered key-value iteration

type IteratorOptions

type IteratorOptions struct {
	Prefix         []byte
	Reverse        bool
	PrefetchValues bool
	PrefetchSize   int
}

IteratorOptions configures iteration behavior

type KeyNotFoundError

type KeyNotFoundError struct{}

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string

type NestedTransactionError

type NestedTransactionError struct{}

func (*NestedTransactionError) Error

func (e *NestedTransactionError) Error() string

type Pool

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

Pool manages multiple key-value store instances

func GetPool

func GetPool() *Pool

GetPool returns the global pool instance

func NewPool

func NewPool(dataPath, metaPath string) (*Pool, error)

NewPool creates a new pool with data and metadata stores

func (*Pool) BackgroundMaintenance

func (p *Pool) BackgroundMaintenance(ctx context.Context)

BackgroundMaintenance runs periodic maintenance tasks

func (*Pool) Close

func (p *Pool) Close() error

Close closes all stores in the pool

func (*Pool) DataStore

func (p *Pool) DataStore() Store

DataStore returns the main data store

func (*Pool) MetaStore

func (p *Pool) MetaStore() Store

MetaStore returns the metadata store

func (*Pool) NewDataConnection

func (p *Pool) NewDataConnection(ctx context.Context, writable bool) (*StoreConnection, error)

NewDataConnection creates a connection to the data store

func (*Pool) NewMetaConnection

func (p *Pool) NewMetaConnection(ctx context.Context, writable bool) (*StoreConnection, error)

NewMetaConnection creates a connection to the metadata store

func (*Pool) Size

func (p *Pool) Size() (dataSize, metaSize int64, err error)

Size returns the total size of all stores

func (*Pool) Sync

func (p *Pool) Sync() error

Sync synchronizes both stores to disk

type Store

type Store interface {
	// Basic operations
	Get(ctx context.Context, key []byte) ([]byte, error)
	Put(ctx context.Context, key, value []byte) error
	Delete(ctx context.Context, key []byte) error
	PrefixScan(ctx context.Context, prefix []byte) (map[string][]byte, error)

	// Batch operations for atomic writes
	NewBatch() Batch

	// Iteration support for range queries
	NewIterator(opts IteratorOptions) Iterator

	// Transaction support
	Begin(writable bool) (Transaction, error)

	// Lifecycle
	Close() error

	// Statistics and maintenance
	Size() (int64, error)
	Sync() error
}

Store defines the key-value storage interface for Atlas-DB

type StoreConnection

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

StoreConnection represents a connection to a specific store

func (*StoreConnection) Close

func (c *StoreConnection) Close() error

Close discards the transaction (alias for Rollback)

func (*StoreConnection) Commit

func (c *StoreConnection) Commit() error

Commit commits the transaction

func (*StoreConnection) Rollback

func (c *StoreConnection) Rollback()

Rollback discards the transaction

func (*StoreConnection) Store

func (c *StoreConnection) Store() Store

Store returns the underlying store

func (*StoreConnection) Transaction

func (c *StoreConnection) Transaction() Transaction

Transaction returns the active transaction

type Transaction

type Transaction interface {
	Store
	Commit() error
	Discard()
	IterateHistory(ctx context.Context, key []byte) *badger.Iterator
	IterateHistoryReverse(ctx context.Context, key []byte) *badger.Iterator
}

Transaction provides ACID transaction support

Jump to

Keyboard shortcuts

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