diff options
author | Alex Auvolat <alex@adnab.me> | 2023-11-09 16:32:31 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-11-09 16:32:31 +0100 |
commit | df36cf3099f6010c4fc62109b85d4d1e62f160cc (patch) | |
tree | c2ad68640220da38796d63f24117cf56f3f77bb9 /src/rpc/layout/history.rs | |
parent | 9d95f6f7040c1899715ae4f984313427b1432758 (diff) | |
download | garage-df36cf3099f6010c4fc62109b85d4d1e62f160cc.tar.gz garage-df36cf3099f6010c4fc62109b85d4d1e62f160cc.zip |
layout: add helpers to LayoutHistory and prepare integration with Table
Diffstat (limited to 'src/rpc/layout/history.rs')
-rw-r--r-- | src/rpc/layout/history.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs index e17a1c77..dbb02269 100644 --- a/src/rpc/layout/history.rs +++ b/src/rpc/layout/history.rs @@ -32,14 +32,6 @@ impl LayoutHistory { self.versions.last().as_ref().unwrap() } - pub fn all_storage_nodes(&self) -> HashSet<Uuid> { - self.versions - .iter() - .map(|x| x.nongateway_nodes()) - .flatten() - .collect::<HashSet<_>>() - } - pub fn update_hashes(&mut self) { self.trackers_hash = self.calculate_trackers_hash(); self.staging_hash = self.calculate_staging_hash(); @@ -53,6 +45,39 @@ impl LayoutHistory { blake2sum(&nonversioned_encode(&self.staging).unwrap()[..]) } + // ------------------ who stores what now? --------------- + + pub fn max_ack(&self) -> u64 { + self.calculate_global_min(&self.update_trackers.ack_map) + } + + pub fn all_storage_nodes(&self) -> HashSet<Uuid> { + // TODO: cache this + self.versions + .iter() + .map(|x| x.nongateway_nodes()) + .flatten() + .collect::<HashSet<_>>() + } + + pub fn read_nodes_of(&self, position: &Hash) -> Vec<Uuid> { + let sync_min = self.calculate_global_min(&self.update_trackers.sync_map); + let version = self + .versions + .iter() + .find(|x| x.version == sync_min) + .or(self.versions.last()) + .unwrap(); + version.nodes_of(position, version.replication_factor) + } + + pub fn write_sets_of(&self, position: &Hash) -> Vec<Vec<Uuid>> { + self.versions + .iter() + .map(|x| x.nodes_of(position, x.replication_factor)) + .collect::<Vec<_>>() + } + // ------------------ update tracking --------------- pub(crate) fn update_trackers(&mut self, node_id: Uuid) { |