garage_db: refactor transactions and add on_commit mechanism

This commit is contained in:
Alex Auvolat
2023-09-21 15:32:25 +02:00
parent fd7d8fec59
commit f97168f805
14 changed files with 86 additions and 84 deletions
+3 -3
View File
@@ -85,7 +85,7 @@ impl CountedTree {
let old_some = expected_old.is_some();
let new_some = new.is_some();
let tx_res = self.0.tree.db().transaction(|mut tx| {
let tx_res = self.0.tree.db().transaction(|tx| {
let old_val = tx.get(&self.0.tree, &key)?;
let is_same = match (&old_val, &expected_old) {
(None, None) => true,
@@ -101,9 +101,9 @@ impl CountedTree {
tx.remove(&self.0.tree, &key)?;
}
}
tx.commit(())
Ok(())
} else {
tx.abort(())
Err(TxError::Abort(()))
}
});