public final class ORSet<A> extends java.lang.Object implements ReplicatedData, ReplicatedDataSerialization, RemovedNodePruning, FastMerge
It is not implemented as in the paper A comprehensive study of Convergent and Commutative Replicated Data Types. This is more space efficient and doesn't accumulate garbage for removed elements. It is described in the paper An optimized conflict-free replicated set The implementation is inspired by the Riak DT riak_dt_orswot.
The ORSet has a version vector that is incremented when an element is added to
the set. The node -> count
pair for that increment is stored against the
element as its "birth dot". Every time the element is re-added to the set,
its "birth dot" is updated to that of the node -> count
version vector entry
resulting from the add. When an element is removed, we simply drop it, no tombstones.
When an element exists in replica A and not replica B, is it because A added
it and B has not yet seen that, or that B removed it and A has not yet seen that?
In this implementation we compare the dot
of the present element to the version vector
in the Set it is absent from. If the element dot is not "seen" by the Set version vector,
that means the other set has yet to see this add, and the item is in the merged
Set. If the Set version vector dominates the dot, that means the other Set has removed this
element already, and the item is not in the merged Set.
This class is immutable, i.e. "modifying" methods return a new instance.
Constructor and Description |
---|
ORSet(scala.collection.immutable.Map<A,VersionVector> elementsMap,
VersionVector vvector) |
Modifier and Type | Method and Description |
---|---|
ORSet<A> |
add(Cluster node,
A element)
Adds an element to the set
|
ORSet<A> |
add(UniqueAddress node,
A element)
INTERNAL API
|
static void |
akka$cluster$ddata$FastMerge$$ancestor_$eq(FastMerge x$1) |
static FastMerge |
akka$cluster$ddata$FastMerge$$ancestor() |
static ORSet<java.lang.Object> |
apply() |
static FastMerge |
assignAncestor(akka.cluster.ddata.ReplicatedData.T newData) |
ORSet<A> |
clear(Cluster node)
Removes all elements from the set, but keeps the history.
|
ORSet<A> |
clear(UniqueAddress node)
INTERNAL API
|
static FastMerge |
clearAncestor() |
boolean |
contains(A a) |
static <A> ORSet<A> |
create()
Java API
|
scala.collection.immutable.Set<A> |
elements()
Scala API
|
scala.collection.immutable.Map<A,VersionVector> |
elementsMap() |
static <A> ORSet<A> |
empty() |
boolean |
equals(java.lang.Object o) |
java.util.Set<A> |
getElements()
Java API
|
int |
hashCode() |
static boolean |
isAncestorOf(akka.cluster.ddata.ReplicatedData.T that) |
boolean |
isEmpty() |
ORSet<A> |
merge(ORSet<A> that)
When element is in this Set but not in that Set:
Compare the "birth dot" of the present element to the version vector in the Set it is absent from.
|
static <A> scala.collection.immutable.Map<A,VersionVector> |
mergeCommonKeys(scala.collection.immutable.Set<A> commonKeys,
ORSet<A> lhs,
ORSet<A> rhs)
INTERNAL API
|
static <A> scala.collection.immutable.Map<A,VersionVector> |
mergeDisjointKeys(scala.collection.immutable.Set<A> keys,
scala.collection.immutable.Map<A,VersionVector> elementsMap,
VersionVector vvector,
scala.collection.immutable.Map<A,VersionVector> accumulator)
INTERNAL API
|
boolean |
needPruningFrom(UniqueAddress removedNode)
Does it have any state changes from a specific node,
which has been removed from the cluster.
|
ORSet<A> |
prune(UniqueAddress removedNode,
UniqueAddress collapseInto)
When the
removed node has been removed from the cluster the state
changes from that node will be pruned by collapsing the data entries
to another node. |
ORSet<A> |
pruningCleanup(UniqueAddress removedNode)
Remove data entries from a node that has been removed from the cluster
and already been pruned.
|
ORSet<A> |
remove(Cluster node,
A element)
Removes an element from the set.
|
ORSet<A> |
remove(UniqueAddress node,
A element)
INTERNAL API
|
int |
size() |
static VersionVector |
subtractDots(VersionVector dot,
VersionVector vvector)
INTERNAL API
Subtract the
vvector from the dot . |
java.lang.String |
toString() |
static <A> scala.Option<scala.collection.immutable.Set<A>> |
unapply(ORSet<A> s)
Extract the
elements() . |
static scala.Option<scala.collection.immutable.Set<java.lang.Object>> |
unapply(ReplicatedData a)
Extract the
elements() of an ORSet . |
VersionVector |
vvector() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
merge
assignAncestor, clearAncestor, isAncestorOf
public ORSet(scala.collection.immutable.Map<A,VersionVector> elementsMap, VersionVector vvector)
public static <A> ORSet<A> empty()
public static ORSet<java.lang.Object> apply()
public static <A> ORSet<A> create()
public static <A> scala.Option<scala.collection.immutable.Set<A>> unapply(ORSet<A> s)
elements()
.s
- (undocumented)public static scala.Option<scala.collection.immutable.Set<java.lang.Object>> unapply(ReplicatedData a)
elements()
of an ORSet
.a
- (undocumented)public static VersionVector subtractDots(VersionVector dot, VersionVector vvector)
vvector
from the dot
.
What this means is that any (node, version) pair in
dot
that is <= an entry in vvector
is removed from dot
.
Example [{a, 3}, {b, 2}, {d, 14}, {g, 22}] -
[{a, 4}, {b, 1}, {c, 1}, {d, 14}, {e, 5}, {f, 2}] =
[{b, 2}, {g, 22}]dot
- (undocumented)vvector
- (undocumented)public static <A> scala.collection.immutable.Map<A,VersionVector> mergeCommonKeys(scala.collection.immutable.Set<A> commonKeys, ORSet<A> lhs, ORSet<A> rhs)
commonKeys
- (undocumented)lhs
- (undocumented)rhs
- (undocumented)merge(akka.cluster.ddata.ORSet<A>)
public static <A> scala.collection.immutable.Map<A,VersionVector> mergeDisjointKeys(scala.collection.immutable.Set<A> keys, scala.collection.immutable.Map<A,VersionVector> elementsMap, VersionVector vvector, scala.collection.immutable.Map<A,VersionVector> accumulator)
keys
- (undocumented)elementsMap
- (undocumented)vvector
- (undocumented)accumulator
- (undocumented)merge(akka.cluster.ddata.ORSet<A>)
public static FastMerge akka$cluster$ddata$FastMerge$$ancestor()
public static void akka$cluster$ddata$FastMerge$$ancestor_$eq(FastMerge x$1)
public static FastMerge assignAncestor(akka.cluster.ddata.ReplicatedData.T newData)
public static boolean isAncestorOf(akka.cluster.ddata.ReplicatedData.T that)
public static FastMerge clearAncestor()
public scala.collection.immutable.Map<A,VersionVector> elementsMap()
public VersionVector vvector()
public scala.collection.immutable.Set<A> elements()
public java.util.Set<A> getElements()
public boolean contains(A a)
public boolean isEmpty()
public int size()
public ORSet<A> add(Cluster node, A element)
node
- (undocumented)element
- (undocumented)public ORSet<A> add(UniqueAddress node, A element)
node
- (undocumented)element
- (undocumented)public ORSet<A> remove(Cluster node, A element)
node
- (undocumented)element
- (undocumented)public ORSet<A> remove(UniqueAddress node, A element)
node
- (undocumented)element
- (undocumented)public ORSet<A> clear(Cluster node)
remove(akka.cluster.Cluster, A)
for each
element, but it is more efficient.node
- (undocumented)public ORSet<A> clear(UniqueAddress node)
node
- (undocumented)public ORSet<A> merge(ORSet<A> that)
When element in both this Set and in that Set: Some dots may still need to be shed. If this Set has dots that the other Set does not have, and the other Set version vector dominates those dots, then we need to drop those dots. Keep only common dots, and dots that are not dominated by the other sides version vector
that
- (undocumented)public boolean needPruningFrom(UniqueAddress removedNode)
RemovedNodePruning
needPruningFrom
in interface RemovedNodePruning
removedNode
- (undocumented)public ORSet<A> prune(UniqueAddress removedNode, UniqueAddress collapseInto)
RemovedNodePruning
removed
node has been removed from the cluster the state
changes from that node will be pruned by collapsing the data entries
to another node.prune
in interface RemovedNodePruning
removedNode
- (undocumented)collapseInto
- (undocumented)public ORSet<A> pruningCleanup(UniqueAddress removedNode)
RemovedNodePruning
pruningCleanup
in interface RemovedNodePruning
removedNode
- (undocumented)public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object