aboutsummaryrefslogtreecommitdiff
path: root/src/garage/repair.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-02 23:14:10 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-02 23:14:10 +0200
commitc439cb11a908ee5405ed0a3a721e9c8c0e299ad2 (patch)
tree65835f8c9b47d0670d1461fc43f358fc73850414 /src/garage/repair.rs
parent364061453cd0a5a2e4f76f4194e6b5887aae7ed8 (diff)
downloadgarage-c439cb11a908ee5405ed0a3a721e9c8c0e299ad2.tar.gz
garage-c439cb11a908ee5405ed0a3a721e9c8c0e299ad2.zip
Sqlite iter with unsafe code
Diffstat (limited to 'src/garage/repair.rs')
-rw-r--r--src/garage/repair.rs57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/garage/repair.rs b/src/garage/repair.rs
index 04d9ee72..762a8300 100644
--- a/src/garage/repair.rs
+++ b/src/garage/repair.rs
@@ -66,18 +66,10 @@ impl Repair {
async fn repair_versions(&self, must_exit: &watch::Receiver<bool>) -> Result<(), Error> {
let mut pos = vec![];
- while let Some(item) = self
- .garage
- .version_table
- .data
- .store
- .range((Bound::Excluded(pos), Bound::Unbounded))?
- .next()
- {
- let (item_key, item_bytes) = item?;
- pos = item_key.to_vec();
+ while let Some((item_key, item_bytes)) = self.get_next_version_after(&pos)? {
+ pos = item_key;
- let version = rmp_serde::decode::from_read_ref::<_, Version>(item_bytes.as_ref())?;
+ let version = rmp_serde::decode::from_read_ref::<_, Version>(&item_bytes)?;
if version.deleted.get() {
continue;
}
@@ -113,22 +105,30 @@ impl Repair {
Ok(())
}
- async fn repair_block_ref(&self, must_exit: &watch::Receiver<bool>) -> Result<(), Error> {
- let mut pos = vec![];
-
- while let Some(item) = self
+ fn get_next_version_after(&self, pos: &[u8]) -> Result<Option<(Vec<u8>, Vec<u8>)>, Error> {
+ match self
.garage
- .block_ref_table
+ .version_table
.data
.store
- .range((Bound::Excluded(pos), Bound::Unbounded))?
+ .range::<&[u8], _>((Bound::Excluded(pos), Bound::Unbounded))?
.next()
{
- let (item_key, item_bytes) = item?;
+ None => Ok(None),
+ Some(item) => {
+ let (item_key, item_bytes) = item?;
+ Ok(Some((item_key.into_owned(), item_bytes.into_owned())))
+ }
+ }
+ }
- pos = item_key.to_vec();
+ async fn repair_block_ref(&self, must_exit: &watch::Receiver<bool>) -> Result<(), Error> {
+ let mut pos = vec![];
- let block_ref = rmp_serde::decode::from_read_ref::<_, BlockRef>(item_bytes.as_ref())?;
+ while let Some((item_key, item_bytes)) = self.get_next_block_ref_after(&pos)? {
+ pos = item_key;
+
+ let block_ref = rmp_serde::decode::from_read_ref::<_, BlockRef>(&item_bytes)?;
if block_ref.deleted.get() {
continue;
}
@@ -160,4 +160,21 @@ impl Repair {
}
Ok(())
}
+
+ fn get_next_block_ref_after(&self, pos: &[u8]) -> Result<Option<(Vec<u8>, Vec<u8>)>, 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_owned(), item_bytes.into_owned())))
+ }
+ }
+ }
}