Documentation
¶
Overview ¶
Package eventfulranges is an event-sourced CRDT for real-valued ranges.
Operations (add or remove a range) are appended to an append-only log and merged under a conflict-resolution strategy such as last-write-wins or additive-wins. The default backend is a JSON Lines file, which needs no network; a KurrentDB backend is available behind the kurrent build tag.
Example ¶
package main
import (
"context"
"fmt"
"os"
"github.com/d-led/eventfulranges"
"github.com/d-led/eventfulranges/strategy"
)
func main() {
ctx := context.Background()
dir, err := os.MkdirTemp("", "eventfulranges-example")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(dir) }()
rs, err := eventfulranges.Open(ctx, dir, strategy.LWW)
if err != nil {
panic(err)
}
_, _ = rs.Add(ctx, 1, 5) // [1,5]
_, _ = rs.Add(ctx, 3, 7) // merges to [1,7]
_, _ = rs.Remove(ctx, 2, 3) // cuts a hole
for _, iv := range rs.Ranges() {
fmt.Println(iv)
}
}
Output: [1,2) (3,7]
Index ¶
- type BoxOption
- type BoxSet
- func (b *BoxSet) Add(ctx context.Context, min, max []float64) (sop.Op, error)
- func (b *BoxSet) AddWithMeta(ctx context.Context, min, max []float64, m json.RawMessage) (sop.Op, error)
- func (b *BoxSet) Apply(ctx context.Context, o sop.Op) error
- func (b *BoxSet) ApplyAll(ctx context.Context, ops []sop.Op) error
- func (b *BoxSet) Boxes() []space.Box
- func (b *BoxSet) Compact(ctx context.Context) error
- func (b *BoxSet) Contains(p []float64) bool
- func (b *BoxSet) Crossed(p space.Path) []space.Box
- func (b *BoxSet) Ops() []sop.Op
- func (b *BoxSet) Overlaps(box space.Box) bool
- func (b *BoxSet) Remove(ctx context.Context, min, max []float64) (sop.Op, error)
- func (b *BoxSet) RemoveWithMeta(ctx context.Context, min, max []float64, m json.RawMessage) (sop.Op, error)
- func (b *BoxSet) Retract(ctx context.Context, refID string) (sop.Op, error)
- func (b *BoxSet) RetractWithID(ctx context.Context, id, refID string) (sop.Op, error)
- func (b *BoxSet) Snapshot(ctx context.Context) error
- func (b *BoxSet) Traverse(p space.Path) []space.PathSegment
- type Option
- type RangeSet
- func (r *RangeSet) Add(ctx context.Context, start, end float64) (op.Op, error)
- func (r *RangeSet) AddWithBounds(ctx context.Context, start, end float64, sb, eb interval.Bound) (op.Op, error)
- func (r *RangeSet) Apply(ctx context.Context, o op.Op) error
- func (r *RangeSet) ApplyAll(ctx context.Context, ops []op.Op) error
- func (r *RangeSet) Compact(ctx context.Context) error
- func (r *RangeSet) Contains(x float64) bool
- func (r *RangeSet) Ops() []op.Op
- func (r *RangeSet) Overlaps(iv interval.Interval) bool
- func (r *RangeSet) Ranges() []interval.Interval
- func (r *RangeSet) Remove(ctx context.Context, start, end float64) (op.Op, error)
- func (r *RangeSet) RemoveWithBounds(ctx context.Context, start, end float64, sb, eb interval.Bound) (op.Op, error)
- func (r *RangeSet) Snapshot(ctx context.Context) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoxOption ¶ added in v0.0.3
BoxOption customizes a BoxSet.
func WithBoxCanonicalizer ¶ added in v0.0.3
func WithBoxCanonicalizer(c space.Canonicalizer) BoxOption
WithBoxCanonicalizer sets the final canonicalization applied to every materialized view.
func WithBoxClock ¶ added in v0.0.3
WithBoxClock sets the clock used to stamp new box operations.
func WithBoxMetaMerge ¶ added in v0.0.3
WithBoxMetaMerge sets the join used when boxes carrying metadata merge under AdditiveWins or GrowOnly. The default is the top-level key union in the meta package.
func WithBoxSnapshotEvery ¶ added in v0.0.3
WithBoxSnapshotEvery snapshots the view every n new operations; 0 disables automatic snapshots.
type BoxSet ¶ added in v0.0.3
type BoxSet struct {
// contains filtered or unexported fields
}
BoxSet is the high-level n-dimensional API over an n-D engine.
func OpenBoxStore ¶ added in v0.0.3
func OpenBoxStore(ctx context.Context, st sstore.Log, s sstrategy.Strategy, opts ...BoxOption) (*BoxSet, error)
OpenBoxStore opens a box set backed by the given event log.
func OpenBoxes ¶ added in v0.0.3
func OpenBoxes(ctx context.Context, dir string, s sstrategy.Strategy, opts ...BoxOption) (*BoxSet, error)
OpenBoxes opens a JSON Lines-backed box set stored under dir.
func (*BoxSet) Add ¶ added in v0.0.3
Add applies an addition over the half-open box [min, max) and returns the applied op.
func (*BoxSet) AddWithMeta ¶ added in v0.0.3
func (b *BoxSet) AddWithMeta(ctx context.Context, min, max []float64, m json.RawMessage) (sop.Op, error)
AddWithMeta applies an addition over the half-open box [min, max) carrying JSON-object metadata, and returns the applied op.
func (*BoxSet) ApplyAll ¶ added in v0.0.3
ApplyAll applies a batch of operations, ignoring duplicates by ID.
func (*BoxSet) Compact ¶ added in v0.0.3
Compact rewrites the store as a snapshot of the current view, collapsing the stream to its smallest form.
func (*BoxSet) Contains ¶ added in v0.0.3
Contains reports whether the point belongs to the materialized set.
func (*BoxSet) Crossed ¶ added in v0.0.3
Crossed returns the materialized boxes the path crosses with positive length, in canonical cover order.
func (*BoxSet) Overlaps ¶ added in v0.0.3
Overlaps reports whether any materialized box shares a point with box.
func (*BoxSet) Remove ¶ added in v0.0.3
Remove applies a removal over the half-open box [min, max) and returns the applied op.
func (*BoxSet) RemoveWithMeta ¶ added in v0.0.3
func (b *BoxSet) RemoveWithMeta(ctx context.Context, min, max []float64, m json.RawMessage) (sop.Op, error)
RemoveWithMeta applies a removal over the half-open box [min, max) carrying JSON-object metadata, and returns the applied op.
func (*BoxSet) Retract ¶ added in v0.0.3
Retract cancels the operation named refID, undoing that one edit without touching any other operation. Retraction is single-level: a Retract cannot itself be retracted.
func (*BoxSet) RetractWithID ¶ added in v0.0.4
RetractWithID cancels the operation named refID exactly like Retract, but records the retraction itself under id when it is non-empty. A caller that assigns its own operation identifiers can therefore acknowledge the retraction by ID, just like any other operation.
type Option ¶
Option customizes a RangeSet.
func WithSnapshotEvery ¶
WithSnapshotEvery snapshots the view every n new operations; 0 disables automatic snapshots.
type RangeSet ¶
type RangeSet struct {
// contains filtered or unexported fields
}
RangeSet is the high-level API over an engine.
func OpenStore ¶
func OpenStore(ctx context.Context, st store.Log, s strategy.Strategy, opts ...Option) (*RangeSet, error)
OpenStore opens a range set backed by the given event log. Backends that also implement store.Snapshotter get snapshotting for free; stream-only backends simply skip it.
func (*RangeSet) AddWithBounds ¶
func (r *RangeSet) AddWithBounds(ctx context.Context, start, end float64, sb, eb interval.Bound) (op.Op, error)
AddWithBounds applies an addition with explicit boundary inclusivity.
func (*RangeSet) ApplyAll ¶
ApplyAll applies a batch of operations, ignoring duplicates by ID. It is the workhorse of anti-entropy: a replica can hand another replica's Ops() result straight back to ApplyAll.
func (*RangeSet) Compact ¶ added in v0.0.3
Compact rewrites the store as a snapshot of the current view, collapsing the stream to its smallest form.
func (*RangeSet) Overlaps ¶
Overlaps reports whether any materialized interval shares a point with iv.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clock provides timestamps that order range operations across replicas.
|
Package clock provides timestamps that order range operations across replicas. |
|
Package engine applies range operations to an append-only event log and materializes the converged view under a chosen conflict-resolution strategy.
|
Package engine applies range operations to an append-only event log and materializes the converged view under a chosen conflict-resolution strategy. |
|
Package interval defines open and closed real-valued intervals together with canonical set operations over them.
|
Package interval defines open and closed real-valued intervals together with canonical set operations over them. |
|
Package meta merges JSON-object metadata attached to ranges.
|
Package meta merges JSON-object metadata attached to ranges. |
|
Package op defines the range operations that make up the CRDT event log.
|
Package op defines the range operations that make up the CRDT event log. |
|
Package space generalizes the one-dimensional interval set to n dimensions.
|
Package space generalizes the one-dimensional interval set to n dimensions. |
|
engine
Package engine applies box operations to an append-only event log and materializes the converged n-dimensional view under a chosen conflict-resolution strategy.
|
Package engine applies box operations to an append-only event log and materializes the converged n-dimensional view under a chosen conflict-resolution strategy. |
|
op
Package op defines the box operations that make up the n-dimensional CRDT event log.
|
Package op defines the box operations that make up the n-dimensional CRDT event log. |
|
store
Package store defines the append-only event log that backs an n-dimensional engine.
|
Package store defines the append-only event log that backs an n-dimensional engine. |
|
store/jsonl
Package jsonl persists the n-dimensional event log as a single JSON Lines stream: operation records are appended in order and materialized snapshots are embedded as records in the same file, so the stream can be compacted.
|
Package jsonl persists the n-dimensional event log as a single JSON Lines stream: operation records are appended in order and materialized snapshots are embedded as records in the same file, so the stream can be compacted. |
|
store/memory
Package memory provides an in-memory EventStore for tests and single-process use.
|
Package memory provides an in-memory EventStore for tests and single-process use. |
|
strategy
Package strategy materializes a set of box operations into a canonical cover of boxes under a chosen conflict-resolution policy.
|
Package strategy materializes a set of box operations into a canonical cover of boxes under a chosen conflict-resolution policy. |
|
Package store defines the append-only event log that backs an engine.
|
Package store defines the append-only event log that backs an engine. |
|
jsonl
Package jsonl persists the event log as a single JSON Lines stream: operation records are appended in order and materialized snapshots are embedded as records in the same file, so the stream can be compacted.
|
Package jsonl persists the event log as a single JSON Lines stream: operation records are appended in order and materialized snapshots are embedded as records in the same file, so the stream can be compacted. |
|
kurrent
Package kurrent implements an EventStore backed by KurrentDB.
|
Package kurrent implements an EventStore backed by KurrentDB. |
|
memory
Package memory provides an in-memory EventStore for tests and single-process use.
|
Package memory provides an in-memory EventStore for tests and single-process use. |
|
Package strategy materializes a set of range operations into canonical non-overlapping intervals under a chosen conflict-resolution policy.
|
Package strategy materializes a set of range operations into canonical non-overlapping intervals under a chosen conflict-resolution policy. |
