aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout/version.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-11-14 14:28:16 +0100
committerAlex Auvolat <alex@adnab.me>2023-11-14 14:28:16 +0100
commit3b361d2959e3d577bdae6f8a5ccb0c9d5526b7ea (patch)
treef5448d44c7d5705c1e31912ca6d101c5998523ef /src/rpc/layout/version.rs
parent866196750fca74c1911ade2a90611f3663e60046 (diff)
downloadgarage-3b361d2959e3d577bdae6f8a5ccb0c9d5526b7ea.tar.gz
garage-3b361d2959e3d577bdae6f8a5ccb0c9d5526b7ea.zip
layout: prepare for write sets
Diffstat (limited to 'src/rpc/layout/version.rs')
-rw-r--r--src/rpc/layout/version.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/rpc/layout/version.rs b/src/rpc/layout/version.rs
index 2cbdcee2..912ee538 100644
--- a/src/rpc/layout/version.rs
+++ b/src/rpc/layout/version.rs
@@ -107,25 +107,24 @@ impl LayoutVersion {
}
/// Return the n servers in which data for this hash should be replicated
- pub fn nodes_of(&self, position: &Hash, n: usize) -> Vec<Uuid> {
+ pub fn nodes_of(&self, position: &Hash, n: usize) -> impl Iterator<Item = Uuid> + '_ {
assert_eq!(n, self.replication_factor);
let data = &self.ring_assignment_data;
- if data.len() != self.replication_factor * (1 << PARTITION_BITS) {
+ let partition_nodes = if data.len() == self.replication_factor * (1 << PARTITION_BITS) {
+ let partition_idx = self.partition_of(position) as usize;
+ let partition_start = partition_idx * self.replication_factor;
+ let partition_end = (partition_idx + 1) * self.replication_factor;
+ &data[partition_start..partition_end]
+ } else {
warn!("Ring not yet ready, read/writes will be lost!");
- return vec![];
- }
-
- let partition_idx = self.partition_of(position) as usize;
- let partition_start = partition_idx * self.replication_factor;
- let partition_end = (partition_idx + 1) * self.replication_factor;
- let partition_nodes = &data[partition_start..partition_end];
+ &[]
+ };
partition_nodes
.iter()
- .map(|i| self.node_id_vec[*i as usize])
- .collect::<Vec<_>>()
+ .map(move |i| self.node_id_vec[*i as usize])
}
// ===================== internal information extractors ======================