From d25e631a4a47ab54684777120316cdc32d49c4d5 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 25 Mar 2025 16:35:56 +0100 Subject: [PATCH] relocalize logic for write_sets --- src/rpc/layout/helper.rs | 13 ------------- src/table/replication/fullcopy.rs | 14 ++++++++++---- src/table/replication/sharded.rs | 12 ++++++++++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/rpc/layout/helper.rs b/src/rpc/layout/helper.rs index 6614ac22..482a2eea 100644 --- a/src/rpc/layout/helper.rs +++ b/src/rpc/layout/helper.rs @@ -196,19 +196,6 @@ impl LayoutHelper { self.current().nodes_of(hash).collect() } - /// For a given hash, or for all cluster if no hash is given, - /// return for each layout version the set of nodes that writes should be sent to - /// and for which a quorum of OK responses should be awaited. - pub fn write_sets_of(&self, hash: Option<&Hash>) -> Vec> { - self.versions() - .iter() - .map(|x| match hash { - Some(h) => x.nodes_of(h).collect(), - None => x.all_nodes().to_vec(), - }) - .collect() - } - pub fn ack_map_min(&self) -> u64 { self.ack_map_min } diff --git a/src/table/replication/fullcopy.rs b/src/table/replication/fullcopy.rs index cdb7361f..2ede578e 100644 --- a/src/table/replication/fullcopy.rs +++ b/src/table/replication/fullcopy.rs @@ -51,9 +51,7 @@ impl TableReplication for TableFullReplication { } fn write_sets(&self, _hash: &Hash) -> Self::WriteSets { - self.system - .layout_manager - .write_lock_with(|l| l.write_sets_of(None)) + self.system.layout_manager.write_lock_with(write_sets) } fn write_quorum(&self) -> usize { let layout = self.system.cluster_layout(); @@ -89,7 +87,7 @@ impl TableReplication for TableFullReplication { partition: 0u16, first_hash: [0u8; 32].into(), last_hash: [0xff; 32].into(), - storage_sets: layout.write_sets_of(None), + storage_sets: write_sets(&layout), }]; SyncPartitions { @@ -98,3 +96,11 @@ impl TableReplication for TableFullReplication { } } } + +fn write_sets(layout: &LayoutHelper) -> Vec> { + layout + .versions() + .iter() + .map(|x| x.all_nodes().to_vec()) + .collect() +} diff --git a/src/table/replication/sharded.rs b/src/table/replication/sharded.rs index 4f73b277..2514d880 100644 --- a/src/table/replication/sharded.rs +++ b/src/table/replication/sharded.rs @@ -56,7 +56,7 @@ impl TableReplication for TableShardedReplication { fn write_sets(&self, hash: &Hash) -> Self::WriteSets { self.system .layout_manager - .write_lock_with(|l| l.write_sets_of(Some(hash))) + .write_lock_with(|l| write_sets(l, hash)) } fn write_quorum(&self) -> usize { self.write_quorum @@ -78,7 +78,7 @@ impl TableReplication for TableShardedReplication { partition, first_hash, last_hash: [0u8; 32].into(), // filled in just after - storage_sets: layout.write_sets_of(Some(&first_hash)), + storage_sets: write_sets(&layout, &first_hash), } }) .collect::>(); @@ -97,3 +97,11 @@ impl TableReplication for TableShardedReplication { } } } + +fn write_sets(layout: &LayoutHelper, hash: &Hash) -> Vec> { + layout + .versions() + .iter() + .map(|x| x.nodes_of(hash).collect()) + .collect() +}