From 87121dce9d6e9a22bd9b65590262af5a1f481249 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 17 Dec 2021 15:01:35 +0100 Subject: New buckets for 0.6.0: documentation and build files --- src/util/crdt/crdt.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util') diff --git a/src/util/crdt/crdt.rs b/src/util/crdt/crdt.rs index 2508d03b..00bb2e3b 100644 --- a/src/util/crdt/crdt.rs +++ b/src/util/crdt/crdt.rs @@ -28,6 +28,17 @@ pub trait Crdt { fn merge(&mut self, other: &Self); } +/// Option implements Crdt for any type T, even if T doesn't implement CRDT itself: when +/// different values are detected, they are always merged to None. This can be used for value +/// types which shoulnd't be merged, instead of trying to merge things when we know we don't want +/// to merge them (which is what the AutoCrdt trait is used for most of the time). This cases +/// arises very often, for example with a Lww or a LwwMap: the value type has to be a CRDT so that +/// we have a rule for what to do when timestamps aren't enough to disambiguate (in a distributed +/// system, anything can happen!), and with AutoCrdt the rule is to make an arbitrary (but +/// determinstic) choice between the two. When using an Option instead with this impl, ambiguity +/// cases are explicitely stored as None, which allows us to detect the ambiguity and handle it in +/// the way we want. (this can only work if we are happy with losing the value when an ambiguity +/// arises) impl Crdt for Option where T: Eq, -- cgit v1.2.3