diff options
author | Alex Auvolat <alex@adnab.me> | 2021-11-03 17:34:44 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-11-03 17:34:44 +0100 |
commit | 8c4f418fe889106758a086b34688f7c3b378ca64 (patch) | |
tree | bfff8380a328fe4b7077cd6608424ffbe1503691 /src/rpc/system.rs | |
parent | bef6d627b06997a0b98cbd5522a65c8db11e07b9 (diff) | |
download | garage-8c4f418fe889106758a086b34688f7c3b378ca64.tar.gz garage-8c4f418fe889106758a086b34688f7c3b378ca64.zip |
Fix peer list persistence: do not forget previous peers
Diffstat (limited to 'src/rpc/system.rs')
-rw-r--r-- | src/rpc/system.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/rpc/system.rs b/src/rpc/system.rs index ed18f657..8f5a1ec5 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -500,13 +500,7 @@ impl System { } } - let peer_list = self - .fullmesh - .get_peer_list() - .iter() - .map(|n| (n.id.into(), n.addr)) - .collect::<Vec<_>>(); - if let Err(e) = self.persist_peer_list.save_async(&peer_list).await { + if let Err(e) = self.save_peer_list().await { warn!("Could not save peer list to file: {}", e); } @@ -520,6 +514,28 @@ impl System { } } + async fn save_peer_list(&self) -> Result<(), Error> { + // Prepare new peer list to save to file + // It is a vec of tuples (node ID as Uuid, node SocketAddr) + let mut peer_list = self + .fullmesh + .get_peer_list() + .iter() + .map(|n| (n.id.into(), n.addr)) + .collect::<Vec<_>>(); + + // Before doing it, we read the current peer list file (if it exists) + // and append it to the list we are about to save, + // so that no peer ID gets lost in the process. + if let Ok(mut prev_peer_list) = self.persist_peer_list.load_async().await { + prev_peer_list.retain(|(id, _ip)| peer_list.iter().all(|(id2, _ip2)| id2 != id)); + peer_list.extend(prev_peer_list); + } + + // Save new peer list to file + self.persist_peer_list.save_async(&peer_list).await + } + async fn pull_config(self: Arc<Self>, peer: Uuid) { let resp = self .rpc |