aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout/history.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-11-14 12:48:38 +0100
committerAlex Auvolat <alex@adnab.me>2023-11-14 12:48:38 +0100
commit8e292e06b3fde1d3b5b019a26eabd4f0d9ac22c3 (patch)
treec4d252eaf122d9dd583cb755dffeb7d776ae4b66 /src/rpc/layout/history.rs
parent9a491fa1372a23e91c793ee1d2b313607752826a (diff)
downloadgarage-8e292e06b3fde1d3b5b019a26eabd4f0d9ac22c3.tar.gz
garage-8e292e06b3fde1d3b5b019a26eabd4f0d9ac22c3.zip
layout: some refactoring of nongateway nodes
Diffstat (limited to 'src/rpc/layout/history.rs')
-rw-r--r--src/rpc/layout/history.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs
index 050f5d0a..877ad3a7 100644
--- a/src/rpc/layout/history.rs
+++ b/src/rpc/layout/history.rs
@@ -1,3 +1,4 @@
+use std::borrow::Cow;
use std::collections::HashSet;
use garage_util::crdt::{Crdt, Lww, LwwMap};
@@ -59,13 +60,19 @@ impl LayoutHistory {
(self.current().version, self.all_ack(), self.min_stored())
}
- pub fn all_nongateway_nodes(&self) -> HashSet<Uuid> {
+ pub fn all_nongateway_nodes(&self) -> Cow<'_, [Uuid]> {
// TODO: cache this
- self.versions
- .iter()
- .map(|x| x.nongateway_nodes())
- .flatten()
- .collect::<HashSet<_>>()
+ if self.versions.len() == 1 {
+ self.versions[0].nongateway_nodes().into()
+ } else {
+ let set = self
+ .versions
+ .iter()
+ .map(|x| x.nongateway_nodes())
+ .flatten()
+ .collect::<HashSet<_>>();
+ set.into_iter().copied().collect::<Vec<_>>().into()
+ }
}
pub fn read_nodes_of(&self, position: &Hash) -> Vec<Uuid> {
@@ -202,14 +209,11 @@ To know the correct value of the new layout version, invoke `garage layout show`
}
// Compute new version and add it to history
- let mut new_version = self.current().clone();
- new_version.version += 1;
-
- new_version.roles.merge(&self.staging.get().roles);
- new_version.roles.retain(|(_, _, v)| v.0.is_some());
- new_version.parameters = *self.staging.get().parameters.get();
+ let (new_version, msg) = self
+ .current()
+ .clone()
+ .calculate_next_version(&self.staging.get())?;
- let msg = new_version.calculate_partition_assignment()?;
self.versions.push(new_version);
if self.current().check().is_ok() {
while self.versions.first().unwrap().check().is_err() {