Skip to content

Commit

Permalink
upgrade value-log
Browse files Browse the repository at this point in the history
to use Slice::from_reader
  • Loading branch information
marvin-j97 committed Nov 13, 2024
1 parent 15d46a4 commit c33a9d8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "lsm-tree"
description = "A K.I.S.S. implementation of log-structured merge trees (LSM-trees/LSMTs)"
license = "MIT OR Apache-2.0"
version = "2.3.2"
version = "2.3.3"
edition = "2021"
rust-version = "1.74.0"
readme = "README.md"
Expand Down Expand Up @@ -37,7 +37,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.1.1"
value-log = "1.2.0"
varint-rs = "2.2.0"
xxhash-rust = { version = "0.8.12", features = ["xxh3"] }

Expand Down
2 changes: 2 additions & 0 deletions src/blob_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ impl AbstractTree for BlobTree {
if item.is_tombstone() {
// NOTE: Still need to add tombstone to index tree
// But no blob to blob writer

// TODO: Slice::empty
segment_writer.write(InternalValue::new(item.key, vec![]))?;
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions src/blob_tree/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ impl Decode for MaybeInlineValue {
match tag {
TAG_INLINE => {
let len = reader.read_u32_varint()? as usize;
let mut bytes = vec![0; len];
reader.read_exact(&mut bytes)?;
Ok(Self::Inline(Slice::from(bytes)))
let slice = Slice::from_reader(reader, len)?;
Ok(Self::Inline(slice))
}
TAG_INDIRECT => {
let vhandle = ValueHandle::decode_from(reader)?;
Expand Down
6 changes: 3 additions & 3 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
cmp::Reverse,
io::{Read, Write},
};
use value_log::Slice;
use varint_rs::{VarintReader, VarintWriter};

#[derive(Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -43,7 +44,7 @@ impl InternalKey {

assert!(
user_key.len() <= u16::MAX.into(),
"keys can be 65535 bytes in length"
"keys can be 65535 bytes in length",
);

Self {
Expand Down Expand Up @@ -83,8 +84,7 @@ impl Decode for InternalKey {
.map_err(|()| DecodeError::InvalidTag(("ValueType", value_type)))?;

let key_len = reader.read_u16_varint()?;
let mut key = vec![0; key_len.into()];
reader.read_exact(&mut key)?;
let key = Slice::from_reader(reader, key_len.into())?;

Ok(Self::new(key, seqno, value_type))
}
Expand Down
8 changes: 2 additions & 6 deletions src/key_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,10 @@ impl Encode for KeyRange {
impl Decode for KeyRange {
fn decode_from<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
let key_min_len = reader.read_u16::<BigEndian>()?;
let mut key_min = vec![0; key_min_len.into()];
reader.read_exact(&mut key_min)?;
let key_min: UserKey = Slice::from(key_min);
let key_min: UserKey = Slice::from_reader(reader, key_min_len.into())?;

let key_max_len = reader.read_u16::<BigEndian>()?;
let mut key_max = vec![0; key_max_len.into()];
reader.read_exact(&mut key_max)?;
let key_max: UserKey = Slice::from(key_max);
let key_max: UserKey = Slice::from_reader(reader, key_max_len.into())?;

Ok(Self::new((key_min, key_max)))
}
Expand Down
11 changes: 3 additions & 8 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ impl InternalValue {
///
/// Panics if the key length is empty or greater than 2^16.
pub fn new_tombstone<K: Into<UserKey>>(key: K, seqno: u64) -> Self {
let key = key.into();
let key = InternalKey::new(key, seqno, ValueType::Tombstone);
Self::new(key, vec![])
}
Expand All @@ -128,7 +127,6 @@ impl InternalValue {
///
/// Panics if the key length is empty or greater than 2^16.
pub fn new_weak_tombstone<K: Into<UserKey>>(key: K, seqno: u64) -> Self {
let key = key.into();
let key = InternalKey::new(key, seqno, ValueType::WeakTombstone);
Self::new(key, vec![])
}
Expand Down Expand Up @@ -187,19 +185,16 @@ impl Decode for InternalValue {
if key.is_tombstone() {
Ok(Self {
key,
// TODO: Slice::empty()
value: vec![].into(),
})
} else {
// NOTE: Only read value if we are actually a value

let value_len = reader.read_u32_varint()?;
let mut value = vec![0; value_len as usize];
reader.read_exact(&mut value)?;
let value = Slice::from_reader(reader, value_len as usize)?;

Ok(Self {
key,
value: value.into(),
})
Ok(Self { key, value })
}
}
}
Expand Down

0 comments on commit c33a9d8

Please sign in to comment.