aboutsummaryrefslogtreecommitdiff
path: root/src/db/lmdb_adapter.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-07 16:52:57 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-07 16:52:57 +0200
commita9e79f848b704347601e082c8065c3ce042b283b (patch)
tree940df323b35f402450225473a63a8ec73b86bc90 /src/db/lmdb_adapter.rs
parent5dbc79b77ebaec3778791f9882266fc809217f62 (diff)
downloadgarage-a9e79f848b704347601e082c8065c3ce042b283b.tar.gz
garage-a9e79f848b704347601e082c8065c3ce042b283b.zip
Bring back the counted tree hack for Sled (with caveat)
caveat: it's not only for sled
Diffstat (limited to 'src/db/lmdb_adapter.rs')
-rw-r--r--src/db/lmdb_adapter.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/db/lmdb_adapter.rs b/src/db/lmdb_adapter.rs
index 3f468128..d8e5bcd3 100644
--- a/src/db/lmdb_adapter.rs
+++ b/src/db/lmdb_adapter.rs
@@ -122,12 +122,13 @@ impl IDb for LmdbDb {
Ok(tree.len(&tx)?.try_into().unwrap())
}
- fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<()> {
+ fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool> {
let tree = self.get_tree(tree)?;
let mut tx = self.db.write_txn()?;
+ let old_val = tree.get(&tx, key)?.map(Vec::from);
tree.put(&mut tx, key, value)?;
tx.commit()?;
- Ok(())
+ Ok(old_val.is_none())
}
fn iter(&self, tree: usize) -> Result<ValueIter<'_>> {
@@ -221,10 +222,11 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> {
unimplemented!(".len() in transaction not supported with LMDB backend")
}
- fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<()> {
+ fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool> {
let tree = *self.get_tree(tree)?;
+ let old_val = tree.get(&self.tx, key)?.map(Vec::from);
tree.put(&mut self.tx, key, value)?;
- Ok(())
+ Ok(old_val.is_none())
}
fn remove(&mut self, tree: usize, key: &[u8]) -> Result<bool> {
let tree = *self.get_tree(tree)?;