Skip to content

Commit

Permalink
Bumpup version
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 8, 2024
1 parent 8747a34 commit c151987
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 125 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 50

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ harness = false

[features]
default = ["std"]
std = ["rarena-allocator/default", "crossbeam-skiplist/default", "bitflags/default", "dbutils/default", "among/default", "faststr?/default", "bytes?/default", "smol_str?/default"]
std = ["rarena-allocator/default", "crossbeam-skiplist/default", "bitflags/std", "dbutils/default", "among/default", "faststr?/default", "bytes?/default", "smol_str?/default"]

xxhash3 = ["dbutils/xxhash3", "std"]
xxhash64 = ["dbutils/xxhash64", "std"]
Expand All @@ -27,8 +27,8 @@ tracing = ["dep:tracing", "dbutils/tracing"]

[dependencies]
among = { version = "0.1", default-features = false, features = ["either"] }
bitflags = { version = "1", default-features = false }
dbutils = { version = "0.4", default-features = false, features = ["crc32fast"] }
bitflags = { version = "2", default-features = false }
dbutils = { version = "0.6", default-features = false, features = ["crc32fast"] }
ref-cast = "1"
rarena-allocator = { version = "0.4", default-features = false, features = ["memmap"] }
crossbeam-skiplist = { version = "0.1", default-features = false, package = "crossbeam-skiplist-pr1132" }
Expand Down
10 changes: 9 additions & 1 deletion examples/zero_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,25 @@ impl<'a> KeyRef<'a, Person> for PersonRef<'a> {

impl Type for Person {
type Ref<'a> = PersonRef<'a>;
type Error = dbutils::leb128::EncodeVarintError;
type Error = dbutils::error::InsufficientBuffer;

fn encoded_len(&self) -> usize {
encoded_u64_varint_len(self.id) + self.name.len()
}

#[inline]
fn encode(&self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let id_size = encode_u64_varint(self.id, buf)?;
buf[id_size..].copy_from_slice(self.name.as_bytes());
Ok(id_size + self.name.len())
}

#[inline]
fn encode_to_buffer(&self, buf: &mut orderwal::VacantBuffer<'_>) -> Result<usize, Self::Error> {
let id_size = buf.put_u64_varint(self.id)?;
buf.put_slice_unchecked(self.name.as_bytes());
Ok(id_size + self.name.len())
}
}

impl<'a> TypeRef<'a> for PersonRef<'a> {
Expand Down
19 changes: 19 additions & 0 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::borrow::Borrow;

use crossbeam_skiplist::set::Entry as SetEntry;
use dbutils::{
buffer::VacantBuffer,
equivalent::{Comparable, Equivalent},
traits::{KeyRef, Type, TypeRef},
};
Expand Down Expand Up @@ -321,6 +322,9 @@ impl<'a, T: 'a + Type + ?Sized> Generic<'a, T> {
}

/// Encodes the generic into the buffer.
///
/// ## Panics
/// - if the buffer is not large enough.
#[inline]
pub fn encode(&self, buf: &mut [u8]) -> Result<usize, T::Error> {
match &self.data {
Expand All @@ -331,6 +335,21 @@ impl<'a, T: 'a + Type + ?Sized> Generic<'a, T> {
}
}
}

/// Encodes the generic into the given buffer.
///
/// ## Panics
/// - if the buffer is not large enough.
#[inline]
pub fn encode_to_buffer(&self, buf: &mut VacantBuffer<'_>) -> Result<usize, T::Error> {
match &self.data {
Either::Left(val) => val.encode_to_buffer(buf),
Either::Right(val) => {
buf.put_slice_unchecked(val);
Ok(buf.len())
}
}
}
}

