diff options
author | Alex <alex@adnab.me> | 2022-09-13 16:49:05 +0200 |
---|---|---|
committer | Alex <alex@adnab.me> | 2022-09-13 16:49:05 +0200 |
commit | 80fdbfb0aa1b7186db3aeef888c0954748a35c62 (patch) | |
tree | 20c275ab7019b9c1458e4c2daef56a1b93411f8a /src/rpc | |
parent | 11bdc971e2aaa1ef90358b7d9c1bd6a8e9743bbf (diff) | |
parent | ab722cb40f5aacf661a280b7eb025acd3aefc1bb (diff) | |
download | garage-0.8.0-beta1.tar.gz garage-0.8.0-beta1.zip |
Merge pull request 'various fixes for v0.8.0' (#380) from various-fixes-for-0.8 into mainv0.8.0-beta1
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/380
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/kubernetes.rs | 2 | ||||
-rw-r--r-- | src/rpc/system.rs | 30 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/rpc/kubernetes.rs b/src/rpc/kubernetes.rs index 939a0eed..197245aa 100644 --- a/src/rpc/kubernetes.rs +++ b/src/rpc/kubernetes.rs @@ -56,7 +56,7 @@ pub async fn get_kubernetes_nodes( let mut ret = Vec::with_capacity(nodes.items.len()); for node in nodes { - println!("Found Pod: {:?}", node.metadata.name); + info!("Found Pod: {:?}", node.metadata.name); let pubkey = &node .metadata diff --git a/src/rpc/system.rs b/src/rpc/system.rs index c0e70c61..228b66a4 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -198,7 +198,7 @@ impl System { background: Arc<BackgroundRunner>, replication_factor: usize, config: &Config, - ) -> Arc<Self> { + ) -> Result<Arc<Self>, Error> { let node_key = gen_node_key(&config.metadata_dir).expect("Unable to read or generate node ID"); info!( @@ -206,11 +206,21 @@ impl System { hex::encode(&node_key.public_key()[..8]) ); - let persist_cluster_layout = Persister::new(&config.metadata_dir, "cluster_layout"); + let persist_cluster_layout: Persister<ClusterLayout> = + Persister::new(&config.metadata_dir, "cluster_layout"); let persist_peer_list = Persister::new(&config.metadata_dir, "peer_list"); let cluster_layout = match persist_cluster_layout.load() { - Ok(x) => x, + Ok(x) => { + if x.replication_factor != replication_factor { + return Err(Error::Message(format!( + "Prevous cluster layout has replication factor {}, which is different than the one specified in the config file ({}). The previous cluster layout can be purged, if you know what you are doing, simply by deleting the `cluster_layout` file in your metadata directory.", + x.replication_factor, + replication_factor + ))); + } + x + } Err(e) => { info!( "No valid previous cluster layout stored ({}), starting fresh.", @@ -303,7 +313,7 @@ impl System { metadata_dir: config.metadata_dir.clone(), }); sys.system_endpoint.set_handler(sys.clone()); - sys + Ok(sys) } /// Perform bootstraping, starting the ping loop @@ -485,7 +495,7 @@ impl System { let local_info = self.local_status.load(); if local_info.replication_factor < info.replication_factor { - error!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and might lead to bugs", + error!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and will lead to data corruption. Shutting down for safety.", info.replication_factor, local_info.replication_factor); std::process::exit(1); @@ -513,6 +523,16 @@ impl System { self: &Arc<Self>, adv: &ClusterLayout, ) -> Result<SystemRpc, Error> { + if adv.replication_factor != self.replication_factor { + let msg = format!( + "Received a cluster layout from another node with replication factor {}, which is different from what we have in our configuration ({}). Discarding the cluster layout we received.", + adv.replication_factor, + self.replication_factor + ); + error!("{}", msg); + return Err(Error::Message(msg)); + } + let update_ring = self.update_ring.lock().await; let mut layout: ClusterLayout = self.ring.borrow().layout.clone(); |