refactor: remove unnecessarily wrap value into a Result

this simplify code and remove some unwrap.
warning: this function's return value is unnecessarily wrapped by `Result`
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_wraps
This commit is contained in:
Gwen Lg
2026-02-02 17:34:32 +01:00
committed by Alex
parent b060a7e0f1
commit 83f8bdbacd
7 changed files with 33 additions and 35 deletions
+9 -10
View File
@@ -2,7 +2,6 @@ use std::cmp::min;
use std::collections::HashMap;
use garage_util::crdt::Crdt;
use garage_util::error::*;
use crate::layout::*;
use crate::replication_mode::ReplicationFactor;
@@ -21,14 +20,14 @@ use crate::replication_mode::ReplicationFactor;
// number of tokens by zone : (A, 4), (B,1), (C,4), (D, 4), (E, 2)
// With these parameters, the naive algo fails, whereas there is a solution:
// (A,A,C,D,E) , (A,B,C,D,D) (A,C,C,D,E)
fn check_against_naive(cl: &LayoutVersion) -> Result<bool, Error> {
fn check_against_naive(cl: &LayoutVersion) -> bool {
let over_size = cl.partition_size + 1;
let mut zone_token = HashMap::<String, usize>::new();
let (zones, zone_to_id) = cl.generate_nongateway_zone_ids()?;
let (zones, zone_to_id) = cl.generate_nongateway_zone_ids();
if zones.is_empty() {
return Ok(false);
return false;
}
for z in zones.iter() {
@@ -66,7 +65,7 @@ fn check_against_naive(cl: &LayoutVersion) -> Result<bool, Error> {
{
curr_zone += 1;
if curr_zone >= zones.len() {
return Ok(true);
return true;
}
}
id_zone_token[curr_zone] -= 1;
@@ -77,7 +76,7 @@ fn check_against_naive(cl: &LayoutVersion) -> Result<bool, Error> {
}
}
Ok(false)
false
}
fn show_msg(msg: &Message) {
@@ -127,7 +126,7 @@ fn test_assignment() {
let (mut cl, msg) = cl.apply_staged_changes(v + 1).unwrap();
show_msg(&msg);
assert_eq!(cl.check(), Ok(()));
assert!(check_against_naive(cl.current()).unwrap());
assert!(check_against_naive(cl.current()));
node_capacity_vec = vec![4000, 1000, 1000, 3000, 1000, 1000, 2000, 10000, 2000];
node_zone_vec = vec!["A", "B", "C", "C", "C", "B", "G", "H", "I"];
@@ -136,7 +135,7 @@ fn test_assignment() {
let (mut cl, msg) = cl.apply_staged_changes(v + 1).unwrap();
show_msg(&msg);
assert_eq!(cl.check(), Ok(()));
assert!(check_against_naive(cl.current()).unwrap());
assert!(check_against_naive(cl.current()));
node_capacity_vec = vec![4000, 1000, 2000, 7000, 1000, 1000, 2000, 10000, 2000];
update_layout(&mut cl, &node_capacity_vec, &node_zone_vec, 3);
@@ -144,7 +143,7 @@ fn test_assignment() {
let (mut cl, msg) = cl.apply_staged_changes(v + 1).unwrap();
show_msg(&msg);
assert_eq!(cl.check(), Ok(()));
assert!(check_against_naive(cl.current()).unwrap());
assert!(check_against_naive(cl.current()));
node_capacity_vec = vec![
4000000, 4000000, 2000000, 7000000, 1000000, 9000000, 2000000, 10000, 2000000,
@@ -154,5 +153,5 @@ fn test_assignment() {
let (cl, msg) = cl.apply_staged_changes(v + 1).unwrap();
show_msg(&msg);
assert_eq!(cl.check(), Ok(()));
assert!(check_against_naive(cl.current()).unwrap());
assert!(check_against_naive(cl.current()));
}
+4 -6
View File
@@ -271,7 +271,7 @@ impl LayoutVersion {
// 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().unwrap();
let (_, zone_to_id) = cl2.generate_nongateway_zone_ids();
match cl2.compute_optimal_partition_size(&zone_to_id, zone_redundancy) {
Ok(s) if s != self.partition_size => {
return Err(format!(
@@ -330,7 +330,7 @@ impl LayoutVersion {
// We generate for once numerical ids for the zones of non gateway nodes,
// to use them as indices in the flow graphs.
let (id_to_zone, zone_to_id) = self.generate_nongateway_zone_ids()?;
let (id_to_zone, zone_to_id) = self.generate_nongateway_zone_ids();
if self.nongateway_nodes().len() < self.replication_factor {
return Err(Error::Message(format!(
@@ -489,9 +489,7 @@ impl LayoutVersion {
/// This function generates ids for the zone of the nodes appearing in
/// `self.node_id_vec`.
pub(crate) fn generate_nongateway_zone_ids(
&self,
) -> Result<(Vec<String>, HashMap<String, usize>), Error> {
pub(crate) fn generate_nongateway_zone_ids(&self) -> (Vec<String>, HashMap<String, usize>) {
let mut id_to_zone = Vec::<String>::new();
let mut zone_to_id = HashMap::<String, usize>::new();
@@ -502,7 +500,7 @@ impl LayoutVersion {
id_to_zone.push(r.zone.clone());
}
}
Ok((id_to_zone, zone_to_id))
(id_to_zone, zone_to_id)
}
/// This function computes by dichotomy the largest realizable partition size, given