aboutsummaryrefslogtreecommitdiff
path: root/src/membership.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-17 21:08:43 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-17 21:08:43 +0200
commitace07da7c17d4eeec8b29b9eea2ae84c0d76088c (patch)
treef21e5213eeab8fafd1ebaf2b107d78384aefd79d /src/membership.rs
parent40c48e6a590c887586664957da2dca0f368cdcb2 (diff)
downloadgarage-ace07da7c17d4eeec8b29b9eea2ae84c0d76088c.tar.gz
garage-ace07da7c17d4eeec8b29b9eea2ae84c0d76088c.zip
Fix walk_ring_from
Diffstat (limited to 'src/membership.rs')
-rw-r--r--src/membership.rs18
1 files changed, 10 insertions, 8 deletions
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<UUID> {
+ if n >= self.config.members.len() {
+ return self.config.members.keys().cloned().collect::<Vec<_>>();
+ }
+
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());
}
}