diff options
author | Alex <alex@adnab.me> | 2024-08-24 11:12:39 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2024-08-24 11:12:39 +0000 |
commit | 8d62616ec057c8a9e32e9ae42ca637369ee403e3 (patch) | |
tree | 99e12ae5a775e729991e092fc8e9107549b58b3a /src/rpc/layout | |
parent | bd6fe72c065048663b9f6af87f1e5a4a48e88d04 (diff) | |
parent | 7fb66b4944b637dfcd53bc301f7bbed501ca8573 (diff) | |
download | garage-8d62616ec057c8a9e32e9ae42ca637369ee403e3.tar.gz garage-8d62616ec057c8a9e32e9ae42ca637369ee403e3.zip |
Merge pull request 'layout: discard old info when it is completely out-of-date (fix #841)' (#861) from fix-841 into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/861
Diffstat (limited to 'src/rpc/layout')
-rw-r--r-- | src/rpc/layout/history.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs index af2cbc63..574c50c2 100644 --- a/src/rpc/layout/history.rs +++ b/src/rpc/layout/history.rs @@ -227,24 +227,29 @@ impl LayoutHistory { // ================== updates to layout, public interface =================== pub fn merge(&mut self, other: &LayoutHistory) -> bool { + // If our current layout version is completely out-of-date, + // forget everything we know and replace it by incoming layout data. + if self.current().version < other.min_stored() { + *self = other.clone(); + return true; + } + let mut changed = false; // Add any new versions to history for v2 in other.versions.iter() { - if let Some(v1) = self.versions.iter().find(|v| v.version == v2.version) { + if v2.version == self.current().version + 1 { + // This is the next version, add it to our version list + self.versions.push(v2.clone()); + changed = true; + } else if let Some(v1) = self.versions.iter().find(|v| v.version == v2.version) { // Version is already present, check consistency if v1 != v2 { error!("Inconsistent layout histories: different layout compositions for version {}. Your cluster will be broken as long as this layout version is not replaced.", v2.version); } - } else if self.versions.iter().all(|v| v.version != v2.version - 1) { - error!( - "Cannot receive new layout version {}, version {} is missing", - v2.version, - v2.version - 1 - ); } else { - self.versions.push(v2.clone()); - changed = true; + // This is an older version + assert!(v2.version < self.min_stored()); } } |