register

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: 10 Imported by: 0

Documentation

Overview

Package register implements state-based register CRDTs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilMVRegister      = errors.New("register: nil MV-Register")
	ErrInvalidMVRegister  = errors.New("register: invalid MV-Register state")
	ErrMVRegisterOverflow = errors.New("register: MV-Register version overflow")
	ErrInvalidMVSnapshot  = errors.New("register: invalid MV-Register snapshot")
)
View Source
var (
	ErrInvalidReplicaID = errors.New("register: invalid replica ID")
	ErrNilLWW           = errors.New("register: nil LWW register")
	ErrNilMax           = errors.New("register: nil max register")
	ErrTagConflict      = errors.New("register: conflicting value for one tag")
)

Functions

This section is empty.

Types

type LWW

type LWW struct {
	// contains filtered or unexported fields
}

LWW stores an opaque byte value selected by the greatest HLC tag. Values are copied at both API boundaries so callers cannot mutate converged state.

func NewLWW

func NewLWW(replicaID string) (*LWW, error)

func NewLWWFromClock

func NewLWWFromClock(state clock.State) (*LWW, error)

func (*LWW) ClockState

func (r *LWW) ClockState() clock.State

func (*LWW) Get

func (r *LWW) Get() ([]byte, bool)

func (*LWW) MarshalJSON added in v1.0.5

func (r *LWW) MarshalJSON() ([]byte, error)

MarshalJSON returns a diagnostic summary for structured logs. It omits the opaque value, HLC tag, and clock state, and cannot restore the register.

func (*LWW) Merge

func (r *LWW) Merge(other *LWW) error

func (*LWW) Set

func (r *LWW) Set(value []byte) error

func (*LWW) State

func (r *LWW) State() crdt.StateSnapshot

type MVEntry added in v1.0.5

type MVEntry struct {
	ReplicaID string
	Counter   uint64
	Value     []byte
}

MVEntry is one concurrently visible MV-Register value. Value is owned by the caller; it never aliases register state.

type MVRegister added in v1.0.5

type MVRegister struct {
	// contains filtered or unexported fields
}

MVRegister is a multi-value register. A Set overwrites every value it has observed, while values written concurrently at different replicas remain visible together. Causal context is represented by a per-replica version vector, not wall-clock time, so clock skew cannot discard a concurrent write.

func NewMVRegister added in v1.0.5

func NewMVRegister(replicaID string) (*MVRegister, error)

NewMVRegister creates a causally replicated multi-value register for replicaID. Reusing an ID requires restoring its prior state first.

func NewMVRegisterFromSnapshot added in v1.0.5

func NewMVRegisterFromSnapshot(replicaID string, saved snapshot.Snapshot) (*MVRegister, error)

NewMVRegisterFromSnapshot restores a register and its causal context. The restored state must be persisted atomically before reusing replicaID.

func (*MVRegister) ApplyDelta added in v1.0.5

func (r *MVRegister) ApplyDelta(delta MVRegisterDelta) error

ApplyDelta joins delta into r.

func (*MVRegister) MarshalBinary added in v1.0.5

func (r *MVRegister) MarshalBinary() ([]byte, error)

MarshalBinary returns the canonical framed MV-Register state.

func (*MVRegister) MarshalJSON added in v1.0.5

func (r *MVRegister) MarshalJSON() ([]byte, error)

MarshalJSON returns a diagnostic summary for structured logs. It omits values, causal context, and dots, and cannot restore the register.

func (*MVRegister) Merge added in v1.0.5

func (r *MVRegister) Merge(other *MVRegister) error

Merge joins other into r. The receiver changes only after both states have been validated and a same-dot value conflict has been ruled out.

func (*MVRegister) Set added in v1.0.5

func (r *MVRegister) Set(value []byte) (MVRegisterDelta, error)

Set stores value, causally overwriting all values currently observed by r, and returns a delta suitable for duplicate and out-of-order delivery.

func (*MVRegister) Snapshot added in v1.0.5

func (r *MVRegister) Snapshot() (snapshot.Snapshot, error)

Snapshot returns an immutable state snapshot containing the causal context required to resume writes safely with the same replica ID.

func (*MVRegister) State added in v1.0.5

func (r *MVRegister) State() crdt.StateSnapshot

State returns an immutable diagnostic summary.

func (*MVRegister) UnmarshalBinary added in v1.0.5

func (r *MVRegister) UnmarshalBinary(data []byte) error

UnmarshalBinary atomically replaces r with one canonical state frame.

func (*MVRegister) UnmarshalBinaryWithLimits added in v1.0.5

func (r *MVRegister) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error

UnmarshalBinaryWithLimits validates all state before replacing r.

func (*MVRegister) Value added in v1.0.5

func (r *MVRegister) Value() ([]byte, bool)

Value returns the sole value when no write is concurrent with it.

func (*MVRegister) Values added in v1.0.5

func (r *MVRegister) Values() []MVEntry

Values returns all concurrently visible values in canonical dot order.

type MVRegisterDelta added in v1.0.5

type MVRegisterDelta struct {
	// contains filtered or unexported fields
}

MVRegisterDelta is a joinable partial MV-Register state. Set returns a delta carrying its new value and the full causal context it observed, which is required to remove only causally prior values at another replica.

func UnmarshalMVRegisterDelta added in v1.0.5

func UnmarshalMVRegisterDelta(data []byte) (MVRegisterDelta, error)

UnmarshalMVRegisterDelta validates and returns one MV-Register delta frame.

func UnmarshalMVRegisterDeltaWithLimits added in v1.0.5

func UnmarshalMVRegisterDeltaWithLimits(data []byte, limits frame.DecoderLimits) (MVRegisterDelta, error)

UnmarshalMVRegisterDeltaWithLimits validates a bounded delta frame.

func (MVRegisterDelta) MarshalBinary added in v1.0.5

func (d MVRegisterDelta) MarshalBinary() ([]byte, error)

MarshalBinary returns the canonical framed MV-Register delta.

func (MVRegisterDelta) MarshalJSON added in v1.0.5

func (d MVRegisterDelta) MarshalJSON() ([]byte, error)

MarshalJSON returns a diagnostic summary for structured logs. It omits values, causal context, and dots and cannot be applied as a delta from JSON.

func (MVRegisterDelta) Merge added in v1.0.5

Merge joins partial states without modifying either input delta.

func (MVRegisterDelta) Values added in v1.0.5

func (d MVRegisterDelta) Values() []MVEntry

Values returns copies of the values represented by d in canonical order.

type Max

type Max struct {
	// contains filtered or unexported fields
}

Max is a grow-only register. A write below its current value is a no-op; Merge takes the maximum, which is associative, commutative, and idempotent.

func NewMax

func NewMax() *Max

func (*Max) Get

func (r *Max) Get() (uint64, bool)

func (*Max) MarshalJSON added in v1.0.5

func (r *Max) MarshalJSON() ([]byte, error)

MarshalJSON returns a diagnostic summary for structured logs. It omits the register value and cannot restore the register.

func (*Max) Merge

func (r *Max) Merge(other *Max) error

func (*Max) Set

func (r *Max) Set(value uint64) error

func (*Max) State

func (r *Max) State() crdt.StateSnapshot

Jump to

Keyboard shortcuts

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