From e16077f40a714fddf7a9ba585a171d0c7b40d19a Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 5 Apr 2021 20:26:01 +0200 Subject: Persist directly and not in background --- src/rpc/membership.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index adef7c97..330c154f 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -410,7 +410,7 @@ impl System { if has_changes { status.recalculate_hash(); } - self.update_status(&update_locked, status); + self.update_status(&update_locked, status).await; drop(update_locked); if to_advertise.len() > 0 { @@ -434,7 +434,7 @@ impl System { let status_hash = status.hash; let config_version = self.ring.borrow().config.version; - self.update_status(&update_locked, status); + self.update_status(&update_locked, status).await; drop(update_locked); if is_new || status_hash != ping.status_hash { @@ -502,7 +502,7 @@ impl System { if has_changed { status.recalculate_hash(); } - self.update_status(&update_lock, status); + self.update_status(&update_lock, status).await; drop(update_lock); if to_ping.len() > 0 { @@ -650,19 +650,18 @@ impl System { } } - fn update_status(self: &Arc, updaters: &Updaters, status: Status) { + async fn update_status(self: &Arc, updaters: &Updaters, status: Status) { + if status.hash != self.status.borrow().hash { + info!("Persisting new peer list"); + let serializable_status = status.to_serializable_membership(&self); + self.persist_status.save_async(&serializable_status).await + .expect("Unable to persist peer list"); + } + let status = Arc::new(status); updaters .update_status .send(status.clone()) .expect("Could not update internal membership status"); - self.background - .spawn_cancellable(self.clone().persist_status(status)); - } - - async fn persist_status(self: Arc, status: Arc) -> Result<(), Error> { - let serializable_status = status.to_serializable_membership(&self); - self.persist_status.save_async(&serializable_status).await?; - Ok(()) } } -- cgit v1.2.3