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 ¶
- Variables
- func Count(tx Tx, ns, prefix string) int
- func Counts(st Store, nss map[string]string) map[string]int
- func Exists(tx Tx, ns, key string) bool
- func GetJSON(tx Tx, ns, key string, v any) error
- func HasPrefix(tx Tx, ns, prefix string) bool
- func ListJSON[T any](tx Tx, ns, prefix string) ([]T, error)
- func PutJSON(tx Tx, ns, key string, v any) error
- type Bolt
- type Change
- type Memory
- type Observer
- type Store
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("store: not found")
ErrNotFound is returned by GetJSON when a key is absent.
Functions ¶
func Counts ¶ added in v0.2.0
Counts returns, for each resource type in nss, the number of keys in its namespace.
Types ¶
type Bolt ¶
type Bolt struct {
// contains filtered or unexported fields
}
Bolt is a crash-safe file-backed Store built on bbolt.
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.
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.
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.