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 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) 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 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) 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 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. |
|
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 JSON Lines with a sidecar snapshot file.
|
Package jsonl persists the event log as JSON Lines with a sidecar snapshot file. |
|
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. |