block repair: simpler/more robust iterator progress calculation
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex 2023-09-11 12:28:29 +02:00
parent 9526328d38
commit ba7ac52c19

View file

@ -18,7 +18,6 @@ use garage_util::time::*;
use garage_util::tranquilizer::Tranquilizer; use garage_util::tranquilizer::Tranquilizer;
use crate::block::*; use crate::block::*;
use crate::layout::*;
use crate::manager::*; use crate::manager::*;
// Full scrub every 25 days with a random element of 10 days mixed in below // Full scrub every 25 days with a random element of 10 days mixed in below
@ -636,31 +635,23 @@ impl BlockStoreIterator {
fn new(manager: &BlockManager) -> Self { fn new(manager: &BlockManager) -> Self {
let data_layout = manager.data_layout.load_full(); let data_layout = manager.data_layout.load_full();
let min_cap = data_layout let mut dir_cap = vec![0; data_layout.data_dirs.len()];
.data_dirs for prim in data_layout.part_prim.iter() {
.iter() dir_cap[*prim as usize] += 1;
.filter_map(|x| x.capacity()) }
.min() for sec_vec in data_layout.part_sec.iter() {
.unwrap_or(0); for sec in sec_vec.iter() {
dir_cap[*sec as usize] += 1;
let sum_cap = data_layout }
.data_dirs }
.iter() let sum_cap = dir_cap.iter().sum::<usize>() as u64;
.map(|x| x.capacity().unwrap_or(min_cap /* approximation */))
.sum::<u64>() as u128;
let mut cum_cap = 0; let mut cum_cap = 0;
let mut todo = vec![]; let mut todo = vec![];
for dir in data_layout.data_dirs.iter() { for (dir, cap) in data_layout.data_dirs.iter().zip(dir_cap.into_iter()) {
let cap = match dir.state { let progress_min = (cum_cap * PROGRESS_FP) / sum_cap;
DataDirState::Active { capacity } => capacity, let progress_max = ((cum_cap + cap as u64) * PROGRESS_FP) / sum_cap;
_ => min_cap, cum_cap += cap as u64;
};
let progress_min = ((cum_cap as u128 * PROGRESS_FP as u128) / (sum_cap as u128)) as u64;
let progress_max =
(((cum_cap + cap) as u128 * PROGRESS_FP as u128) / (sum_cap as u128)) as u64;
cum_cap += cap;
todo.push(BsiTodo::Directory { todo.push(BsiTodo::Directory {
path: dir.path.clone(), path: dir.path.clone(),