From e6cfb47be2efb6e21f6a75024f78f0557a4c9e3c Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Wed, 2 Jun 2021 12:29:29 +0200 Subject: [PATCH 1/3] warn when inconsistent level of replication is detected --- src/rpc/membership.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index 72477539..e29436ec 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -141,7 +141,10 @@ impl StatusEntry { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct StateInfo { + /// Hostname of the node pub hostname: String, + /// Replication factor configured on the node + pub replication_factor: Option, // TODO Option is just for retrocompatibility. It should become a simple usize at some point } impl Status { @@ -269,6 +272,7 @@ impl System { hostname: gethostname::gethostname() .into_string() .unwrap_or_else(|_| "".to_string()), + replication_factor: Some(replication_factor), }; let ring = Ring::new(net_config, replication_factor); @@ -504,6 +508,7 @@ impl System { let update_lock = self.update_lock.lock().await; let mut status: Status = self.status.borrow().as_ref().clone(); let mut has_changed = false; + let mut max_replication_factor = 0; for node in adv.iter() { if node.id == self.id { @@ -529,11 +534,21 @@ impl System { // Case 2: the node might have changed address Some(our_node) => node.is_up && !our_node.is_up() && our_node.addr != node.addr, }; + max_replication_factor = std::cmp::max( + max_replication_factor, + node.state_info.replication_factor.unwrap_or_default(), + ); if ping_them { to_ping.push((node.addr, Some(node.id))); } } } + + if self.replication_factor < max_replication_factor { + warn!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and might lead to bugs", + max_replication_factor, + self.replication_factor); + } if has_changed { status.recalculate_hash(); } -- 2.45.3 From 13bd3138cb9ec4221049d1503ede33e8f391dfb0 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Wed, 2 Jun 2021 13:12:36 +0200 Subject: [PATCH 2/3] error and exit on replication level mismatch --- src/rpc/membership.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index e29436ec..d7890b52 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -544,10 +544,11 @@ impl System { } } - if self.replication_factor < max_replication_factor { - warn!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and might lead to bugs", + if self.replication_factor < max_replication_factor { + error!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and might lead to bugs", max_replication_factor, self.replication_factor); + std::process::exit(1); } if has_changed { status.recalculate_hash(); -- 2.45.3 From 8611f8c0efd25bf3e748834c4bc640e26bde25bb Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Wed, 2 Jun 2021 13:22:06 +0200 Subject: [PATCH 3/3] fix formating --- src/rpc/membership.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index d7890b52..a77eeed3 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -544,7 +544,7 @@ impl System { } } - if self.replication_factor < max_replication_factor { + if self.replication_factor < max_replication_factor { error!("Some node have a higher replication factor ({}) than this one ({}). This is not supported and might lead to bugs", max_replication_factor, self.replication_factor); -- 2.45.3