diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-03 12:35:12 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-03 12:35:12 +0200 |
commit | 4bf706b170f149f54fd701576692cd5cd5bc9779 (patch) | |
tree | 9f85ddd71c76edfdbc7cfd0d016ae059bc5326e5 /src/garage/repair.rs | |
parent | bd9ff432d716020d7235ece76257b60dc3ead95a (diff) | |
download | garage-4bf706b170f149f54fd701576692cd5cd5bc9779.tar.gz garage-4bf706b170f149f54fd701576692cd5cd5bc9779.zip |
Slightly prettier code
Diffstat (limited to 'src/garage/repair.rs')
-rw-r--r-- | src/garage/repair.rs | 68 |
1 files changed, 18 insertions, 50 deletions
diff --git a/src/garage/repair.rs b/src/garage/repair.rs index 5735d6d0..a90b4148 100644 --- a/src/garage/repair.rs +++ b/src/garage/repair.rs @@ -1,4 +1,3 @@ -use core::ops::Bound; use std::sync::Arc; use tokio::sync::watch; @@ -16,8 +15,6 @@ pub struct Repair { pub garage: Arc<Garage>, } -type OptKVPair = Option<(Vec<u8>, Vec<u8>)>; - impl Repair { pub async fn repair_worker(&self, opt: RepairOpt, must_exit: watch::Receiver<bool>) { if let Err(e) = self.repair_worker_aux(opt, must_exit).await { @@ -68,8 +65,15 @@ impl Repair { async fn repair_versions(&self, must_exit: &watch::Receiver<bool>) -> Result<(), Error> { let mut pos = vec![]; - while let Some((item_key, item_bytes)) = self.get_next_version_after(&pos)? { - pos = item_key; + while *must_exit.borrow() { + let item_bytes = { + let (k, v) = match self.garage.version_table.data.store.get_gt(pos)? { + Some(pair) => pair, + None => break, + }; + pos = k.into_vec(); + v.into_vec() + }; let version = rmp_serde::decode::from_read_ref::<_, Version>(&item_bytes)?; if version.deleted.get() { @@ -99,36 +103,22 @@ impl Repair { )) .await?; } - - if *must_exit.borrow() { - break; - } } Ok(()) } - fn get_next_version_after(&self, pos: &[u8]) -> Result<OptKVPair, Error> { - match self - .garage - .version_table - .data - .store - .range::<&[u8], _>((Bound::Excluded(pos), Bound::Unbounded))? - .next() - { - None => Ok(None), - Some(item) => { - let (item_key, item_bytes) = item?; - Ok(Some((item_key.into_vec(), item_bytes.into_vec()))) - } - } - } - async fn repair_block_ref(&self, must_exit: &watch::Receiver<bool>) -> Result<(), Error> { let mut pos = vec![]; - while let Some((item_key, item_bytes)) = self.get_next_block_ref_after(&pos)? { - pos = item_key; + while *must_exit.borrow() { + let item_bytes = { + let (k, v) = match self.garage.block_ref_table.data.store.get_gt(pos)? { + Some(pair) => pair, + None => break, + }; + pos = k.into_vec(); + v.into_vec() + }; let block_ref = rmp_serde::decode::from_read_ref::<_, BlockRef>(&item_bytes)?; if block_ref.deleted.get() { @@ -155,29 +145,7 @@ impl Repair { }) .await?; } - - if *must_exit.borrow() { - break; - } } Ok(()) } - - #[allow(clippy::type_complexity)] - fn get_next_block_ref_after(&self, pos: &[u8]) -> Result<OptKVPair, Error> { - match self - .garage - .block_ref_table - .data - .store - .range::<&[u8], _>((Bound::Excluded(pos), Bound::Unbounded))? - .next() - { - None => Ok(None), - Some(item) => { - let (item_key, item_bytes) = item?; - Ok(Some((item_key.into_vec(), item_bytes.into_vec()))) - } - } - } } |