aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-11-07 20:29:25 +0100
committerAlex Auvolat <alex@adnab.me>2022-11-07 20:29:25 +0100
commitfd5bc142b553d716c8265d83cff0bb633aa09e6b (patch)
treeec54e33128d777a776f14231367ed40393ecabe7
parentea5afc251106b3f6e2d07f942ba1f88abeef8765 (diff)
downloadgarage-fd5bc142b553d716c8265d83cff0bb633aa09e6b.tar.gz
garage-fd5bc142b553d716c8265d83cff0bb633aa09e6b.zip
Ensure .sort() is called before counting unique items
-rw-r--r--src/rpc/layout.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/rpc/layout.rs b/src/rpc/layout.rs
index 95f69dc8..15765662 100644
--- a/src/rpc/layout.rs
+++ b/src/rpc/layout.rs
@@ -355,17 +355,22 @@ To know the correct value of the new layout version, invoke `garage layout show`
// Check that every partition is associated to distinct nodes
let rf = self.replication_factor;
for p in 0..(1 << PARTITION_BITS) {
- let nodes_of_p = self.ring_assignation_data[rf * p..rf * (p + 1)].to_vec();
+ let mut nodes_of_p = self.ring_assignation_data[rf * p..rf * (p + 1)].to_vec();
+ nodes_of_p.sort();
if nodes_of_p.iter().unique().count() != rf {
return false;
}
// Check that every partition is spread over at least zone_redundancy zones.
- let zones_of_p = nodes_of_p.iter().map(|n| {
- self.get_node_zone(&self.node_id_vec[*n as usize])
- .expect("Zone not found.")
- });
+ let mut zones_of_p = nodes_of_p
+ .iter()
+ .map(|n| {
+ self.get_node_zone(&self.node_id_vec[*n as usize])
+ .expect("Zone not found.")
+ })
+ .collect::<Vec<_>>();
+ zones_of_p.sort();
let redundancy = self.parameters.zone_redundancy;
- if zones_of_p.unique().count() < redundancy {
+ if zones_of_p.iter().unique().count() < redundancy {
return false;
}
}
@@ -378,9 +383,7 @@ To know the correct value of the new layout version, invoke `garage layout show`
for (n, usage) in node_usage.iter().enumerate() {
if *usage > 0 {
let uuid = self.node_id_vec[n];
- if usage * self.partition_size
- > self.get_node_capacity(&uuid).expect("Critical Error")
- {
+ if usage * self.partition_size > self.get_node_capacity(&uuid).unwrap() {
return false;
}
}
@@ -389,7 +392,7 @@ To know the correct value of the new layout version, invoke `garage layout show`
// Check that the partition size stored is the one computed by the asignation
// algorithm.
let cl2 = self.clone();
- let (_, zone_to_id) = cl2.generate_nongateway_zone_ids().expect("Critical Error");
+ let (_, zone_to_id) = cl2.generate_nongateway_zone_ids().unwrap();
match cl2.compute_optimal_partition_size(&zone_to_id) {
Ok(s) if s != self.partition_size => return false,
Err(_) => return false,
@@ -484,12 +487,7 @@ impl ClusterLayout {
}
// We display statistics of the computation
- msg.append(&mut self.output_stat(
- &gflow,
- &old_assignation_opt,
- &zone_to_id,
- &id_to_zone,
- )?);
+ msg.extend(self.output_stat(&gflow, &old_assignation_opt, &zone_to_id, &id_to_zone)?);
msg.push("".to_string());
// We update the layout structure