Documentation
¶
Overview ¶
Package register implements state-based register CRDTs.
Index ¶
- Variables
- type LWW
- type MVEntry
- type MVRegister
- func (r *MVRegister) ApplyDelta(delta MVRegisterDelta) error
- func (r *MVRegister) MarshalBinary() ([]byte, error)
- func (r *MVRegister) MarshalJSON() ([]byte, error)
- func (r *MVRegister) Merge(other *MVRegister) error
- func (r *MVRegister) Set(value []byte) (MVRegisterDelta, error)
- func (r *MVRegister) Snapshot() (snapshot.Snapshot, error)
- func (r *MVRegister) State() crdt.StateSnapshot
- func (r *MVRegister) UnmarshalBinary(data []byte) error
- func (r *MVRegister) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
- func (r *MVRegister) Value() ([]byte, bool)
- func (r *MVRegister) Values() []MVEntry
- type MVRegisterDelta
- type Max
Constants ¶
This section is empty.
Variables ¶
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") )
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 (*LWW) ClockState ¶
func (*LWW) MarshalJSON ¶ added in v1.0.5
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) State ¶
func (r *LWW) State() crdt.StateSnapshot
type MVEntry ¶ added in v1.0.5
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
func (d MVRegisterDelta) Merge(other MVRegisterDelta) (MVRegisterDelta, error)
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 (*Max) MarshalJSON ¶ added in v1.0.5
MarshalJSON returns a diagnostic summary for structured logs. It omits the register value and cannot restore the register.
func (*Max) State ¶
func (r *Max) State() crdt.StateSnapshot