Documentation ¶
Overview ¶
Package vvmap is an implementation of a delta-based CRDT map as written about in "∆-CRDTs: Making δ-CRDTs Delta-Based" (http://nova-lincs.di.fct.unl.pt/system/publication_files/files/000/000/666/original/a12-van_der_linde.pdf?1483708753) and "Dotted Version Vectors: Logical Clocks for Optimistic Replication" (https://arxiv.org/pdf/1011.5808.pdf).
Example ¶
aliceID := ID("alice") bobID := ID("bob") timID := ID("tim") lexicographicResolver := func(key string, left, right Record) bool { leftVal := left.Value.(string) rightVal := right.Value.(string) return strings.Compare(leftVal, rightVal) > 0 // choose left if lexicographically greater } alice := New(aliceID, lexicographicResolver) bob := New(bobID, lexicographicResolver) tim := New(timID, lexicographicResolver) // concurrently update everyone -- causes a conflict, should all resolve to "turkey" since // lexicographically greatest alice.Set("lunch", "turkey") bob.Set("lunch", "ham") tim.Set("lunch", "chicken") // sync alice alice.Merge(bob.Delta(alice.Version())) alice.Merge(tim.Delta(alice.Version())) // sync bob bob.Merge(alice.Delta(bob.Version())) // alice is most up-to-date so no need to sync with Tim // sync tim tim.Merge(alice.Delta(tim.Version())) fmt.Println("alice:", alice.Get("lunch")) fmt.Println("bob:", bob.Get("lunch")) fmt.Println("tim:", tim.Get("lunch"))
Output: alice: turkey bob: turkey tim: turkey
Index ¶
- type ChooseLeftConflictResolver
- type Delta
- type ID
- type Map
- func (v *Map) Delta(since VersionVector) Delta
- func (v *Map) Get(key string) interface{}
- func (v *Map) GobDecode(buf []byte) error
- func (v *Map) GobEncode() ([]byte, error)
- func (v *Map) ID() ID
- func (v *Map) Keys() []string
- func (v *Map) Merge(delta Delta)
- func (v *Map) Set(key string, value interface{})
- func (v *Map) Version() VersionVector
- type Record
- type VVDot
- type VersionVector
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChooseLeftConflictResolver ¶
ChooseLeftConflictResolver is a function which returns whether the left Record should be used to resolve the conflict. It can be assumed that left and right have the same key. This must deterministically choose the same item no matter the order.
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
Delta are the most recent records seen between since and current
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a delta based CRDT map
func New ¶
func New(id ID, resolver ChooseLeftConflictResolver) *Map
New returns a new Map with the specified ID and conflict resolver
func (*Map) Delta ¶
func (v *Map) Delta(since VersionVector) Delta
Delta generates a list of records that have not been seen by the specified version vector.
type VVDot ¶
VVDot is a version vector dot used to represent an event with the specified version from a node with SourceID
type VersionVector ¶
VersionVector vector of node versions keyed by their ID