bbolt

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingPath     = errors.New("bbolt: path is missing from config")
	ErrCantWriteToPath = errors.New("bbolt: can't write to path")
)
View Source
var (
	ErrNotExists = errors.New("bbolt: value does not exist in store")
)

Sentinel error value used for testing and in admin-visible error messages.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path is the filesystem path of the database. The folder must be writable to Anubis.
	Path string `json:"path"`
}

Config is the bbolt storage backend configuration.

func (Config) Valid

func (c Config) Valid() error

Valid validates the configuration including checking if its containing folder is writable.

type Factory

type Factory struct{}

Factory builds new instances of the bbolt storage backend according to configuration passed via a json.RawMessage.

func (Factory) Build

func (Factory) Build(ctx context.Context, data json.RawMessage) (store.Interface, error)

Build parses and validates the bbolt storage backend Config and creates a new instance of it.

func (Factory) Valid

func (Factory) Valid(data json.RawMessage) error

Valid parses and validates the bbolt store Config or returns an error.

type Store

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

Store implements store.Interface backed by bbolt1.

In essence, bbolt is a hierarchical key/value store with a twist: every value needs to belong to a bucket. Buckets can contain an infinite number of buckets. As such, Anubis nests values in buckets. Each value in the store is given its own bucket with two keys:

1. data - The raw data, usually in JSON 2. expiry - The expiry time formatted as a time.RFC3339Nano timestamp string

When Anubis stores a new bit of data, it creates a new bucket for that value. This allows the cleanup phase to iterate over every bucket in the database and only scan the expiry times without having to decode the entire record.

bbolt is not suitable for environments where multiple instance of Anubis need to read from and write to the same backend store. For that, use the valkey storage backend.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete a key from the datastore. If the key does not exist, return an error.

func (*Store) Get

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

Get a value from the datastore.

Because each value is stored in its own bucket with data and expiry keys, two get operations are required:

1. Get the expiry key, parse as time.RFC3339Nano. If the key has expired, run deletion in the background and return a "key not found" error. 2. Get the data key, copy into the result byteslice, return it.

func (*Store) IsPersistent added in v1.23.0

func (s *Store) IsPersistent() bool

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, expiry time.Duration) error

Set a value into the store with a given expiry.

Jump to

Keyboard shortcuts

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