diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-07 16:52:57 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-07 16:52:57 +0200 |
commit | a9e79f848b704347601e082c8065c3ce042b283b (patch) | |
tree | 940df323b35f402450225473a63a8ec73b86bc90 /src/db/lib.rs | |
parent | 5dbc79b77ebaec3778791f9882266fc809217f62 (diff) | |
download | garage-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/lib.rs')
-rw-r--r-- | src/db/lib.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/db/lib.rs b/src/db/lib.rs index afea9f55..4543e53c 100644 --- a/src/db/lib.rs +++ b/src/db/lib.rs @@ -2,6 +2,8 @@ pub mod lmdb_adapter; pub mod sled_adapter; pub mod sqlite_adapter; +pub mod counted_tree_hack; + #[cfg(test)] pub mod test; @@ -164,10 +166,13 @@ impl Tree { .transpose() } + /// True if item didn't exist before, false if item already existed + /// and was replaced. #[inline] - pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(&self, key: T, value: U) -> Result<()> { + pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(&self, key: T, value: U) -> Result<bool> { self.0.insert(self.1, key.as_ref(), value.as_ref()) } + /// True if item was removed, false if item already didn't exist #[inline] pub fn remove<T: AsRef<[u8]>>(&self, key: T) -> Result<bool> { self.0.remove(self.1, key.as_ref()) @@ -215,15 +220,18 @@ impl<'a> Transaction<'a> { self.0.len(tree.1) } + /// True if item didn't exist before, false if item already existed + /// and was replaced. #[inline] pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>( &mut self, tree: &Tree, key: T, value: U, - ) -> Result<()> { + ) -> Result<bool> { self.0.insert(tree.1, key.as_ref(), value.as_ref()) } + /// True if item was removed, false if item already didn't exist #[inline] pub fn remove<T: AsRef<[u8]>>(&mut self, tree: &Tree, key: T) -> Result<bool> { self.0.remove(tree.1, key.as_ref()) @@ -281,7 +289,7 @@ pub(crate) trait IDb: Send + Sync { fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>; fn len(&self, tree: usize) -> Result<usize>; - fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<()>; + fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool>; fn remove(&self, tree: usize, key: &[u8]) -> Result<bool>; fn iter(&self, tree: usize) -> Result<ValueIter<'_>>; @@ -307,7 +315,7 @@ pub(crate) trait ITx { fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>; fn len(&self, tree: usize) -> Result<usize>; - fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<()>; + fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool>; fn remove(&mut self, tree: usize, key: &[u8]) -> Result<bool>; fn iter(&self, tree: usize) -> Result<ValueIter<'_>>; |