aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout/version.rs
diff options
context:
space:
mode:
authorBaptiste Jonglez <git@bitsofnetworks.org>2025-01-26 20:40:02 +0100
committerBaptiste Jonglez <git@bitsofnetworks.org>2025-01-27 19:33:57 +0100
commit6d798c640f523c0eb1653be9c7d89114a75b3fc3 (patch)
tree745a824c35c04344a034cded8c662d5f26b60f29 /src/rpc/layout/version.rs
parentd4e3e609209eb52d820338daf628df7cf09881ab (diff)
downloadgarage-6d798c640f523c0eb1653be9c7d89114a75b3fc3.tar.gz
garage-6d798c640f523c0eb1653be9c7d89114a75b3fc3.zip
WIP: fix crash in layout computation when changing all nodes of a zone to gateway mode
This change is probably not a proper fix, somebody with more expertise on this code should look at it. Here is how to reproduce the crash: - start with a layout with two zones - move all nodes of a zone to gateway mode: `garage layout assign fea54bcc081f318 -g` - `garage layout show` will panic with a backtrace Fortunately, the crash is only on the RPC client side, not on the Garage server itself, and `garage layout revert` still works to go back to the previous state. As far as I can tell, this bug is present since Garage 0.9.0 which includes the new layout assignation algorithm: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/296
Diffstat (limited to 'src/rpc/layout/version.rs')
-rw-r--r--src/rpc/layout/version.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/rpc/layout/version.rs b/src/rpc/layout/version.rs
index a569c7c6..b7902898 100644
--- a/src/rpc/layout/version.rs
+++ b/src/rpc/layout/version.rs
@@ -650,8 +650,11 @@ impl LayoutVersion {
let mut cost = CostFunction::new();
for (p, assoc_p) in prev_assign.iter().enumerate() {
for n in assoc_p.iter() {
- let node_zone = zone_to_id[self.expect_get_node_zone(&self.node_id_vec[*n])];
- cost.insert((Vertex::PZ(p, node_zone), Vertex::N(*n)), -1);
+ if let Some(&node_zone) =
+ zone_to_id.get(self.expect_get_node_zone(&self.node_id_vec[*n]))
+ {
+ cost.insert((Vertex::PZ(p, node_zone), Vertex::N(*n)), -1);
+ }
}
}
@@ -751,8 +754,11 @@ impl LayoutVersion {
if let Some(prev_assign) = prev_assign_opt {
let mut old_zones_of_p = Vec::<usize>::new();
for n in prev_assign[p].iter() {
- old_zones_of_p
- .push(zone_to_id[self.expect_get_node_zone(&self.node_id_vec[*n])]);
+ if let Some(&zone_id) =
+ zone_to_id.get(self.expect_get_node_zone(&self.node_id_vec[*n]))
+ {
+ old_zones_of_p.push(zone_id);
+ }
}
if !old_zones_of_p.contains(&z) {
new_partitions_zone[z] += 1;