aboutsummaryrefslogtreecommitdiff
path: root/src/table
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/table
parent364061453cd0a5a2e4f76f4194e6b5887aae7ed8 (diff)
downloadgarage-c439cb11a908ee5405ed0a3a721e9c8c0e299ad2.tar.gz
garage-c439cb11a908ee5405ed0a3a721e9c8c0e299ad2.zip
Sqlite iter with unsafe code
Diffstat (limited to 'src/table')
-rw-r--r--src/table/merkle.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/table/merkle.rs b/src/table/merkle.rs
index 4b0b44ce..6e0c2f7e 100644
--- a/src/table/merkle.rs
+++ b/src/table/merkle.rs
@@ -89,36 +89,36 @@ where
async fn updater_loop(self: Arc<Self>, mut must_exit: watch::Receiver<bool>) {
while !*must_exit.borrow() {
- if let Some(x) = self.data.merkle_todo.iter().unwrap().next() {
- // TODO unwrap to remove
- match x {
- Ok((key, valhash)) => {
- if let Err(e) = self.update_item(&key[..], &valhash[..]) {
- warn!(
- "({}) Error while updating Merkle tree item: {}",
- F::TABLE_NAME,
- e
- );
- }
- }
- Err(e) => {
- warn!(
- "({}) Error while iterating on Merkle todo tree: {}",
- F::TABLE_NAME,
- e
- );
- tokio::time::sleep(Duration::from_secs(10)).await;
+ match self.updater_loop_iter() {
+ Ok(true) => (),
+ Ok(false) => {
+ select! {
+ _ = self.data.merkle_todo_notify.notified().fuse() => {},
+ _ = must_exit.changed().fuse() => {},
}
}
- } else {
- select! {
- _ = self.data.merkle_todo_notify.notified().fuse() => {},
- _ = must_exit.changed().fuse() => {},
+ Err(e) => {
+ warn!(
+ "({}) Error while updating Merkle tree item: {}",
+ F::TABLE_NAME,
+ e
+ );
+ tokio::time::sleep(Duration::from_secs(10)).await;
}
}
}
}
+ fn updater_loop_iter(&self) -> Result<bool, Error> {
+ if let Some(x) = self.data.merkle_todo.iter()?.next() {
+ let (key, valhash) = x?;
+ self.update_item(&key[..], &valhash[..])?;
+ Ok(true)
+ } else {
+ Ok(false)
+ }
+ }
+
fn update_item(&self, k: &[u8], vhash_by: &[u8]) -> Result<(), Error> {
let khash = blake2sum(k);