Documentation
¶
Overview ¶
Package tree implements an observed-remove rooted tree CRDT.
Index ¶
- Constants
- Variables
- func StableFrameType() crdt.FrameType
- type Delta
- type Node
- type NodeID
- type ORTree
- func New(replicaID string) (*ORTree, error)
- func NewFromClock(state clock.State) (*ORTree, error)
- func NewFromClockWithOptions(state clock.State, options Options) (*ORTree, error)
- func NewFromSnapshot(saved snapshot.Snapshot) (*ORTree, error)
- func NewFromSnapshotWithOptions(saved snapshot.Snapshot, options Options) (*ORTree, error)
- func NewFromSnapshotWithOptionsAndLimits(saved snapshot.Snapshot, options Options, limits frame.DecoderLimits) (*ORTree, error)
- func NewWithOptions(replicaID string, options Options) (*ORTree, error)
- func (t *ORTree) Add(parent NodeID, value []byte) (NodeID, Delta, error)
- func (t *ORTree) ApplyDelta(delta Delta) error
- func (t *ORTree) ClockState() clock.State
- func (t *ORTree) CompactEligibleTombstones(tags []NodeID) (int, error)
- func (t *ORTree) CompactTombstones(tags []NodeID) (int, error)
- func (t *ORTree) MarshalBinary() ([]byte, error)
- func (t *ORTree) MarshalBinaryWithClockState() ([]byte, clock.State, error)
- func (t *ORTree) MarshalBinaryWithClockStateAndLimits(limits frame.DecoderLimits) ([]byte, clock.State, error)
- func (t *ORTree) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
- func (t *ORTree) MarshalJSON() ([]byte, error)
- func (t *ORTree) Merge(other *ORTree) error
- func (t *ORTree) Nodes() []Node
- func (t *ORTree) Remove(id NodeID) (Delta, error)
- func (t *ORTree) SnapshotCurrentState() (snapshot.Snapshot, error)
- func (t *ORTree) SnapshotCurrentStateWithLimits(limits frame.DecoderLimits) (snapshot.Snapshot, error)
- func (t *ORTree) State() crdt.StateSnapshot
- func (t *ORTree) TombstoneTags() []NodeID
- func (t *ORTree) UnmarshalBinary(data []byte) error
- func (t *ORTree) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
- type Options
Constants ¶
const SemanticsVersion uint64 = crdt.SemanticsVersionORTree
SemanticsVersion is the immutable observed-remove tree v1 contract. It must match the value negotiated in a replica manifest.
Variables ¶
var ( ErrInvalidReplicaID = errors.New("tree: invalid replica ID") ErrNilTree = errors.New("tree: nil OR-Tree") ErrUnknownParent = errors.New("tree: unknown live parent") ErrUnknownNode = errors.New("tree: unknown live node") ErrInvalidDelta = errors.New("tree: invalid delta") ErrIncompleteState = errors.New("tree: incomplete OR-Tree state") ErrNodeConflict = errors.New("tree: conflicting node identity") ErrResourceLimit = errors.New("tree: OR-Tree resource limit exceeded") ErrUnsafeCompaction = errors.New("tree: unsafe OR-Tree tombstone compaction") )
Functions ¶
func StableFrameType ¶ added in v1.0.24
StableFrameType returns the stable observed-remove tree state/delta pair. Tree v1 supports immutable parent links with add and observed-remove only; a future move protocol requires a distinct frame pair and semantic version.
Types ¶
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
func UnmarshalDelta ¶
func UnmarshalDeltaWithLimits ¶
func UnmarshalDeltaWithLimits(data []byte, limits frame.DecoderLimits) (Delta, error)
func (Delta) MarshalBinary ¶
func (Delta) MarshalBinaryWithLimits ¶ added in v1.0.24
func (d Delta) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
MarshalBinaryWithLimits returns a deterministic OR-Tree delta while enforcing caller-selected frame limits.
func (Delta) MarshalJSON ¶ added in v1.0.5
MarshalJSON returns a diagnostic summary for structured logs. It omits node values, identities, tombstone identities, and clock state.
type ORTree ¶
type ORTree struct {
// contains filtered or unexported fields
}
ORTree supports add and observed-remove. Moving a node is deliberately not an in-place operation: remove it and add a new instance under the new parent.
func NewFromClockWithOptions ¶ added in v1.0.10
NewFromClockWithOptions restores an OR-Tree clock with explicit retained-state limits. Persist the clock atomically with a complete state before reusing its replica ID.
func NewFromSnapshotWithOptions ¶ added in v1.0.10
NewFromSnapshotWithOptions restores an OR-Tree snapshot while retaining the application's local resource limits. A snapshot is not allowed to widen the receiver's memory budget.
func NewFromSnapshotWithOptionsAndLimits ¶ added in v1.0.24
func NewFromSnapshotWithOptionsAndLimits(saved snapshot.Snapshot, options Options, limits frame.DecoderLimits) (*ORTree, error)
NewFromSnapshotWithOptionsAndLimits restores an OR-Tree snapshot under the caller's retained-state and decoder limits. A snapshot never widens either budget on the recovering replica.
func NewWithOptions ¶ added in v1.0.10
NewWithOptions constructs an OR-Tree with explicit retained-state limits.
func (*ORTree) ApplyDelta ¶
func (*ORTree) ClockState ¶
func (*ORTree) CompactEligibleTombstones ¶ added in v1.0.24
CompactEligibleTombstones makes best-effort structural progress through an exact-acknowledged tombstone batch. It removes deleted descendants before their deleted ancestors, so an entirely deleted tree branch can compact in one call. A retained child that is not part of the batch remains a structural anchor and prevents its parent from being removed.
For replicated state, callers must first authenticate exact acknowledgements for the current membership epoch, durably persist the post-compaction checkpoint, and retire old-epoch frames. tombstonegc.SimpleCollector may use this structural operation only for its documented local-only lifecycle.
func (*ORTree) CompactTombstones ¶ added in v1.0.10
CompactTombstones removes exactly the requested tombstoned leaf nodes. For replicated state, call it only after the current membership epoch has durably recorded exact acknowledgements, a post-compaction checkpoint, and retirement of old deltas. tombstonegc.SimpleCollector may call it only for its documented local-only lifecycle. Any known child makes a deleted node a structural anchor, so the operation is all-or-nothing for that request.
func (*ORTree) MarshalBinary ¶
MarshalBinary returns a deterministic, bounded framed OR-Tree state.
func (*ORTree) MarshalBinaryWithClockState ¶
func (*ORTree) MarshalBinaryWithClockStateAndLimits ¶ added in v1.0.24
func (t *ORTree) MarshalBinaryWithClockStateAndLimits(limits frame.DecoderLimits) ([]byte, clock.State, error)
MarshalBinaryWithClockStateAndLimits returns a complete framed state and the HLC state that must be persisted atomically before reusing the replica ID.
func (*ORTree) MarshalBinaryWithLimits ¶ added in v1.0.24
func (t *ORTree) MarshalBinaryWithLimits(limits frame.DecoderLimits) ([]byte, error)
MarshalBinaryWithLimits returns a deterministic complete OR-Tree state while enforcing caller-selected frame limits.
func (*ORTree) MarshalJSON ¶ added in v1.0.5
MarshalJSON returns a diagnostic summary for structured logs. It omits node values, identities, tombstone identities, and clock state.
func (*ORTree) SnapshotCurrentState ¶
func (*ORTree) SnapshotCurrentStateWithLimits ¶ added in v1.0.24
func (t *ORTree) SnapshotCurrentStateWithLimits(limits frame.DecoderLimits) (snapshot.Snapshot, error)
SnapshotCurrentStateWithLimits returns a validated HLC-backed snapshot while enforcing caller-selected output limits.
func (*ORTree) State ¶
func (t *ORTree) State() crdt.StateSnapshot
func (*ORTree) TombstoneTags ¶ added in v1.0.10
TombstoneTags returns every retained deletion tag in canonical order. It is an exact-acknowledgement input, not proof that a tombstone is safe to compact.
func (*ORTree) UnmarshalBinary ¶
UnmarshalBinary validates the full state before atomically replacing t. Complete states additionally require every non-root parent to be present.
func (*ORTree) UnmarshalBinaryWithLimits ¶
func (t *ORTree) UnmarshalBinaryWithLimits(data []byte, limits frame.DecoderLimits) error
type Options ¶ added in v1.0.10
Options bounds retained OR-Tree state. Applications handling untrusted peers should set limits for the replication group rather than rely on process-wide memory availability.
func DefaultOptions ¶ added in v1.0.10
func DefaultOptions() Options
DefaultOptions returns conservative retention limits that align with one default frame's element and value limits.