aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-10-21 13:45:52 +0200
committerAlex Auvolat <alex@adnab.me>2021-10-21 13:45:52 +0200
commit2fa65554f167eda086156ab5f2caf899d5402be8 (patch)
tree1e4bee9d7f365113bf524198ee41db08efede2ba
parent1dc7cc793638693c4000e13b43f4a7d117b1ea23 (diff)
downloadgarage-2fa65554f167eda086156ab5f2caf899d5402be8.tar.gz
garage-2fa65554f167eda086156ab5f2caf899d5402be8.zip
Persist peer list to file
-rw-r--r--src/rpc/system.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/rpc/system.rs b/src/rpc/system.rs
index 3a81bc3b..3031063d 100644
--- a/src/rpc/system.rs
+++ b/src/rpc/system.rs
@@ -69,6 +69,7 @@ pub struct System {
pub id: Uuid,
persist_config: Persister<NetworkConfig>,
+ persist_peer_list: Persister<Vec<(Uuid, SocketAddr)>>,
local_status: ArcSwap<NodeStatus>,
node_status: RwLock<HashMap<Uuid, (u64, NodeStatus)>>,
@@ -148,6 +149,7 @@ impl System {
info!("Node public key: {}", hex::encode(&node_key.public_key()));
let persist_config = Persister::new(&config.metadata_dir, "network_config");
+ let persist_peer_list = Persister::new(&config.metadata_dir, "peer_list");
let net_config = match persist_config.load() {
Ok(x) => x,
@@ -189,6 +191,7 @@ impl System {
let sys = Arc::new(System {
id: netapp.id.into(),
persist_config,
+ persist_peer_list,
local_status: ArcSwap::new(Arc::new(local_status)),
node_status: RwLock::new(HashMap::new()),
netapp: netapp.clone(),
@@ -424,13 +427,12 @@ impl System {
let mut ping_list = self.bootstrap_peers.clone();
- /*
- *TODO bring this back: persisted list of peers
- if let Ok(peers) = self.persist_status.load_async().await {
- ping_list.extend(peers.iter().map(|x| (x.addr, Some(x.id))));
+ // Add peer list from list stored on disk
+ if let Ok(peers) = self.persist_peer_list.load_async().await {
+ ping_list.extend(peers.iter().map(|(id, addr)| ((*id).into(), *addr)))
}
- */
+ // Fetch peer list from Consul
if let Some((consul_host, consul_service_name)) = &consul_config {
match get_consul_nodes(consul_host, consul_service_name).await {
Ok(node_list) => {
@@ -447,6 +449,16 @@ 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 {
+ warn!("Could not save peer list to file: {}", e);
+ }
+
self.background.spawn(self.clone().advertise_to_consul());
let restart_at = tokio::time::sleep(DISCOVERY_INTERVAL);