kvstore

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 20 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

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

NewBadgerBackupExecutor creates a new backup executor.

Types

type BackupUploader

type BackupUploader interface {
	Upload(ctx context.Context, filename string, data []byte) error
}

BackupUploader is an optional interface for pushing encrypted backup files to remote storage.

type BadgerBackupMeta

type BadgerBackupMeta struct {
	Algo            string `json:"algo"`
	NonceB64        string `json:"nonce_b64"`
	CreatedAt       string `json:"created_at"`
	EncryptionKeyID string `json:"encryption_key_id"`
}

type BadgerConfig

type BadgerConfig struct {
	NodeID              string
	EncryptionKey       []byte
	BackupEncryptionKey []byte
	BackupDir           string
	DBPath              string
	Uploader            BackupUploader // optional off-site backup uploader (e.g. R2)
}

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

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.

type R2Uploader

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

R2Uploader uploads encrypted backup files to Cloudflare R2 using the S3-compatible API.

func NewR2Uploader

func NewR2Uploader(accountID, accessKeyID, secretAccessKey, bucket, prefix string) (*R2Uploader, error)

NewR2Uploader creates an R2Uploader.

  • accountID: Cloudflare account ID (used to build the endpoint URL)
  • accessKeyID / secretAccessKey: R2 API token credentials
  • bucket: R2 bucket name
  • prefix: optional object key prefix (e.g. "node0/"); leave empty for root

func (*R2Uploader) Download

func (u *R2Uploader) Download(ctx context.Context, key string) ([]byte, error)

Download retrieves a single object by its full key and returns its contents.

func (*R2Uploader) ListObjects

func (u *R2Uploader) ListObjects(ctx context.Context) ([]string, error)

ListObjects returns all object keys under the uploader's prefix, sorted ascending.

func (*R2Uploader) Upload

func (u *R2Uploader) Upload(ctx context.Context, filename string, data []byte) error

Upload sends the encrypted backup file to R2. The object key is <prefix><filename>.

Jump to

Keyboard shortcuts

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