aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/layout
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-11-27 11:52:57 +0100
committerAlex Auvolat <alex@adnab.me>2023-11-27 11:52:57 +0100
commitd6d239fc7909cbd017da6ea35cceb3d561a87cca (patch)
tree18725effafdd990d7e2953adcc1b50399673caed /src/rpc/layout
parent3ecd14b9f6202ad3c5513c6ad7422bd408134002 (diff)
downloadgarage-d6d239fc7909cbd017da6ea35cceb3d561a87cca.tar.gz
garage-d6d239fc7909cbd017da6ea35cceb3d561a87cca.zip
block manager: read_block using old layout versions if necessary
Diffstat (limited to 'src/rpc/layout')
-rw-r--r--src/rpc/layout/helper.rs23
-rw-r--r--src/rpc/layout/history.rs12
-rw-r--r--src/rpc/layout/schema.rs7
3 files changed, 41 insertions, 1 deletions
diff --git a/src/rpc/layout/helper.rs b/src/rpc/layout/helper.rs
index 0d746ea3..5d159f3e 100644
--- a/src/rpc/layout/helper.rs
+++ b/src/rpc/layout/helper.rs
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
use garage_util::data::*;
use super::schema::*;
+use crate::rpc_helper::RpcHelper;
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct LayoutDigest {
@@ -140,6 +141,28 @@ impl LayoutHelper {
.collect()
}
+ pub fn block_read_nodes_of(&self, position: &Hash, rpc_helper: &RpcHelper) -> Vec<Uuid> {
+ let mut ret = Vec::with_capacity(12);
+ let ver_iter = self
+ .layout()
+ .versions
+ .iter()
+ .rev()
+ .chain(self.layout().old_versions.iter().rev());
+ for ver in ver_iter {
+ if ver.version > self.sync_map_min {
+ continue;
+ }
+ let nodes = ver.nodes_of(position, ver.replication_factor);
+ for node in rpc_helper.request_order(nodes) {
+ if !ret.contains(&node) {
+ ret.push(node);
+ }
+ }
+ }
+ ret
+ }
+
pub(crate) fn write_sets_of(&self, position: &Hash) -> Vec<Vec<Uuid>> {
self.layout()
.versions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs
index 653d2a48..7d4a1b48 100644
--- a/src/rpc/layout/history.rs
+++ b/src/rpc/layout/history.rs
@@ -18,6 +18,7 @@ impl LayoutHistory {
LayoutHistory {
versions: vec![version],
+ old_versions: vec![],
update_trackers: Default::default(),
staging: Lww::raw(0, staging),
}
@@ -86,11 +87,20 @@ impl LayoutHistory {
.min(&all_nongateway_nodes, min_version);
if self.min_stored() < sync_ack_map_min {
let removed = self.versions.remove(0);
- info!("Layout history: pruning old version {}", removed.version);
+ info!(
+ "Layout history: moving version {} to old_versions",
+ removed.version
+ );
+ self.old_versions.push(removed);
} else {
break;
}
}
+
+ while self.old_versions.len() > OLD_VERSION_COUNT {
+ let removed = self.old_versions.remove(0);
+ info!("Layout history: removing old_version {}", removed.version);
+ }
}
pub(crate) fn clamp_update_trackers(&mut self, nodes: &[Uuid]) {
diff --git a/src/rpc/layout/schema.rs b/src/rpc/layout/schema.rs
index 00a2c017..08db44ca 100644
--- a/src/rpc/layout/schema.rs
+++ b/src/rpc/layout/schema.rs
@@ -193,12 +193,18 @@ mod v010 {
use std::collections::BTreeMap;
pub use v09::{LayoutParameters, NodeRole, NodeRoleV, ZoneRedundancy};
+ pub const OLD_VERSION_COUNT: usize = 5;
+
/// The history of cluster layouts, with trackers to keep a record
/// of which nodes are up-to-date to current cluster data
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct LayoutHistory {
/// The versions currently in use in the cluster
pub versions: Vec<LayoutVersion>,
+ /// At most 5 of the previous versions, not used by the garage_table
+ /// module, but usefull for the garage_block module to find data blocks
+ /// that have not yet been moved
+ pub old_versions: Vec<LayoutVersion>,
/// Update trackers
pub update_trackers: UpdateTrackers,
@@ -300,6 +306,7 @@ mod v010 {
};
Self {
versions: vec![version],
+ old_versions: vec![],
update_trackers: UpdateTrackers {
ack_map: update_tracker.clone(),
sync_map: update_tracker.clone(),