Documentation
¶
Overview ¶
Package pstate provides a schema-free persistent JSON state store for jobs and services. It combines immutable ordered snapshots, lock-free in-process models, and process-safe atomic file transactions.
Index ¶
- Variables
- type Entry
- type Model
- func (m *Model) Apply(patch Patch) (Snapshot, error)
- func (m *Model) Close() error
- func (m *Model) Delete(key string) (Snapshot, error)
- func (m *Model) Flush() error
- func (m *Model) Get(key string) (Value, bool)
- func (m *Model) LastError() error
- func (m *Model) Len() int
- func (m *Model) Set(key string, value Value) (Snapshot, error)
- func (m *Model) Snapshot() Snapshot
- type Patch
- type Query
- type Snapshot
- type Store
- type Tree
- type Value
- type Writer
- type WriterFunc
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("pstate: model closed")
ErrClosed is returned by operations that cannot run after Close begins.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model provides lock-free snapshots and CAS updates. Its single background worker coalesces notifications and calls Writer serially. Use Store for coordination between separate processes.
func NewModel ¶
NewModel starts a model containing initial. A nil writer disables I/O while retaining Flush and Close semantics.
func (*Model) Apply ¶
Apply atomically publishes all edits as one update. A patch with no net change does not advance the version.
func (*Model) Close ¶
Close rejects future updates, flushes the final snapshot, and stops the worker.
func (*Model) Flush ¶
Flush waits until a snapshot at least as recent as the one captured at call start has been persisted successfully.
func (*Model) LastError ¶
LastError returns the most recent background persistence error. A successful write clears it.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
Patch is an immutable ordered batch of edits. Its zero value is empty. If a key occurs more than once, the final edit wins.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a compiled deterministic predicate over an entry. Queries are safe for concurrent use.
func ParseQuery ¶
ParseQuery compiles an expression. An empty expression matches every entry.
Selectors are key, value, .field, value.field, and array/object paths such as .runs[0].status or value["odd key"]. Operators are ==, !=, <, <=, >, >=, ^= (prefix), $= (suffix), and *= (substring). Combine predicates with !, &&, ||, and parentheses. Literals use JSON syntax.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is an immutable point-in-time view. Version increases once per successfully published Model update or Store transaction.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a process-safe file-backed state store. Each mutation takes an exclusive sidecar lock, reloads the latest snapshot, and durably replaces the file, preventing lost updates between independent heartbeat invocations.
func (*Store) Apply ¶
Apply atomically commits a patch against the latest on-disk snapshot. A patch with no net change does not rewrite the file or advance its revision.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is an immutable, string-keyed ordered map of JSON values. Its zero value is empty. Set and Delete share all unaffected nodes with the original tree.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is an immutable, canonical JSON value. Its zero value is JSON null.
func EncodeValue ¶
EncodeValue converts v to an immutable JSON value.
func ParseValue ¶
ParseValue validates data and returns its deterministic compact encoding.
func (Value) Equal ¶
Equal reports JSON equality. Values are canonical, so this is constant time apart from comparing their encodings.
func (Value) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Value) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type WriterFunc ¶
WriterFunc adapts a function to Writer.
func (WriterFunc) WriteSnapshot ¶
func (f WriterFunc) WriteSnapshot(snapshot Snapshot) error
WriteSnapshot calls f(snapshot).