aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout/schema.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-11-15 13:28:30 +0100
committerAlex Auvolat <alex@adnab.me>2023-11-15 13:28:30 +0100
commit65066c70640371cc318faddfb4c05c96de18e86d (patch)
tree11c8d69b325896e8b0cf3d2af83e18c1c90fbc78 /src/rpc/layout/schema.rs
parentacd49de9f97bd27409232691262bd5827983388d (diff)
downloadgarage-65066c70640371cc318faddfb4c05c96de18e86d.tar.gz
garage-65066c70640371cc318faddfb4c05c96de18e86d.zip
layout: wip cache global mins
Diffstat (limited to 'src/rpc/layout/schema.rs')
-rw-r--r--src/rpc/layout/schema.rs36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/rpc/layout/schema.rs b/src/rpc/layout/schema.rs
index 79440a47..969f5a0b 100644
--- a/src/rpc/layout/schema.rs
+++ b/src/rpc/layout/schema.rs
@@ -260,7 +260,10 @@ mod v010 {
/// The history of cluster layouts
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
- pub struct UpdateTracker(pub BTreeMap<Uuid, u64>);
+ pub struct UpdateTracker {
+ pub values: BTreeMap<Uuid, u64>,
+ pub current_min: u64,
+ }
impl garage_util::migrate::Migrate for LayoutHistory {
const VERSION_MARKER: &'static [u8] = b"G010lh";
@@ -290,14 +293,15 @@ mod v010 {
nongateway_node_count,
ring_assignment_data: previous.ring_assignment_data,
};
- let update_tracker = UpdateTracker(
- version
+ let update_tracker = UpdateTracker {
+ values: version
.nongateway_nodes()
.iter()
.copied()
.map(|x| (x, version.version))
.collect::<BTreeMap<Uuid, u64>>(),
- );
+ current_min: 0,
+ };
let staging = LayoutStaging {
parameters: previous.staging_parameters,
roles: previous.staging_roles,
@@ -378,14 +382,14 @@ impl core::str::FromStr for ZoneRedundancy {
impl UpdateTracker {
fn merge(&mut self, other: &UpdateTracker) -> bool {
let mut changed = false;
- for (k, v) in other.0.iter() {
- if let Some(v_mut) = self.0.get_mut(k) {
+ for (k, v) in other.values.iter() {
+ if let Some(v_mut) = self.values.get_mut(k) {
if *v > *v_mut {
*v_mut = *v;
changed = true;
}
} else {
- self.0.insert(*k, *v);
+ self.values.insert(*k, *v);
changed = true;
}
}
@@ -393,18 +397,26 @@ impl UpdateTracker {
}
pub(crate) fn set_max(&mut self, peer: Uuid, value: u64) -> bool {
- match self.0.get_mut(&peer) {
+ match self.values.get_mut(&peer) {
Some(e) if *e < value => {
*e = value;
true
}
None => {
- self.0.insert(peer, value);
+ self.values.insert(peer, value);
true
}
_ => false,
}
}
+
+ fn update_min(&mut self, storage_nodes: &[Uuid], min_version: u64) {
+ self.current_min = storage_nodes
+ .iter()
+ .map(|x| self.values.get(x).copied().unwrap_or(min_version))
+ .min()
+ .unwrap_or(min_version)
+ }
}
impl UpdateTrackers {
@@ -414,4 +426,10 @@ impl UpdateTrackers {
let c3 = self.sync_ack_map.merge(&other.sync_ack_map);
c1 || c2 || c3
}
+
+ pub(crate) fn update_min(&mut self, storage_nodes: &[Uuid], min_version: u64) {
+ self.ack_map.update_min(&storage_nodes, min_version);
+ self.sync_map.update_min(&storage_nodes, min_version);
+ self.sync_ack_map.update_min(&storage_nodes, min_version);
+ }
}