diff options
author | Alex Auvolat <alex@adnab.me> | 2021-04-05 20:26:01 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-04-27 16:37:09 +0200 |
commit | e16077f40a714fddf7a9ba585a171d0c7b40d19a (patch) | |
tree | 82194baf5dcde3fdd71d322a3d3eeb686f1222a9 /src | |
parent | 15ae74b080d2199dfe6ac076235651ca4dc4fe08 (diff) | |
download | garage-e16077f40a714fddf7a9ba585a171d0c7b40d19a.tar.gz garage-e16077f40a714fddf7a9ba585a171d0c7b40d19a.zip |
Persist directly and not in background
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/membership.rs | 23 |
1 files 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<Self>, updaters: &Updaters, status: Status) { + async fn update_status(self: &Arc<Self>, 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<Self>, status: Arc<Status>) -> Result<(), Error> { - let serializable_status = status.to_serializable_membership(&self); - self.persist_status.save_async(&serializable_status).await?; - Ok(()) } } |