impl<'a, T: 'a + ?Sized> Generic<'a, T> {
Expand Down
6 changes: 0 additions & 6 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ impl Options {
/// assert_eq!(opts.read(), true);
/// ```
#[inline]

pub const fn read(&self) -> bool {
self.read
}
Expand All @@ -579,7 +578,6 @@ impl Options {
/// assert_eq!(opts.write(), true);
/// ```
#[inline]

pub const fn write(&self) -> bool {
self.write
}
Expand All @@ -595,7 +593,6 @@ impl Options {
/// assert_eq!(opts.append(), true);
/// ```
#[inline]

pub const fn append(&self) -> bool {
self.append
}
Expand All @@ -611,7 +608,6 @@ impl Options {
/// assert_eq!(opts.truncate(), true);
/// ```
#[inline]

pub const fn truncate(&self) -> bool {
self.truncate
}
Expand All @@ -627,7 +623,6 @@ impl Options {
/// assert_eq!(opts.create(), true);
/// ```
#[inline]

pub const fn create(&self) -> bool {
self.create
}
Expand All @@ -643,7 +638,6 @@ impl Options {
/// assert_eq!(opts.create_new(), true);
/// ```
#[inline]

pub const fn create_new(&self) -> bool {
self.create_new
}
Expand Down
48 changes: 13 additions & 35 deletions src/swmr/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,17 +612,12 @@ where
Some(e) => e,
None => {
let klen = key.encoded_len() as u32;
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| {
buf.set_len(klen as usize);
key.encode(buf).map(|_| ())
});
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| key.encode_to_buffer(buf).map(|_| ()));

let val: Generic<'_, V> = val.into();
let vlen = val.encoded_len() as u32;
let vb: ValueBuilder<_> = ValueBuilder::once(vlen, |buf| {
buf.set_len(vlen as usize);
val.encode(buf).map(|_| ())
});
let vb: ValueBuilder<_> =
ValueBuilder::once(vlen, |buf| val.encode_to_buffer(buf).map(|_| ()));

Either::Right(self.insert_in(kb, vb))
}
Expand Down Expand Up @@ -650,16 +645,11 @@ where
Some(e) => e,
None => {
let klen = key.encoded_len() as u32;
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| {
buf.set_len(klen as usize);
key.encode(buf).map(|_| ())
});
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| key.encode_to_buffer(buf).map(|_| ()));
let val = value();
let vlen = val.encoded_len() as u32;
let vb: ValueBuilder<_> = ValueBuilder::once(vlen, |buf| {
buf.set_len(vlen as usize);
val.encode(buf).map(|_| ())
});
let vb: ValueBuilder<_> =
ValueBuilder::once(vlen, |buf| val.encode_to_buffer(buf).map(|_| ()));

Either::Right(self.insert_in(kb, vb))
}
Expand Down Expand Up @@ -736,7 +726,7 @@ macro_rules! process_batch {

let flag = Flags::BATCHING;

buf.put_u8_unchecked(flag.bits);
buf.put_u8_unchecked(flag.bits());
buf.put_u64_varint_unchecked(batch_meta);

let mut cursor = 1 + batch_meta_size;
Expand Down Expand Up @@ -832,17 +822,11 @@ where
{
let key: Generic<'_, K> = key.into();
let klen = key.encoded_len() as u32;
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| {
buf.set_len(klen as usize);
key.encode(buf).map(|_| ())
});
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| key.encode_to_buffer(buf).map(|_| ()));

let val: Generic<'_, V> = val.into();
let vlen = val.encoded_len() as u32;
let vb: ValueBuilder<_> = ValueBuilder::once(vlen, |buf| {
buf.set_len(vlen as usize);
val.encode(buf).map(|_| ())
});
let vb: ValueBuilder<_> = ValueBuilder::once(vlen, |buf| val.encode_to_buffer(buf).map(|_| ()));
self.insert_in(kb, vb)
}

Expand All @@ -868,10 +852,7 @@ where
{
let val: Generic<'_, V> = val.into();
let vlen = val.encoded_len() as u32;
let vb = ValueBuilder::once(vlen, |buf| {
buf.set_len(vlen as usize);
val.encode(buf).map(|_| ())
});
let vb = ValueBuilder::once(vlen, |buf| val.encode_to_buffer(buf).map(|_| ()));

self.insert_in(kb, vb)
}
Expand All @@ -898,10 +879,7 @@ where
{
let key: Generic<'_, K> = key.into();
let klen = key.encoded_len() as u32;
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| {
buf.set_len(klen as usize);
key.encode(buf).map(|_| ())
});
let kb: KeyBuilder<_> = KeyBuilder::once(klen, |buf| key.encode_to_buffer(buf).map(|_| ()));

self.insert_in::<K::Error, E>(kb, vb)
}
Expand Down Expand Up @@ -1063,13 +1041,13 @@ where

let mut cks = self.core.cks.build_checksumer();
let committed_flag = Flags::BATCHING | Flags::COMMITTED;
cks.update(&[committed_flag.bits]);
cks.update(&[committed_flag.bits()]);
cks.update(&buf[1..]);
let checksum = cks.digest();
buf.put_u64_le_unchecked(checksum);

// commit the entry
buf[0] = committed_flag.bits;
buf[0] = committed_flag.bits();
let buf_cap = buf.capacity();

