Documentation
¶
Overview ¶
Package crdt defines the common types and contracts used by the CRDT primitives in this module.
Index ¶
Constants ¶
const ( TypeIDGCounterState uint64 = 1 TypeIDORSetState uint64 = 2 TypeIDGCounterDelta uint64 = 3 TypeIDORSetDelta uint64 = 4 TypeIDPNCounterState uint64 = 5 TypeIDPNCounterDelta uint64 = 6 TypeIDLWWSetState uint64 = 7 TypeIDLWWSetDelta uint64 = 8 TypeIDLWWMapState uint64 = 9 TypeIDLWWMapDelta uint64 = 10 TypeIDRGAState uint64 = 11 TypeIDRGADelta uint64 = 12 TypeIDGSetState uint64 = 13 TypeIDGSetDelta uint64 = 14 TypeIDMVRegisterState uint64 = 15 TypeIDMVRegisterDelta uint64 = 16 TypeIDORTreeState uint64 = 17 TypeIDORTreeDelta uint64 = 18 )
Stable frame type assignments. Values are part of the v1 wire contract and must never be reused for a different payload shape.
Variables ¶
This section is empty.
Functions ¶
func IsExperimentalFrame ¶
IsExperimentalFrame reports whether typeID belongs to an implemented experimental protocol. Reserved or unknown type IDs return false.
func MarshalDiagnosticJSON ¶ added in v1.0.5
func MarshalDiagnosticJSON(summary StateSnapshot) ([]byte, error)
MarshalDiagnosticJSON encodes a caller-provided diagnostic summary. It is useful for CRDT delta log views that use the same schema as StateSnapshot. The summary must not contain application values or replication state.
func MarshalStateJSON ¶ added in v1.0.5
func MarshalStateJSON(value StateReporter) ([]byte, error)
MarshalStateJSON returns a compact JSON diagnostic summary for value.
This helper is intended for structured logs and human inspection. It does not encode CRDT state, deltas, or opaque application values, so its output cannot reconstruct a replica and must not be used as a wire format.
Types ¶
type CRDT ¶
type CRDT[T any] interface { Merge(other T) error State() StateSnapshot }
CRDT is the common contract for state-based CRDTs.
For every concrete state type T, Merge must be commutative, associative, and idempotent. If Merge returns an error, it must leave the receiver unchanged.
type DeltaCapable ¶
DeltaCapable is implemented by a state-based CRDT that accepts a concrete, type-safe delta D. Delta mutators return D directly; the library does not maintain an implicitly acknowledged delta buffer.
type FrameType ¶
FrameType describes one fully implemented framed CRDT protocol. The type table is deliberately closed: reserving an ID alone must not make a payload eligible for batching or recovery before its concrete codec is available.
func FrameTypeForDelta ¶
FrameTypeForDelta returns the supported protocol associated with deltaID.
func FrameTypeForState ¶
FrameTypeForState returns the supported protocol associated with stateID.
type ProtocolPolicy ¶
type ProtocolPolicy struct {
// AllowExperimental includes the framed LWW-Map, RGA, and OR-Tree protocols.
// Keep it false until the replication group has accepted their experimental
// API and tombstone-retention lifecycle.
AllowExperimental bool
}
ProtocolPolicy controls which implemented frame types one replication group advertises. It is a local, immutable-by-convention value for connection setup; it does not install a process-wide switch or permit runtime protocol registration.
Peers must compare FrameTypes before sending state or deltas. A matching TypeID remains necessary but is not sufficient: applications still own authentication, authorization, limits, and decoder selection.
func (ProtocolPolicy) FrameTypes ¶
func (p ProtocolPolicy) FrameTypes() []FrameType
FrameTypes returns a copy of every protocol enabled by p. The returned slice is stable in type-ID order and safe for callers to advertise or modify.
func (ProtocolPolicy) SupportsFrame ¶
func (p ProtocolPolicy) SupportsFrame(typeID uint64) bool
SupportsFrame reports whether typeID is both implemented by this module and enabled by p. It applies to either a state or delta frame type ID.
type StateReporter ¶ added in v1.0.5
type StateReporter interface {
State() StateSnapshot
}
StateReporter exposes an immutable CRDT diagnostic summary.
It intentionally excludes application values, mutation tags, clock state, and framed bytes. Use it for observability only, never to persist or replicate a CRDT.
type StateSnapshot ¶
type StateSnapshot struct {
Type string `json:"type"`
ReplicaID string `json:"replica_id"`
ElementCount int `json:"element_count"`
TombstoneCount int `json:"tombstone_count"`
}
StateSnapshot is an immutable summary of a CRDT state for diagnostics and observability. It never exposes mutable internal data.
type Tag ¶
Tag uniquely identifies a CRDT mutation. WallTime, Logical, and ReplicaID are compared in that order. ReplicaID must be globally unique among live logical replicas; callers that reuse an ID across restarts must persist the last emitted clock state.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clock implements a hybrid logical clock for CRDT mutation tags.
|
Package clock implements a hybrid logical clock for CRDT mutation tags. |
|
cmd
|
|
|
crdt-analyze
command
Command crdt-analyze reports bounded, transport-safe metadata about one canonical CRDT frame.
|
Command crdt-analyze reports bounded, transport-safe metadata about one canonical CRDT frame. |
|
crdt-sync-probe
command
Command crdt-sync-probe exercises CRDT delta delivery over real HTTP links.
|
Command crdt-sync-probe exercises CRDT delta delivery over real HTTP links. |
|
Package counter implements counter CRDT primitives.
|
Package counter implements counter CRDT primitives. |
|
Package delta provides bounded batching and coalescing for encoded CRDT deltas.
|
Package delta provides bounded batching and coalescing for encoded CRDT deltas. |
|
durable
module
|
|
|
Package encoding provides canonical, bounded binary frames for CRDT state.
|
Package encoding provides canonical, bounded binary frames for CRDT state. |
|
examples
|
|
|
collaborative-board
command
Command collaborative-board demonstrates how an application can use CRDT deltas for a field-maintenance workboard while replicas are disconnected.
|
Command collaborative-board demonstrates how an application can use CRDT deltas for a field-maintenance workboard while replicas are disconnected. |
|
Package lww implements last-write-wins CRDT collections.
|
Package lww implements last-write-wins CRDT collections. |
|
Package merkle provides deterministic state digests for anti-entropy.
|
Package merkle provides deterministic state digests for anti-entropy. |
|
providers
|
|
|
internal/sqlrelay
module
|
|
|
sqlite
module
|
|
|
Package register implements state-based register CRDTs.
|
Package register implements state-based register CRDTs. |
|
Package replica defines the transport-independent boundary around one framed CRDT replication group.
|
Package replica defines the transport-independent boundary around one framed CRDT replication group. |
|
Package set implements set CRDT primitives.
|
Package set implements set CRDT primitives. |
|
Package snapshot defines immutable, versioned CRDT state snapshots and bounded recovery plans.
|
Package snapshot defines immutable, versioned CRDT state snapshots and bounded recovery plans. |
|
telemetry
module
|
|
|
Package text implements a state-based Replicated Growable Array (RGA).
|
Package text implements a state-based Replicated Growable Array (RGA). |
|
Package tombstonegc coordinates safe, automatic OR-Set tombstone collection.
|
Package tombstonegc coordinates safe, automatic OR-Set tombstone collection. |
|
Package tree implements an observed-remove rooted tree CRDT.
|
Package tree implements an observed-remove rooted tree CRDT. |