From a2d87a012d2452177da37d159f1367f17eba7d9c Mon Sep 17 00:00:00 2001 From: Yureka Date: Sun, 20 Apr 2025 20:56:04 +0200 Subject: [PATCH] refactor: use replication factor of the layout versions in calculate_sync_map_min_with_quorum --- src/rpc/layout/helper.rs | 7 +------ src/rpc/layout/history.rs | 26 +++++++++++++++----------- src/rpc/layout/manager.rs | 8 ++------ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/rpc/layout/helper.rs b/src/rpc/layout/helper.rs index 35746851..088ffb2f 100644 --- a/src/rpc/layout/helper.rs +++ b/src/rpc/layout/helper.rs @@ -28,7 +28,6 @@ pub struct SyncLayoutDigest { } pub struct LayoutHelper { - replication_factor: ReplicationFactor, consistency_mode: ConsistencyMode, layout: Option, @@ -51,7 +50,6 @@ pub struct LayoutHelper { impl LayoutHelper { pub fn new( - replication_factor: ReplicationFactor, consistency_mode: ConsistencyMode, mut layout: LayoutHistory, mut ack_lock: HashMap, @@ -97,8 +95,7 @@ impl LayoutHelper { // consistency on those). // This value is calculated using quorums to allow progress even // if not all nodes have successfully completed a sync. - let sync_map_min = - layout.calculate_sync_map_min_with_quorum(replication_factor, &all_nongateway_nodes); + let sync_map_min = layout.calculate_sync_map_min_with_quorum(&all_nongateway_nodes); let trackers_hash = layout.calculate_trackers_hash(); let staging_hash = layout.calculate_staging_hash(); @@ -111,7 +108,6 @@ impl LayoutHelper { let is_check_ok = layout.check().is_ok(); LayoutHelper { - replication_factor, consistency_mode, layout: Some(layout), ack_map_min, @@ -134,7 +130,6 @@ impl LayoutHelper { let changed = f(self.layout.as_mut().unwrap()); if changed { *self = Self::new( - self.replication_factor, self.consistency_mode, self.layout.take().unwrap(), std::mem::take(&mut self.ack_lock), diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs index 1e6bc84b..79f4e3c0 100644 --- a/src/rpc/layout/history.rs +++ b/src/rpc/layout/history.rs @@ -123,13 +123,9 @@ impl LayoutHistory { } } - pub(crate) fn calculate_sync_map_min_with_quorum( - &self, - replication_factor: ReplicationFactor, - all_nongateway_nodes: &[Uuid], - ) -> u64 { - // This function calculates the minimum layout version from which - // it is safe to read if we want to maintain read-after-write consistency. + /// This function calculates the minimum layout version from which + /// it is safe to read if we want to maintain read-after-write consistency. + pub(crate) fn calculate_sync_map_min_with_quorum(&self, all_nongateway_nodes: &[Uuid]) -> u64 { // In the general case the computation can be a bit expensive so // we try to optimize it in several ways. @@ -139,8 +135,6 @@ impl LayoutHistory { return self.current().version; } - let quorum = replication_factor.write_quorum(ConsistencyMode::Consistent); - let min_version = self.min_stored(); let global_min = self .update_trackers @@ -153,7 +147,16 @@ impl LayoutHistory { // This is represented by reading from the layout with version // number global_min, the smallest layout version for which all nodes // have completed a sync. - if quorum == self.current().replication_factor { + // + // While we currently do not support changing the replication factor + // between layout versions, this calculation is future-proofing for the + // case where this might be possible. + if self + .versions + .iter() + .filter(|v| v.version >= global_min) + .all(|v| v.write_quorum(ConsistencyMode::Consistent) == v.replication_factor) + { return global_min; } @@ -195,7 +198,8 @@ impl LayoutHistory { .map(|x| self.update_trackers.sync_map.get(x, min_version)) .collect::>(); sync_values.sort(); - let set_min = sync_values[sync_values.len() - quorum]; + let set_min = + sync_values[sync_values.len() - v.write_quorum(ConsistencyMode::Consistent)]; if set_min < current_min { current_min = set_min; } diff --git a/src/rpc/layout/manager.rs b/src/rpc/layout/manager.rs index 789603b5..c5bba0b6 100644 --- a/src/rpc/layout/manager.rs +++ b/src/rpc/layout/manager.rs @@ -64,12 +64,8 @@ impl LayoutManager { } }; - let mut cluster_layout = LayoutHelper::new( - replication_factor, - consistency_mode, - cluster_layout, - Default::default(), - ); + let mut cluster_layout = + LayoutHelper::new(consistency_mode, cluster_layout, Default::default()); cluster_layout.update_update_trackers(node_id.into()); let layout = Arc::new(RwLock::new(cluster_layout));