Documentation
¶
Overview ¶
Package list implements a generic, ordered Replicated Growable Array (RGA).
Each position holds one canonical caller-coded value. Positions, rather than offsets, are replicated, so duplicate and out-of-order delivery converge.
Index ¶
- Constants
- Variables
- func MoveFrameType() crdt.FrameType
- func StableFrameType() crdt.FrameType
- type Delta
- type ElementCodec
- type MoveDelta
- type MoveRGA
- func NewMoveRGA[T any](replicaID string, codec ElementCodec[T]) (*MoveRGA[T], error)
- func NewMoveRGAFromClockWithOptions[T any](state clock.State, codec ElementCodec[T], options Options) (*MoveRGA[T], error)
- func NewMoveRGAFromSnapshot[T any](saved snapshot.Snapshot, codec ElementCodec[T]) (*MoveRGA[T], error)
- func NewMoveRGAWithOptions[T any](replicaID string, codec ElementCodec[T], options Options) (*MoveRGA[T], error)
- func (r *MoveRGA[T]) Append(values []T) (MoveDelta, error)
- func (r *MoveRGA[T]) ApplyDelta(delta MoveDelta) error
- func (r *MoveRGA[T]) ClockState() clock.State
- func (r *MoveRGA[T]) Delete(offset, count int) (MoveDelta, error)
- func (r *MoveRGA[T]) Insert(offset int, values []T) (MoveDelta, error)
- func (r *MoveRGA[T]) MarshalBinary() ([]byte, error)
- func (r *MoveRGA[T]) MarshalBinaryWithClockState() ([]byte, clock.State, error)
- func (r *MoveRGA[T]) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
- func (r *MoveRGA[T]) Merge(other *MoveRGA[T]) error
- func (r *MoveRGA[T]) Move(from, count, to int) (MoveDelta, error)
- func (r *MoveRGA[T]) Positions() []Position
- func (r *MoveRGA[T]) SnapshotCurrentState() (snapshot.Snapshot, error)
- func (r *MoveRGA[T]) State() crdt.StateSnapshot
- func (r *MoveRGA[T]) UnmarshalBinary(data []byte) error
- func (r *MoveRGA[T]) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
- func (r *MoveRGA[T]) Values() ([]T, error)
- type Options
- type Position
- type RGA
- func New[T any](replicaID string, codec ElementCodec[T]) (*RGA[T], error)
- func NewFromClock[T any](state clock.State, codec ElementCodec[T]) (*RGA[T], error)
- func NewFromClockWithOptions[T any](state clock.State, codec ElementCodec[T], options Options) (*RGA[T], error)
- func NewFromSnapshot[T any](saved snapshot.Snapshot, codec ElementCodec[T]) (*RGA[T], error)
- func NewFromSnapshotWithOptions[T any](saved snapshot.Snapshot, codec ElementCodec[T], options Options, ...) (*RGA[T], error)
- func NewWithOptions[T any](replicaID string, codec ElementCodec[T], options Options) (*RGA[T], error)
- func (r *RGA[T]) Append(values []T) (Delta, error)
- func (r *RGA[T]) ApplyDelta(delta Delta) error
- func (r *RGA[T]) At(offset int) (T, error)
- func (r *RGA[T]) ClockState() clock.State
- func (r *RGA[T]) CompactTombstones(tags []Position) (int, error)
- func (r *RGA[T]) Delete(offset, count int) (Delta, error)
- func (r *RGA[T]) Insert(offset int, values []T) (Delta, error)
- func (r *RGA[T]) MarshalBinary() ([]byte, error)
- func (r *RGA[T]) MarshalBinaryWithClockState() ([]byte, clock.State, error)
- func (r *RGA[T]) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
- func (r *RGA[T]) Merge(other *RGA[T]) error
- func (r *RGA[T]) MissingParents() []Position
- func (r *RGA[T]) PendingCount() int
- func (r *RGA[T]) Positions() []Position
- func (r *RGA[T]) SnapshotCurrentState() (snapshot.Snapshot, error)
- func (r *RGA[T]) State() crdt.StateSnapshot
- func (r *RGA[T]) TombstoneTags() []Position
- func (r *RGA[T]) UnmarshalBinary(data []byte) error
- func (r *RGA[T]) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
- func (r *RGA[T]) Values() ([]T, error)
Constants ¶
const MoveSemanticsVersion uint64 = crdt.SemanticsVersionMoveRGA
MoveSemanticsVersion is the immutable contract for the move-capable list. It is intentionally distinct from the insert/delete-only list RGA version.
const SemanticsVersion uint64 = crdt.SemanticsVersionListRGA
SemanticsVersion is the immutable generic list RGA v1 contract. It must match the value negotiated in a replica manifest.
Variables ¶
var ( ErrNilList = errors.New("list: nil RGA") ErrInvalidReplica = errors.New("list: invalid replica ID") ErrInvalidCodec = errors.New("list: invalid element codec") ErrRange = errors.New("list: range outside visible list") ErrInvalidDelta = errors.New("list: invalid RGA delta") ErrTagConflict = errors.New("list: conflicting node for one tag") ErrIncompleteState = errors.New("list: incomplete RGA state") ErrResourceLimit = errors.New("list: RGA resource limit exceeded") ErrUnsafeCompaction = errors.New("list: unsafe RGA tombstone compaction") )
Functions ¶
func MoveFrameType ¶ added in v1.0.26
MoveFrameType returns the framed protocol a manifest must negotiate for a MoveRGA document. It is not interchangeable with StableFrameType, which describes the insert/delete-only generic list RGA.
func StableFrameType ¶ added in v1.0.25
StableFrameType returns the stable generic list RGA v1 state/delta pair.
Types ¶
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
Delta is an opaque, joinable partial list state. It is constructed by local mutations or bounded frame decoding only.
func UnmarshalDelta ¶
func UnmarshalDelta[T any](data []byte, codec ElementCodec[T]) (Delta, error)
UnmarshalDelta decodes a bounded canonical list delta for codec.
func UnmarshalDeltaWithLimits ¶
func UnmarshalDeltaWithLimits[T any](data []byte, codec ElementCodec[T], limits frame.DecoderLimits) (Delta, error)
UnmarshalDeltaWithLimits decodes a bounded canonical list delta for codec.
func (Delta) MarshalBinary ¶
MarshalBinary returns one canonical list delta frame.
func (Delta) MarshalBinaryWithLimits ¶
func (d Delta) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
MarshalBinaryWithLimits returns a canonical bounded list delta frame.
type ElementCodec ¶
type ElementCodec[T any] interface { ID() string Marshal(T) ([]byte, error) Unmarshal([]byte) (T, error) }
ElementCodec defines one application value's canonical wire representation. Marshal must encode semantically equal values identically. The RGA verifies every locally created and remotely decoded value by a decode/re-encode round trip before it can enter replicated state.
type MoveDelta ¶ added in v1.0.25
type MoveDelta struct {
// contains filtered or unexported fields
}
MoveDelta is an opaque, joinable partial MoveRGA state. Local operations and the bounded decoder are its only constructors.
func UnmarshalMoveDelta ¶ added in v1.0.25
func UnmarshalMoveDelta[T any](data []byte, codec ElementCodec[T]) (MoveDelta, error)
UnmarshalMoveDelta decodes a bounded canonical move-sequence delta.
func UnmarshalMoveDeltaWithLimits ¶ added in v1.0.25
func UnmarshalMoveDeltaWithLimits[T any](data []byte, codec ElementCodec[T], limits frame.DecoderLimits) (MoveDelta, error)
UnmarshalMoveDeltaWithLimits decodes a bounded canonical move-sequence delta and verifies that every application value round-trips canonically.
func (MoveDelta) MarshalBinary ¶ added in v1.0.25
func (MoveDelta) MarshalBinaryWithLimits ¶ added in v1.0.25
func (d MoveDelta) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
type MoveRGA ¶ added in v1.0.25
type MoveRGA[T any] struct { // contains filtered or unexported fields }
MoveRGA is a move-capable, generic sequence CRDT. It is intentionally a different protocol from RGA: existing List RGA frames retain their immutable insert/delete-only semantics.
Element identities are immutable. A move writes a per-element placement register whose HLC operation ID provides last-writer-wins conflict resolution. Concurrent moves can create an attachment cycle; projection deterministically drops the lower-priority cycle-closing attachment instead of mutating shared state. Therefore replicas converge without pretending that every concurrent intent can be satisfied simultaneously.
func NewMoveRGA ¶ added in v1.0.25
func NewMoveRGA[T any](replicaID string, codec ElementCodec[T]) (*MoveRGA[T], error)
NewMoveRGA constructs a move-capable sequence using conservative defaults.
func NewMoveRGAFromClockWithOptions ¶ added in v1.0.25
func NewMoveRGAFromClockWithOptions[T any](state clock.State, codec ElementCodec[T], options Options) (*MoveRGA[T], error)
NewMoveRGAFromClockWithOptions restores a replica clock that was persisted atomically with a MoveRGA snapshot.
func NewMoveRGAFromSnapshot ¶ added in v1.0.25
func NewMoveRGAWithOptions ¶ added in v1.0.25
func NewMoveRGAWithOptions[T any](replicaID string, codec ElementCodec[T], options Options) (*MoveRGA[T], error)
NewMoveRGAWithOptions constructs a move-capable sequence with explicit retained-state limits.
func (*MoveRGA[T]) ApplyDelta ¶ added in v1.0.25
ApplyDelta atomically joins a bounded, validated MoveRGA delta.
func (*MoveRGA[T]) ClockState ¶ added in v1.0.25
ClockState returns the HLC state that must be persisted with a snapshot.
func (*MoveRGA[T]) Delete ¶ added in v1.0.25
Delete tombstones count visible elements starting at offset. Tombstones retain their placement identity until the same application-level checkpoint and acknowledgement lifecycle used by other structural sequences permits GC.
func (*MoveRGA[T]) Insert ¶ added in v1.0.25
Insert inserts values before offset. Each value receives a permanent identity; later Move calls relocate that identity rather than cloning it.
func (*MoveRGA[T]) MarshalBinary ¶ added in v1.0.25
MarshalBinary returns a complete canonical MoveRGA state frame. A complete snapshot rejects missing node/move dependencies rather than silently losing an out-of-order operation.
func (*MoveRGA[T]) MarshalBinaryWithClockState ¶ added in v1.0.25
func (*MoveRGA[T]) MarshalBinaryWithLimits ¶ added in v1.0.25
func (r *MoveRGA[T]) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
func (*MoveRGA[T]) Merge ¶ added in v1.0.25
Merge joins the complete state of other. Both lists must use the same codec.
func (*MoveRGA[T]) Move ¶ added in v1.0.25
Move relocates count elements beginning at from. to is an offset in the visible list after the selected range has been removed, so Move(2, 1, 0) moves the third item to the front. A single operation tag and rank preserve the moved block's order under concurrent delivery.
Besides the selected range, a move rewrites the visible suffix that followed it. RGA insertions commonly form a parent chain; only moving the selected nodes would otherwise pull descendants from that suffix along with them. Reattaching the suffix as a chain at the former predecessor performs the required sequence splice while retaining every element's immutable identity.
func (*MoveRGA[T]) Positions ¶ added in v1.0.25
Positions returns permanent identities in current visible order.
func (*MoveRGA[T]) SnapshotCurrentState ¶ added in v1.0.25
func (*MoveRGA[T]) State ¶ added in v1.0.25
func (r *MoveRGA[T]) State() crdt.StateSnapshot
State reports immutable diagnostic metadata only.
func (*MoveRGA[T]) UnmarshalBinary ¶ added in v1.0.25
func (*MoveRGA[T]) UnmarshalBinaryWithLimits ¶ added in v1.0.25
func (r *MoveRGA[T]) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
type Options ¶
type Options struct {
MaxNodes int
MaxTombstones int
MaxPendingNodes int
MaxPendingBytes int
MaxValueBytes int
}
Options bounds retained list state. Applications receiving untrusted peers should set a group-appropriate bound rather than rely on process memory.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns conservative per-list retention limits.
type RGA ¶
type RGA[T any] struct { // contains filtered or unexported fields }
RGA is a generic collaborative list. Deletion retains a structural tombstone: an element deleted before its insertion arrives remains hidden when that insertion is eventually delivered.
func New ¶
func New[T any](replicaID string, codec ElementCodec[T]) (*RGA[T], error)
New constructs a list with default retention limits.
func NewFromClock ¶
NewFromClock restores a replica clock with default list limits.
func NewFromClockWithOptions ¶
func NewFromClockWithOptions[T any](state clock.State, codec ElementCodec[T], options Options) (*RGA[T], error)
NewFromClockWithOptions restores a replica clock. Persist its state atomically with a complete list snapshot before reusing a replica ID.
func NewFromSnapshot ¶
NewFromSnapshot restores a complete HLC-backed list snapshot.
func NewFromSnapshotWithOptions ¶
func NewFromSnapshotWithOptions[T any](saved snapshot.Snapshot, codec ElementCodec[T], options Options, limits frame.DecoderLimits) (*RGA[T], error)
NewFromSnapshotWithOptions restores a complete snapshot within caller retention and decoder limits.
func NewWithOptions ¶
func NewWithOptions[T any](replicaID string, codec ElementCodec[T], options Options) (*RGA[T], error)
NewWithOptions constructs a list with explicit retained-state limits.
func (*RGA[T]) ApplyDelta ¶
ApplyDelta atomically integrates a locally created or decoded delta.
func (*RGA[T]) ClockState ¶
ClockState returns the HLC state that must be persisted with a snapshot.
func (*RGA[T]) CompactTombstones ¶
CompactTombstones removes exactly requested tombstoned leaves. For replicated state, the caller must first obtain exact authenticated acknowledgements for one epoch, save a post-compaction checkpoint, and retire old deltas. tombstonegc.SimpleCollector may call it only for its documented local-only lifecycle. Any retained child or unresolved dependent blocks the entire request.
func (*RGA[T]) Insert ¶
Insert inserts values before visible element offset. One value becomes one RGA position, even when its canonical encoding is large or multi-byte.
func (*RGA[T]) MarshalBinary ¶
MarshalBinary returns a canonical complete list state frame. Pending out-of-order dependencies are deliberately not serializable as a snapshot.
func (*RGA[T]) MarshalBinaryWithClockState ¶
MarshalBinaryWithClockState returns one complete frame and the HLC state that must be durably stored with it.
func (*RGA[T]) MarshalBinaryWithLimits ¶
func (r *RGA[T]) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
MarshalBinaryWithLimits returns a canonical complete list state constrained by caller-selected transport limits.
func (*RGA[T]) MissingParents ¶
MissingParents returns unique unresolved parent IDs in canonical order.
func (*RGA[T]) PendingCount ¶
PendingCount returns unresolved out-of-order nodes. Any non-zero value prevents a complete state snapshot from being emitted.
func (*RGA[T]) SnapshotCurrentState ¶
SnapshotCurrentState creates a complete HLC-backed list snapshot.
func (*RGA[T]) State ¶
func (r *RGA[T]) State() crdt.StateSnapshot
State returns an immutable diagnostic summary that contains no values, positions, clocks, or frame bytes.
func (*RGA[T]) TombstoneTags ¶
TombstoneTags returns every retained deletion identity in canonical order. It is an exact-acknowledgement input, never proof of safe collection.
func (*RGA[T]) UnmarshalBinary ¶
UnmarshalBinary validates a full list state before atomically replacing r.
func (*RGA[T]) UnmarshalBinaryWithLimits ¶
func (r *RGA[T]) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
UnmarshalBinaryWithLimits validates a bounded full state before atomically replacing r. It refuses incomplete states and non-canonical values.