Abstract database behind generic interface and implement alternative drivers #322

Merged
lx merged 64 commits from db-abstraction into main 2022-06-08 08:01:56 +00:00
6 changed files with 18 additions and 32 deletions
Showing only changes of commit 0ab21e780e - Show all commits

View file

@ -10,9 +10,7 @@ use std::sync::{Arc, RwLock};
use heed::types::ByteSlice; use heed::types::ByteSlice;
use heed::{BytesDecode, Env, RoTxn, RwTxn, UntypedDatabase as Database}; use heed::{BytesDecode, Env, RoTxn, RwTxn, UntypedDatabase as Database};
use crate::{ use crate::{Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxResult, Value, ValueIter};
Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxResult, Value, ValueIter,
};
pub use heed; pub use heed;

View file

@ -9,9 +9,7 @@ use sled::transaction::{
UnabortableTransactionError, UnabortableTransactionError,
}; };
use crate::{ use crate::{Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxResult, Value, ValueIter};
Db, Error, IDb, ITx, ITxFn, Result, TxError, TxFnResult, TxResult, Value, ValueIter,
};
pub use sled; pub use sled;

View file

@ -67,13 +67,12 @@ impl Repair {
let mut i = 0; let mut i = 0;
while !*must_exit.borrow() { while !*must_exit.borrow() {
let item_bytes = { let item_bytes = match self.garage.version_table.data.store.get_gt(pos)? {
let (k, v) = match self.garage.version_table.data.store.get_gt(pos)? { Some((k, v)) => {
Some(pair) => pair, pos = k;
None => break, v
}; }
pos = k; None => break,
v
}; };
i += 1; i += 1;
@ -119,13 +118,12 @@ impl Repair {
let mut i = 0; let mut i = 0;
while !*must_exit.borrow() { while !*must_exit.borrow() {
let item_bytes = { let item_bytes = match self.garage.block_ref_table.data.store.get_gt(pos)? {
let (k, v) = match self.garage.block_ref_table.data.store.get_gt(pos)? { Some((k, v)) => {
Some(pair) => pair, pos = k;
None => break, v
}; }
pos = k; None => break,
v
}; };
i += 1; i += 1;

View file

@ -243,10 +243,7 @@ where
pub(crate) fn delete_if_equal(self: &Arc<Self>, k: &[u8], v: &[u8]) -> Result<bool, Error> { pub(crate) fn delete_if_equal(self: &Arc<Self>, k: &[u8], v: &[u8]) -> Result<bool, Error> {
let removed = self.store.db().transaction(|mut tx| { let removed = self.store.db().transaction(|mut tx| {
let remove = match tx.get(&self.store, k)? { let remove = matches!(tx.get(&self.store, k)?, Some(cur_v) if cur_v == v => true);
Some(cur_v) if cur_v == v => true,
_ => false,
};
if remove { if remove {
tx.remove(&self.store, k)?; tx.remove(&self.store, k)?;
tx.insert(&self.merkle_todo, k, vec![])?; tx.insert(&self.merkle_todo, k, vec![])?;

View file

@ -383,10 +383,8 @@ impl GcTodoEntry {
pub(crate) fn remove_if_equal(&self, gc_todo_tree: &db::Tree) -> Result<(), Error> { pub(crate) fn remove_if_equal(&self, gc_todo_tree: &db::Tree) -> Result<(), Error> {
let key = self.todo_table_key(); let key = self.todo_table_key();
gc_todo_tree.db().transaction(|mut tx| { gc_todo_tree.db().transaction(|mut tx| {
let remove = match tx.get(gc_todo_tree, &key)? { let remove =
Some(ov) if ov == self.value_hash.as_slice() => true, matches!(tx.get(gc_todo_tree, &key)? Some(ov) if ov == self.value_hash.as_slice());
_ => false,
};
if remove { if remove {
tx.remove(gc_todo_tree, &key)?; tx.remove(gc_todo_tree, &key)?;
} }

View file

@ -140,10 +140,7 @@ where
.transaction(|mut tx| self.update_item_rec(&mut tx, k, &khash, &key, new_vhash))?; .transaction(|mut tx| self.update_item_rec(&mut tx, k, &khash, &key, new_vhash))?;
let deleted = self.data.merkle_todo.db().transaction(|mut tx| { let deleted = self.data.merkle_todo.db().transaction(|mut tx| {
let remove = match tx.get(&self.data.merkle_todo, k)? { let remove = matches!(tx.get(&self.data.merkle_todo, k)?, Some(ov) if ov == vhash_by);
Some(ov) if ov == vhash_by => true,
_ => false,
};
if remove { if remove {
tx.remove(&self.data.merkle_todo, k)?; tx.remove(&self.data.merkle_todo, k)?;
} }