aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-17 15:01:35 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:47:06 +0100
commit87121dce9d6e9a22bd9b65590262af5a1f481249 (patch)
treeb3b9f712dfef3d7c59afdf6cfea195b291238487
parentb1cfd16913e6957739958ef729b87c1bf3674a5d (diff)
downloadgarage-87121dce9d6e9a22bd9b65590262af5a1f481249.tar.gz
garage-87121dce9d6e9a22bd9b65590262af5a1f481249.zip
New buckets for 0.6.0: documentation and build files
-rw-r--r--Cargo.nix1
-rw-r--r--src/util/crdt/crdt.rs11
2 files changed, 12 insertions, 0 deletions
diff --git a/Cargo.nix b/Cargo.nix
index 78f2b5c0..c6c5c050 100644
--- a/Cargo.nix
+++ b/Cargo.nix
@@ -638,6 +638,7 @@ in
rand = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand."0.8.4" { inherit profileName; };
rmp_serde = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rmp-serde."0.15.5" { inherit profileName; };
serde = rustPackages."registry+https://github.com/rust-lang/crates.io-index".serde."1.0.130" { inherit profileName; };
+ serde_bytes = rustPackages."registry+https://github.com/rust-lang/crates.io-index".serde_bytes."0.11.5" { inherit profileName; };
sled = rustPackages."registry+https://github.com/rust-lang/crates.io-index".sled."0.34.7" { inherit profileName; };
structopt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".structopt."0.3.23" { inherit profileName; };
tokio = rustPackages."registry+https://github.com/rust-lang/crates.io-index".tokio."1.12.0" { inherit profileName; };
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<T> 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<T> 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<T> Crdt for Option<T>
where
T: Eq,