store

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store is the control-plane state store (FR-CORE-032): a small transactional, namespaced key-value interface with an in-memory implementation for --ephemeral and a bbolt (pure Go) one for --data-dir.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("store: not found")

ErrNotFound is returned by GetJSON when a key is absent.

Functions

func Count added in v0.2.0

func Count(tx Tx, ns, prefix string) int

Count returns the number of keys in ns that start with prefix.

func Counts added in v0.2.0

func Counts(st Store, nss map[string]string) map[string]int

Counts returns, for each resource type in nss, the number of keys in its namespace.

func Exists

func Exists(tx Tx, ns, key string) bool

Exists reports whether ns/key is present.

func GetJSON

func GetJSON(tx Tx, ns, key string, v any) error

GetJSON unmarshals the value at ns/key into v.

func HasPrefix

func HasPrefix(tx Tx, ns, prefix string) bool

HasPrefix reports whether any key in ns starts with prefix.

func ListJSON

func ListJSON[T any](tx Tx, ns, prefix string) ([]T, error)

ListJSON decodes every value under prefix into a slice of T.

func PutJSON

func PutJSON(tx Tx, ns, key string, v any) error

PutJSON marshals v and stores it at ns/key.

Types

type Bolt

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

Bolt is a crash-safe file-backed Store built on bbolt.

func OpenBolt

func OpenBolt(path string) (*Bolt, error)

OpenBolt opens (creating if needed) a bbolt database at path.

func (*Bolt) Close

func (s *Bolt) Close() error

func (*Bolt) Dump

func (s *Bolt) Dump() (map[string]map[string][]byte, error)

func (*Bolt) Load

func (s *Bolt) Load(data map[string]map[string][]byte) error

func (*Bolt) Reset

func (s *Bolt) Reset() error

func (*Bolt) Update

func (s *Bolt) Update(fn func(Tx) error) error

func (*Bolt) View

func (s *Bolt) View(fn func(Tx) error) error

type Change added in v0.2.0

type Change struct {
	NS, Key string
	// Val is the value written; nil when Deleted.
	Val     []byte
	Deleted bool
}

Change is one key written or deleted by a committed Update.

type Memory

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

Memory is an in-memory Store. Update transactions are serialised and rolled back on error using an undo log.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty in-memory store.

func (*Memory) Close

func (m *Memory) Close() error

func (*Memory) Dump

func (m *Memory) Dump() (map[string]map[string][]byte, error)

func (*Memory) Load

func (m *Memory) Load(data map[string]map[string][]byte) error

func (*Memory) Reset

func (m *Memory) Reset() error

func (*Memory) Update

func (m *Memory) Update(fn func(Tx) error) (err error)

func (*Memory) View

func (m *Memory) View(fn func(Tx) error) error

type Observer added in v0.2.0

type Observer interface {
	// Committed receives the changes of one Update in the order of their
	// last write; a key written several times appears once. It is called
	// after the Update commits, outside the store's lock, so concurrent
	// Updates may be reported out of order.
	Committed([]Change)
	// Replaced is called after Reset or Load replaced all contents.
	Replaced()
}

Observer is told what committed Updates changed.

type Store

type Store interface {
	View(fn func(Tx) error) error
	Update(fn func(Tx) error) error
	// Reset deletes every namespace.
	Reset() error
	// Dump returns every namespace's contents (for snapshots and admin dumps).
	Dump() (map[string]map[string][]byte, error)
	// Load replaces all contents with data.
	Load(data map[string]map[string][]byte) error
	Close() error
}

Store is a transactional namespaced KV store. Keys within a namespace are iterated in byte order.

func Observe added in v0.2.0

func Observe(st Store, o Observer) Store

Observe wraps st so that o learns of every committed change.

type Tx

type Tx interface {
	Get(ns, key string) ([]byte, bool)
	Put(ns, key string, val []byte) error
	Delete(ns, key string) error
	// Scan calls fn for every key in ns with the given prefix, in order,
	// until fn returns false.
	Scan(ns, prefix string, fn func(key string, val []byte) bool)
}

Tx is a store transaction. Writes on a View transaction return an error.

Jump to

Keyboard shortcuts

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