snapshot

package
v1.0.36 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package snapshot defines immutable, versioned CRDT state snapshots and bounded recovery plans.

Index

Constants

This section is empty.

Variables

View Source
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

func New(state []byte, frontier map[string]crdt.Tag) (Snapshot, error)

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) Bytes

func (s Snapshot) Bytes() []byte

Bytes returns a copy of the canonical state frame.

func (Snapshot) ClockState

func (s Snapshot) ClockState() (clock.State, bool)

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.

func (Snapshot) Frontier

func (s Snapshot) Frontier() map[string]crdt.Tag

Frontier returns a copy of the full per-replica tag frontier.

type StateValidator

type StateValidator func([]byte) error

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.

Jump to

Keyboard shortcuts

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