if self.core.opts.sync() && allocator.is_ondisk() {
Expand Down
14 changes: 12 additions & 2 deletions src/swmr/generic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl KeyRef<'_, Person> for PersonRef<'_> {

impl Type for Person {
type Ref<'a> = PersonRef<'a>;
type Error = dbutils::leb128::EncodeVarintError;
type Error = dbutils::error::InsufficientBuffer;

fn encoded_len(&self) -> usize {
encoded_u64_varint_len(self.id) + self.name.len()
Expand All @@ -148,6 +148,16 @@ impl Type for Person {
buf[id_size..].copy_from_slice(self.name.as_bytes());
Ok(id_size + self.name.len())
}

#[inline]
fn encode_to_buffer(
&self,
buf: &mut dbutils::buffer::VacantBuffer<'_>,
) -> Result<usize, Self::Error> {
let id_size = buf.put_u64_varint(self.id)?;
buf.put_slice_unchecked(self.name.as_bytes());
Ok(id_size + self.name.len())
}
}

impl<'a> TypeRef<'a> for PersonRef<'a> {
Expand All @@ -161,7 +171,7 @@ impl<'a> TypeRef<'a> for PersonRef<'a> {
impl PersonRef<'_> {
#[cfg(test)]
#[allow(dead_code)]
fn encode_into_vec(&self) -> Result<Vec<u8>, dbutils::leb128::EncodeVarintError> {
fn encode_into_vec(&self) -> Result<Vec<u8>, dbutils::error::InsufficientBuffer> {
let mut buf = vec![0; encoded_u64_varint_len(self.id) + self.name.len()];
let id_size = encode_u64_varint(self.id, &mut buf)?;
buf[id_size..].copy_from_slice(self.name.as_bytes());
Expand Down
3 changes: 1 addition & 2 deletions src/swmr/generic/tests/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ fn insert_with_key_builder(wal: &mut GenericOrderWal<Person, String>) -> Vec<Per
wal
.insert_with_key_builder(
KeyBuilder::new(p.encoded_len() as u32, |buf: &mut VacantBuffer<'_>| {
buf.set_len(p.encoded_len());
p.encode(buf).map(|_| ())
p.encode_to_buffer(buf).map(|_| ())
}),
&format!("My name is {}", p.name),
)
Expand Down
57 changes: 36 additions & 21 deletions src/swmr/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,33 +176,48 @@ impl<C, S> ImmutableWal<C, S> for OrderWal<C, S>
where
C: Comparator + CheapClone + Send + 'static,
{
type Iter<'a> = Iter<'a, C> where Self: 'a, C: Comparator;
type Range<'a, Q, R> = Range<'a, Q, R, C>
type Iter<'a>
= Iter<'a, C>
where
Self: 'a,
C: Comparator;
type Range<'a, Q, R>
= Range<'a, Q, R, C>
where
R: core::ops::RangeBounds<Q>,
[u8]: Borrow<Q>,
Q: Ord + ?Sized,
Self: 'a,
C: Comparator;
type Keys<'a>
= Keys<'a, C>
where
Self: 'a,
C: Comparator;

type RangeKeys<'a, Q, R>
= RangeKeys<'a, Q, R, C>
where
R: core::ops::RangeBounds<Q>,
[u8]: Borrow<Q>,
Q: Ord + ?Sized,
Self: 'a,
C: Comparator;

type Values<'a>
= Values<'a, C>
where
Self: 'a,
C: Comparator;

type RangeValues<'a, Q, R>
= RangeValues<'a, Q, R, C>
where
R: core::ops::RangeBounds<Q>,
[u8]: Borrow<Q>,
Q: Ord + ?Sized,
Self: 'a,
C: Comparator;
type Keys<'a> = Keys<'a, C> where Self: 'a, C: Comparator;

type RangeKeys<'a, Q, R> = RangeKeys<'a, Q, R, C>
where
R: core::ops::RangeBounds<Q>,
[u8]: Borrow<Q>,
Q: Ord + ?Sized,
Self: 'a,
C: Comparator;

type Values<'a> = Values<'a, C> where Self: 'a, C: Comparator;

type RangeValues<'a, Q, R> = RangeValues<'a, Q, R, C>
where
R: core::ops::RangeBounds<Q>,
[u8]: Borrow<Q>,
Q: Ord + ?Sized,
Self: 'a,
C: Comparator;

#[inline]
fn path(&self) -> Option<&std::path::Path> {
Expand Down
Loading

0 comments on commit c151987

Please sign in to comment.