kvstore

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEncryptionKeyNotProvided       = errors.New("encryption key not provided")
	ErrBackupEncryptionKeyNotProvided = errors.New("backup encryption key not provided")
)

Functions

func NewBadgerBackupExecutor added in v0.3.1

func NewBadgerBackupExecutor(
	nodeID string,
	db *badger.DB,
	backupEncryptionKey []byte,
	backupDir string,
) *badgerBackupExecutor

NewBadgerBackupExecutor creates a new backup executor. If backupDir is empty, uses ./backups

Types

type BadgerBackupMeta added in v0.3.1

type BadgerBackupMeta struct {
	Algo            string `json:"algo"`              // AES-256-GCM
	NonceB64        string `json:"nonce_b64"`         // base64 nonce
	CreatedAt       string `json:"created_at"`        // RFC3339
	Since           uint64 `json:"since"`             // input watermark
	NextSince       uint64 `json:"next_since"`        // output watermark
	EncryptionKeyID string `json:"encryption_key_id"` // sha256(key) prefix
}

type BadgerBackupVersionInfo added in v0.3.1

type BadgerBackupVersionInfo struct {
	Version   uint64 `json:"version"`    // Human-readable counter
	Since     uint64 `json:"since"`      // Badger internal backup offset
	UpdatedAt string `json:"updated_at"` // RFC3339
}

type BadgerConfig added in v0.3.1

type BadgerConfig struct {
	NodeID              string
	EncryptionKey       []byte
	BackupEncryptionKey []byte
	BackupDir           string
	DBPath              string
}

type BadgerKVStore

type BadgerKVStore struct {
	DB             *badger.DB
	BackupExecutor *badgerBackupExecutor
}

BadgerKVStore is an implementation of the KVStore interface using BadgerDB.

func NewBadgerKVStore

func NewBadgerKVStore(config BadgerConfig) (*BadgerKVStore, error)

NewBadgerKVStore creates a new BadgerKVStore instance.

func (*BadgerKVStore) Backup added in v0.3.1

func (b *BadgerKVStore) Backup() error

func (*BadgerKVStore) Close

func (b *BadgerKVStore) Close() error

Close closes the BadgerDB.

func (*BadgerKVStore) Delete

func (b *BadgerKVStore) Delete(key string) error

Delete removes a key-value pair from BadgerDB.

func (*BadgerKVStore) Get

func (b *BadgerKVStore) Get(key string) ([]byte, error)

Get retrieves the value associated with a key from BadgerDB.

func (*BadgerKVStore) Keys

func (b *BadgerKVStore) Keys() ([]string, error)

func (*BadgerKVStore) Put

func (b *BadgerKVStore) Put(key string, value []byte) error

Put stores a key-value pair in the BadgerDB.

type KVStore

type KVStore interface {
	// Put stores a key-value pair in the store.
	Put(key string, value []byte) error

	// Get retrieves the value associated with a key. If the key is not found, it returns an empty slice.
	Get(key string) ([]byte, error)

	// Delete removes a key-value pair from the store.
	Delete(key string) error

	// Close closes the key-value store.
	Close() error

	Backup() error
}

KVStore defines the interface for a key-value store.

Jump to

Keyboard shortcuts

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