From 168d4e040bcc440155702e10bbb5f455345ec68f Mon Sep 17 00:00:00 2001 From: Carl Sverre <82591+carlsverre@users.noreply.github.com> Date: Tue, 3 Dec 2024 16:32:14 -0800 Subject: [PATCH 1/2] better zero copy support from types that implement Into --- src/abstract.rs | 13 +++++++++---- src/blob_tree/mod.rs | 19 ++++++++++++------- src/tree/mod.rs | 22 +++++++++++++--------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/abstract.rs b/src/abstract.rs index b2c6bad6..e4d1a8b8 100644 --- a/src/abstract.rs +++ b/src/abstract.rs @@ -581,10 +581,15 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn insert, V: AsRef<[u8]>>(&self, key: K, value: V, seqno: SeqNo) -> (u32, u32); + fn insert, V: Into>( + &self, + key: K, + value: V, + seqno: SeqNo, + ) -> (u32, u32); /// Inserts a key-value pair. - fn raw_insert_with_lock, V: AsRef<[u8]>>( + fn raw_insert_with_lock, V: Into>( &self, lock: &RwLockWriteGuard<'_, Memtable>, key: K, @@ -620,7 +625,7 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32); + fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32); /// Removes an item from the tree. /// @@ -654,5 +659,5 @@ pub trait AbstractTree { /// # Errors /// /// Will return `Err` if an IO error occurs. - fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32); + fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32); } diff --git a/src/blob_tree/mod.rs b/src/blob_tree/mod.rs index c2e183db..ae8a8e84 100644 --- a/src/blob_tree/mod.rs +++ b/src/blob_tree/mod.rs @@ -600,7 +600,7 @@ impl AbstractTree for BlobTree { ) } - fn raw_insert_with_lock, V: AsRef<[u8]>>( + fn raw_insert_with_lock, V: Into>( &self, lock: &RwLockWriteGuard<'_, Memtable>, key: K, @@ -613,21 +613,26 @@ impl AbstractTree for BlobTree { // NOTE: Initially, we always write an inline value // On memtable flush, depending on the values' sizes, they will be separated // into inline or indirect values - let item = MaybeInlineValue::Inline(value.as_ref().into()); + let item = MaybeInlineValue::Inline(value.into()); let value = item.encode_into_vec(); - let value = InternalValue::from_components(key.as_ref(), value, seqno, r#type); + let value = InternalValue::from_components(key, value, seqno, r#type); lock.insert(value) } - fn insert, V: AsRef<[u8]>>(&self, key: K, value: V, seqno: SeqNo) -> (u32, u32) { + fn insert, V: Into>( + &self, + key: K, + value: V, + seqno: SeqNo, + ) -> (u32, u32) { use value::MaybeInlineValue; // NOTE: Initially, we always write an inline value // On memtable flush, depending on the values' sizes, they will be separated // into inline or indirect values - let item = MaybeInlineValue::Inline(value.as_ref().into()); + let item = MaybeInlineValue::Inline(value.into()); let value = item.encode_into_vec(); @@ -684,11 +689,11 @@ impl AbstractTree for BlobTree { } } - fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32) { + fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32) { self.index.remove(key, seqno) } - fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32) { + fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32) { self.index.remove_weak(key, seqno) } } diff --git a/src/tree/mod.rs b/src/tree/mod.rs index dc1e245e..c0a0a3f8 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -407,13 +407,17 @@ impl AbstractTree for Tree { Box::new(self.create_prefix(prefix, None, None)) } - fn insert, V: AsRef<[u8]>>(&self, key: K, value: V, seqno: SeqNo) -> (u32, u32) { - let value = - InternalValue::from_components(key.as_ref(), value.as_ref(), seqno, ValueType::Value); + fn insert, V: Into>( + &self, + key: K, + value: V, + seqno: SeqNo, + ) -> (u32, u32) { + let value = InternalValue::from_components(key, value, seqno, ValueType::Value); self.append_entry(value) } - fn raw_insert_with_lock, V: AsRef<[u8]>>( + fn raw_insert_with_lock, V: Into>( &self, lock: &RwLockWriteGuard<'_, Memtable>, key: K, @@ -421,17 +425,17 @@ impl AbstractTree for Tree { seqno: SeqNo, r#type: ValueType, ) -> (u32, u32) { - let value = InternalValue::from_components(key.as_ref(), value.as_ref(), seqno, r#type); + let value = InternalValue::from_components(key, value, seqno, r#type); lock.insert(value) } - fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32) { - let value = InternalValue::new_tombstone(key.as_ref(), seqno); + fn remove>(&self, key: K, seqno: SeqNo) -> (u32, u32) { + let value = InternalValue::new_tombstone(key, seqno); self.append_entry(value) } - fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32) { - let value = InternalValue::new_weak_tombstone(key.as_ref(), seqno); + fn remove_weak>(&self, key: K, seqno: SeqNo) -> (u32, u32) { + let value = InternalValue::new_weak_tombstone(key, seqno); self.append_entry(value) } } From ec3e1b9689baa31020bdbf5d1c6905565955d08b Mon Sep 17 00:00:00 2001 From: Marvin <33938500+marvin-j97@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:28:00 +0100 Subject: [PATCH 2/2] update value-log --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 19432559..71342e33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ quick_cache = { version = "0.6.5", default-features = false, features = [] } rustc-hash = "2.0.0" self_cell = "1.0.4" tempfile = "3.12.0" -value-log = "1.3.0" +value-log = "1.4.0" varint-rs = "2.2.0" xxhash-rust = { version = "0.8.12", features = ["xxh3"] }