Documentation
¶
Overview ¶
Package state is where the engine keeps what must survive a restart (a daemon restart natively, a page reload in a browser): containers, their logs and their writable layers. It is a small key-value Store with three implementations — a directory (wctrd's --data-root), memory (tests), and IndexedDB (the playground, outside this module) — and a sealed record format that detects a torn or corrupted value instead of trusting it.
Keys are "<kind>/<name>", kind lower-case letters, name lower-case hex or letters, digits, '.', '_' and '-' (at most 128 bytes in all), so a key is also a safe relative file path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("state: not found") // ErrNoSpace wraps a store's quota failure (QuotaExceededError in a // browser, ENOSPC natively). A Put that fails with it wrote nothing. ErrNoSpace = errors.New("state: no space left") // ErrCorrupt is a value whose seal does not match its content. ErrCorrupt = errors.New("state: corrupted record") ErrBadKey = errors.New("state: invalid key") )
Errors a Store returns.
Functions ¶
Types ¶
type Describer ¶
Describer is an optional Store method naming where it keeps values and how many bytes they hold (-1: unknown), for `system df`.
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir is a Store in a directory: one file per key, <root>/<kind>/<name>. A Put writes a temporary file, syncs it and renames it over the key, so a crash leaves the old value or the new one.
type Mem ¶
type Mem struct {
MaxBytes int64
// contains filtered or unexported fields
}
Mem is a Store in memory, bounded by MaxBytes (0 = unbounded).
type Store ¶
type Store interface {
Get(key string) ([]byte, error)
Put(key string, value []byte) error
Delete(key string) error // nil when absent
Keys(prefix string) ([]string, error)
}
Store keeps values by key. Put is atomic per key: after a crash a key holds the old value or the new one, never a mix. Implementations are safe for concurrent use.