diff options
author | Alex Auvolat <alex@adnab.me> | 2023-12-11 15:45:14 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-12-11 15:45:14 +0100 |
commit | adccce1145d5d82581e4a5da707be35badb2d5a6 (patch) | |
tree | 7d24d8b76075a5ebcb628ad4f90d2facb9744e89 | |
parent | 85b5a6bcd11c0a7651e4c589569e1935a3d18e46 (diff) | |
download | garage-adccce1145d5d82581e4a5da707be35badb2d5a6.tar.gz garage-adccce1145d5d82581e4a5da707be35badb2d5a6.zip |
layout: refactor/fix bad while loop
-rw-r--r-- | src/rpc/layout/history.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/rpc/layout/history.rs b/src/rpc/layout/history.rs index 23196aee..b8cc27da 100644 --- a/src/rpc/layout/history.rs +++ b/src/rpc/layout/history.rs @@ -86,23 +86,20 @@ impl LayoutHistory { // remove them (keep them in self.old_versions). // ASSUMPTION: we only care about where nodes in the current layout version // are reading from, as we assume older nodes are being discarded. - while self.versions.len() > 1 { - let current_nodes = &self.current().node_id_vec; - let min_version = self.min_stored(); - let sync_ack_map_min = self - .update_trackers - .sync_ack_map - .min_among(current_nodes, min_version); - if self.min_stored() < sync_ack_map_min { - let removed = self.versions.remove(0); - info!( - "Layout history: moving version {} to old_versions", - removed.version - ); - self.old_versions.push(removed); - } else { - break; - } + let current_nodes = &self.current().node_id_vec; + let min_version = self.min_stored(); + let sync_ack_map_min = self + .update_trackers + .sync_ack_map + .min_among(current_nodes, min_version); + while self.min_stored() < sync_ack_map_min { + assert!(self.versions.len() > 1); + let removed = self.versions.remove(0); + info!( + "Layout history: moving version {} to old_versions", + removed.version + ); + self.old_versions.push(removed); } while self.old_versions.len() > OLD_VERSION_COUNT { |