Skip to content

Commit

Permalink
fix(SweepObjects): dedup backend checking
Browse files Browse the repository at this point in the history
To prevent same backend from being checked multiple times
  • Loading branch information
iwanbk authored and LeeSmet committed Dec 4, 2024
1 parent 400fdf0 commit 4404f06
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions zstor/src/actors/repairer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use crate::actors::{
backends::{BackendManagerActor, RequestBackends, StateInterest},
meta::{MetaStoreActor, ObjectMetas},
zstor::{Rebuild, ZstorActor},
use crate::{
actors::{
backends::{BackendManagerActor, RequestBackends, StateInterest},
meta::{MetaStoreActor, ObjectMetas},
zstor::{Rebuild, ZstorActor},
},
zdb::ZdbConnectionInfo,
};
use actix::prelude::*;
use log::{error, warn};
use log::{debug, error, warn};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::time::Duration;

/// Amount of time between starting a new sweep of the backend objects.
Expand Down Expand Up @@ -79,13 +84,37 @@ impl Handler<SweepObjects> for RepairActor {
},
};

// prevent same backend from being checked multiple times
let mut unique_zdbs = HashMap::new();
for (key, metadata) in obj_metas.into_iter() {
let backend_requests = metadata
let mut need_rebuild_check = false;
let backend_requests: Vec<ZdbConnectionInfo> = metadata
.shards()
.iter()
.map(|shard_info| shard_info.zdb())
.cloned()
.collect::<Vec<_>>();
.map(|shard_info| shard_info.zdb().clone())
.filter(|zdb| match unique_zdbs.entry(zdb.clone()) {
Entry::Occupied(entry) => {
let is_healthy: &bool = entry.get();
if !*is_healthy {
need_rebuild_check = true;
}
false
}
Entry::Vacant(entry) => {
entry.insert(false);
true
}
})
.collect();
if backend_requests.is_empty() {
debug!("No unchecked backends found for object: {}", key);
continue;
}
debug!("number of backends to check = {}", backend_requests.len());

if !need_rebuild_check {
continue;
}
let backends = match backend_manager
.send(RequestBackends {
backend_requests,
Expand All @@ -99,7 +128,13 @@ impl Handler<SweepObjects> for RepairActor {
}
Ok(backends) => backends,
};
let must_rebuild = backends.into_iter().any(|b| !matches!(b, Ok(Some(_))));
let must_rebuild = backends.into_iter().fold(false, |rebuild, b| {
let is_healthy = matches!(b, Ok(Some(_)));
if let Ok(Some(zdb)) = b {
unique_zdbs.insert(zdb.connection_info().clone(), is_healthy);
}
rebuild || !is_healthy
});
if must_rebuild {
if let Err(e) = zstor
.send(Rebuild {
Expand Down

0 comments on commit 4404f06

Please sign in to comment.