From ace07da7c17d4eeec8b29b9eea2ae84c0d76088c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 17 Apr 2020 21:08:43 +0200 Subject: [PATCH] Fix walk_ring_from --- src/block.rs | 2 +- src/membership.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/block.rs b/src/block.rs index 200b4201..a0701b97 100644 --- a/src/block.rs +++ b/src/block.rs @@ -86,7 +86,7 @@ impl BlockManager { Ok(f) => f, Err(e) => { // Not found but maybe we should have had it ?? - self.put_to_resync(hash, DEFAULT_TIMEOUT.as_millis() as u64)?; + self.put_to_resync(hash, 0)?; return Err(Into::into(e)); } }; diff --git a/src/membership.rs b/src/membership.rs index b49607b7..6d758c59 100644 --- a/src/membership.rs +++ b/src/membership.rs @@ -158,21 +158,23 @@ impl Ring { } pub fn walk_ring_from_pos(&self, start: usize, n: usize) -> Vec { + if n >= self.config.members.len() { + return self.config.members.keys().cloned().collect::>(); + } + let mut ret = vec![]; let mut datacenters = vec![]; - for delta in 0..self.ring.len() { - if ret.len() == n { - break; - } - + let mut delta = 0; + while ret.len() < n { let i = (start + delta) % self.ring.len(); + delta += 1; - if datacenters.len() == self.n_datacenters && !ret.contains(&self.ring[i].node) { - ret.push(self.ring[i].node.clone()); - } else if !datacenters.contains(&self.ring[i].datacenter) { + if !datacenters.contains(&self.ring[i].datacenter) { ret.push(self.ring[i].node.clone()); datacenters.push(self.ring[i].datacenter); + } else if datacenters.len() == self.n_datacenters && !ret.contains(&self.ring[i].node) { + ret.push(self.ring[i].node.clone()); } }