aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-11-14 13:06:16 +0100
committerAlex Auvolat <alex@adnab.me>2023-11-14 13:12:32 +0100
commit1aab1f4e688ebc3f3adcb41c817c16c688a3291c (patch)
treecf006db1b3aeb6ebff8d976aee33469ffabe75f2 /src/rpc/layout
parent8e292e06b3fde1d3b5b019a26eabd4f0d9ac22c3 (diff)
downloadgarage-1aab1f4e688ebc3f3adcb41c817c16c688a3291c.tar.gz
garage-1aab1f4e688ebc3f3adcb41c817c16c688a3291c.zip
layout: refactoring of all_nodes
Diffstat (limited to 'src/rpc/layout')
-rw-r--r--src/rpc/layout/history.rs15
-rw-r--r--src/rpc/layout/version.rs17
2 files changed, 22 insertions, 10 deletions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs
index 877ad3a7..69348873 100644
--- a/src/rpc/layout/history.rs
+++ b/src/rpc/layout/history.rs
@@ -60,6 +60,21 @@ impl LayoutHistory {
(self.current().version, self.all_ack(), self.min_stored())
}
+ pub fn all_nodes(&self) -> Cow<'_, [Uuid]> {
+ // TODO: cache this
+ if self.versions.len() == 1 {
+ self.versions[0].all_nodes().into()
+ } else {
+ let set = self
+ .versions
+ .iter()
+ .map(|x| x.all_nodes())
+ .flatten()
+ .collect::<HashSet<_>>();
+ set.into_iter().copied().collect::<Vec<_>>().into()
+ }
+ }
+
pub fn all_nongateway_nodes(&self) -> Cow<'_, [Uuid]> {
// TODO: cache this
if self.versions.len() == 1 {
diff --git a/src/rpc/layout/version.rs b/src/rpc/layout/version.rs
index a7f387b6..2cbdcee2 100644
--- a/src/rpc/layout/version.rs
+++ b/src/rpc/layout/version.rs
@@ -38,22 +38,19 @@ impl LayoutVersion {
// ===================== accessors ======================
- /// Returns a list of IDs of nodes that currently have
- /// a role in the cluster
- pub fn node_ids(&self) -> &[Uuid] {
+ /// Returns a list of IDs of nodes that have a role in this
+ /// version of the cluster layout, including gateway nodes
+ pub fn all_nodes(&self) -> &[Uuid] {
&self.node_id_vec[..]
}
- /// Returns the uuids of the non_gateway nodes in self.node_id_vec.
+ /// Returns a list of IDs of nodes that have a storage capacity
+ /// assigned in this version of the cluster layout
pub fn nongateway_nodes(&self) -> &[Uuid] {
&self.node_id_vec[..self.nongateway_node_count]
}
- pub fn num_nodes(&self) -> usize {
- self.node_id_vec.len()
- }
-
- /// Returns the role of a node in the layout
+ /// Returns the role of a node in the layout, if it has one
pub fn node_role(&self, node: &Uuid) -> Option<&NodeRole> {
match self.roles.get(node) {
Some(NodeRoleV(Some(v))) => Some(v),
@@ -61,7 +58,7 @@ impl LayoutVersion {
}
}
- /// Given a node uuids, this function returns its capacity or fails if it does not have any
+ /// Returns the capacity of a node in the layout, if it has one
pub fn get_node_capacity(&self, uuid: &Uuid) -> Option<u64> {
match self.node_role(uuid) {
Some(NodeRole {