Skip to content

Commit a6fb449

Browse files
committed
Fix #73: Don't replace backends without explorer
Signed-off-by: Lee Smet <[email protected]>
1 parent ee8557d commit a6fb449

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

zstor/src/actors/backends.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ impl Handler<CheckBackends> for BackendManagerActor {
214214
.map(|(ci, (db, state))| (ci.clone(), (db.clone(), state.clone())))
215215
.collect::<Vec<_>>();
216216

217+
let config = self.config_addr.clone();
218+
217219
Box::pin(
218220
async move {
219221
let futs = data_backend_info
@@ -292,7 +294,14 @@ impl Handler<CheckBackends> for BackendManagerActor {
292294
}
293295
});
294296
let meta_info = join_all(futs).await;
295-
(data_info, meta_info)
297+
let cfg = match config.send(GetConfig).await {
298+
Ok(cfg) => Some(cfg),
299+
Err(e) => {
300+
error!("Could not get config: {}", e);
301+
None
302+
}
303+
};
304+
(data_info, meta_info, cfg)
296305
}
297306
.into_actor(self)
298307
.map(|res, actor, ctx| {
@@ -314,6 +323,11 @@ impl Handler<CheckBackends> for BackendManagerActor {
314323
if !(new_state.is_readable() && new_state.is_writeable()) {
315324
should_sweep = true;
316325
}
326+
// If the backend is not readable, remove the cached connection to trigger
327+
// a reconnect.
328+
if !new_state.is_readable() {
329+
*possible_con = None;
330+
}
317331
*old_state = new_state
318332
}
319333
}
@@ -334,11 +348,16 @@ impl Handler<CheckBackends> for BackendManagerActor {
334348
if !(new_state.is_readable() && new_state.is_writeable()) {
335349
should_sweep = true;
336350
}
351+
// If the backend is not readable, remove the cached connection to trigger
352+
// a reconnect.
353+
if !new_state.is_readable() {
354+
*possible_con = None;
355+
}
337356
*old_state = new_state
338357
}
339358
}
340359

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

0 commit comments

Comments
 (0)