Skip to content

Commit

Permalink
Fix #73: Don't replace backends without explorer
Browse files Browse the repository at this point in the history
Signed-off-by: Lee Smet <[email protected]>
  • Loading branch information
LeeSmet committed Oct 28, 2021
1 parent ee8557d commit a6fb449
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions zstor/src/actors/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ impl Handler<CheckBackends> for BackendManagerActor {
.map(|(ci, (db, state))| (ci.clone(), (db.clone(), state.clone())))
.collect::<Vec<_>>();

let config = self.config_addr.clone();

Box::pin(
async move {
let futs = data_backend_info
Expand Down Expand Up @@ -292,7 +294,14 @@ impl Handler<CheckBackends> for BackendManagerActor {
}
});
let meta_info = join_all(futs).await;
(data_info, meta_info)
let cfg = match config.send(GetConfig).await {
Ok(cfg) => Some(cfg),
Err(e) => {
error!("Could not get config: {}", e);
None
}
};
(data_info, meta_info, cfg)
}
.into_actor(self)
.map(|res, actor, ctx| {
Expand All @@ -314,6 +323,11 @@ impl Handler<CheckBackends> for BackendManagerActor {
if !(new_state.is_readable() && new_state.is_writeable()) {
should_sweep = true;
}
// If the backend is not readable, remove the cached connection to trigger
// a reconnect.
if !new_state.is_readable() {
*possible_con = None;
}
*old_state = new_state
}
}
Expand All @@ -334,11 +348,16 @@ impl Handler<CheckBackends> for BackendManagerActor {
if !(new_state.is_readable() && new_state.is_writeable()) {
should_sweep = true;
}
// If the backend is not readable, remove the cached connection to trigger
// a reconnect.
if !new_state.is_readable() {
*possible_con = None;
}
*old_state = new_state
}
}

if should_sweep {
if should_sweep && res.2.is_some() {
// Trigger a sweep of all managed backends, removing those at the end of their
// (managed) lifetime, and try to reserve new ones in their place.
actor.replace_backends(ctx);
Expand Down

0 comments on commit a6fb449

Please sign in to comment.