Documentation
¶
Overview ¶
Package snapshot defines immutable, versioned CRDT state snapshots and bounded recovery plans.
Index ¶
- Variables
- type RecoveryPlan
- type Snapshot
- func New(state []byte, frontier map[string]crdt.Tag) (Snapshot, error)
- func NewValidated(state []byte, frontier map[string]crdt.Tag, validator StateValidator) (Snapshot, error)
- func NewValidatedWithClockState(state []byte, frontier map[string]crdt.Tag, clockState clock.State, ...) (Snapshot, error)
- func NewWithClockState(state []byte, frontier map[string]crdt.Tag, clockState clock.State) (Snapshot, error)
- type StateValidator
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("snapshot: invalid snapshot") ErrLimit = errors.New("snapshot: recovery plan limit exceeded") )
Functions ¶
This section is empty.
Types ¶
type RecoveryPlan ¶
type RecoveryPlan struct {
Snapshot Snapshot
// contains filtered or unexported fields
}
RecoveryPlan contains a validated state snapshot followed by compatible encoded deltas. Applying Deltas in any order is safe because they are CRDT joins; callers decide persistence and retry policy.
func NewRecoveryPlan ¶
func NewRecoveryPlan(snapshot Snapshot, deltas [][]byte, maxDeltaBytes int) (RecoveryPlan, error)
NewRecoveryPlan validates compatible delta frames and bounds their combined byte size before creating an immutable recovery plan.
func (RecoveryPlan) Deltas ¶
func (p RecoveryPlan) Deltas() [][]byte
Deltas returns copies of the recovery delta frames.
type Snapshot ¶
type Snapshot struct {
FormatVersion uint64
TypeID uint64
CodecID string
// contains filtered or unexported fields
}
Snapshot holds one complete framed state payload and the full per-replica tag frontier known when it was saved. Its bytes and frontier are copied on both input and output. OR-Set snapshots may also carry the local HLC state needed to safely reuse a replica ID after recovery. Concrete CRDT decoders remain responsible for validating the type-specific payload before it is applied.
func New ¶
New validates the state frame envelope and records a cloned frontier. It does not decode the type-specific payload; use NewValidated when a snapshot must be rejected before persistence unless its concrete CRDT state is valid.
func NewValidated ¶
func NewValidated(state []byte, frontier map[string]crdt.Tag, validator StateValidator) (Snapshot, error)
NewValidated creates a snapshot only when both the frame envelope and its type-specific state are valid according to validator.
func NewValidatedWithClockState ¶
func NewValidatedWithClockState(state []byte, frontier map[string]crdt.Tag, clockState clock.State, validator StateValidator) (Snapshot, error)
NewValidatedWithClockState creates an HLC-backed CRDT snapshot only when its frame, clock state, and type-specific payload are valid. Use it when accepting an externally supplied OR-Set snapshot before persistence.
func NewWithClockState ¶
func NewWithClockState(state []byte, frontier map[string]crdt.Tag, clockState clock.State) (Snapshot, error)
NewWithClockState creates an HLC-backed CRDT snapshot with the local clock state that must be persisted atomically before its replica ID is reused.
func (Snapshot) ClockState ¶
ClockState returns the local HLC state carried by an OR-Set snapshot. The boolean is false for snapshots without HLC state, including G-Counters and legacy snapshots created with New.
type StateValidator ¶
StateValidator validates a type-specific canonical CRDT state frame. It is invoked once while a validated snapshot is created; a panic is treated as an invalid state.