From 5b649379a3ff509e38afa25eb7d1403fa83d0529 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 7 Mar 2024 16:07:04 +0900 Subject: [PATCH] CR comments --- ALGORITHM.md | 6 ++++-- chitchat/src/state.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ALGORITHM.md b/ALGORITHM.md index 0ddd6aa..bef4c6b 100644 --- a/ALGORITHM.md +++ b/ALGORITHM.md @@ -2,10 +2,11 @@ Chitchat relies on an extension of the Scuttlebutt reconciliation algorithm, to - Key-Value deletion - Member leaving the cluster. -For simplification, we will just discuss the replication of a single map on a cluster of n node, one which only one node can write to. +For simplification, we will just discuss the replication of a single map on a cluster of n node, on which only one node can write to. + (In scuttlebutt, each node has ownership over such a map.) -There are two kinds of update events on this map: +There are two kinds of update event on this map: - Set(K, V) - Deletion(K) @@ -34,6 +35,7 @@ node will send two parameters describing how much of the state is replicated: - `max_version`: One big difference with reliable broadcast, is that this `max version` does NOT mean that the node's state reflects all of the events earlier than `max_version`. Rather, it says that if the node were to receive all of the events within between `max_version` and $V$ then it will end up to date. The difference is subtle, but comes from an important optimization of scuttlebutt. + If a node asks for an update above $max_version = m$, and that for a given key $k$ there are two updates after $m$, there is no need to send the first one: it will eventually be overridden by the second one. - `last_gc_version`: Rather than being deleted right away, the algorithm is using a tombstone mechanism. Key entries are kept by marked as deleted. From the client point of view, everything looks like the key really has been deleted. Eventually, in order diff --git a/chitchat/src/state.rs b/chitchat/src/state.rs index 071b39d..ceb8162 100644 --- a/chitchat/src/state.rs +++ b/chitchat/src/state.rs @@ -205,8 +205,16 @@ impl NodeState { current_last_gc_version=self.last_gc_version, "resetting node"); *self = NodeState::new(node_delta.chitchat_id.clone(), self.listeners.clone()); + // The node_delta max_version whe if let Some(max_version) = node_delta.max_version { - self.max_version = max_version; + if node_delta.key_values.is_empty() { + self.max_version = max_version; + } else { + warn!( + "Received a delta with a max_version, and key_values as well. This is \ + unexpected, please report." + ); + } } // We need to reset our `last_gc_version`. self.last_gc_version = node_delta.last_gc_version;