Skip to content

Commit

Permalink
Set maximum key size to u27::MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 30, 2024
1 parent 1fab5db commit 9f825ec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- Refactor the project to make all of the WALs based on the generic implementation.
- Support different memtables based on [`crossbeam-skiplist`](https://github.com/crossbeam-rs/crossbeam) or [`skl`](https://github.com/al8n/skl)
- More user-friendly APIs
- Support freeze `Wal`s to `FrozenOrderWal`.

## 0.4.0 (Sep 30th, 2024)

Expand Down
18 changes: 9 additions & 9 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dbutils::{
checksum::Crc32,
traits::{KeyRef, Type},
};
use skl::either::Either;
use skl::{either::Either, KeySize};

use super::{
checksum::BuildChecksumer,
Expand Down Expand Up @@ -276,13 +276,13 @@ where
/// ## Example
///
/// ```rust
/// use orderwal::{Builder, multiple_version::LinkedTable};
/// use orderwal::{Builder, KeySize, multiple_version::LinkedTable};
///
/// let options = Builder::<LinkedTable<[u8], [u8]>>::new().with_maximum_key_size(1024);
/// assert_eq!(options.maximum_key_size(), 1024);
/// let options = Builder::<LinkedTable<[u8], [u8]>>::new().with_maximum_key_size(KeySize::with(1024));
/// assert_eq!(options.maximum_key_size(), KeySize::with(1024));
/// ```
#[inline]
pub const fn maximum_key_size(&self) -> u32 {
pub const fn maximum_key_size(&self) -> KeySize {
self.opts.maximum_key_size()
}

Expand Down Expand Up @@ -345,13 +345,13 @@ where
/// ## Example
///
/// ```rust
/// use orderwal::{Builder, multiple_version::LinkedTable};
/// use orderwal::{Builder, KeySize, multiple_version::LinkedTable};
///
/// let options = Builder::<LinkedTable<[u8], [u8]>>::new().with_maximum_key_size(1024);
/// assert_eq!(options.maximum_key_size(), 1024);
/// let options = Builder::<LinkedTable<[u8], [u8]>>::new().with_maximum_key_size(KeySize::with(1024));
/// assert_eq!(options.maximum_key_size(), KeySize::with(1024));
/// ```
#[inline]
pub const fn with_maximum_key_size(mut self, size: u32) -> Self {
pub const fn with_maximum_key_size(mut self, size: KeySize) -> Self {
self.opts = self.opts.with_maximum_key_size(size);
self
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub mod types;

mod options;
pub use options::Options;
pub use skl::KeySize;

/// Batch insertions related traits and structs.
pub mod batch;
Expand Down
23 changes: 11 additions & 12 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use rarena_allocator::{Freelist, Options as ArenaOptions};
// use skl::Height;
pub use skl::KeySize;

use super::{CURRENT_VERSION, HEADER_SIZE};

/// Options for the WAL.
#[derive(Debug, Clone)]
pub struct Options {
maximum_key_size: u32,
maximum_key_size: KeySize,
maximum_value_size: u32,
// maximum_height: Height,
sync: bool,
magic_version: u16,
cap: Option<u32>,
Expand Down Expand Up @@ -50,7 +49,7 @@ impl Options {
#[inline]
pub const fn new() -> Self {
Self {
maximum_key_size: u16::MAX as u32,
maximum_key_size: KeySize::new(),
maximum_value_size: u32::MAX,
sync: true,
magic_version: 0,
Expand Down Expand Up @@ -198,13 +197,13 @@ impl Options {
/// ## Example
///
/// ```rust
/// use orderwal::Options;
/// use orderwal::{Options, KeySize};
///
/// let options = Options::new().with_maximum_key_size(1024);
/// assert_eq!(options.maximum_key_size(), 1024);
/// let options = Options::new().with_maximum_key_size(KeySize::with(1024));
/// assert_eq!(options.maximum_key_size(), KeySize::with(1024));
/// ```
#[inline]
pub const fn maximum_key_size(&self) -> u32 {
pub const fn maximum_key_size(&self) -> KeySize {
self.maximum_key_size
}

Expand Down Expand Up @@ -267,13 +266,13 @@ impl Options {
/// ## Example
///
/// ```rust
/// use orderwal::Options;
/// use orderwal::{Options, KeySize};
///
/// let options = Options::new().with_maximum_key_size(1024);
/// assert_eq!(options.maximum_key_size(), 1024);
/// let options = Options::new().with_maximum_key_size(KeySize::with(1024));
/// assert_eq!(options.maximum_key_size(), KeySize::with(1024));
/// ```
#[inline]
pub const fn with_maximum_key_size(mut self, size: u32) -> Self {
pub const fn with_maximum_key_size(mut self, size: KeySize) -> Self {
self.maximum_key_size = size;
self
}
Expand Down
7 changes: 4 additions & 3 deletions src/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use dbutils::{
traits::{KeyRef, Type},
};
use rarena_allocator::{either::Either, Allocator, ArenaPosition, Buffer};
use skl::KeySize;

use crate::{
memtable::{MemtableEntry, MultipleVersionMemtableEntry},
Expand Down Expand Up @@ -457,7 +458,7 @@ pub trait Wal<S> {

/// Returns the maximum key size allowed in the WAL.
#[inline]
fn maximum_key_size(&self) -> u32 {
fn maximum_key_size(&self) -> KeySize {
self.options().maximum_key_size()
}

Expand Down Expand Up @@ -685,7 +686,7 @@ pub trait Wal<S> {
klen,
vlen,
version.is_some(),
self.maximum_key_size(),
self.maximum_key_size().to_u32(),
self.maximum_value_size(),
self.read_only(),
)
Expand Down Expand Up @@ -817,7 +818,7 @@ pub trait Wal<S> {
}

let opts = self.options();
let maximum_key_size = opts.maximum_key_size();
let maximum_key_size = opts.maximum_key_size().to_u32();
let minimum_value_size = opts.maximum_value_size();
let start_offset = unsafe {
let (mut cursor, allocator, mut buf) = batch
Expand Down
4 changes: 2 additions & 2 deletions src/wal/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dbutils::{
};
use rarena_allocator::Allocator;
use ref_cast::RefCast;
use skl::either::Either;
use skl::{either::Either, KeySize};

use crate::{
batch::Batch,
Expand Down Expand Up @@ -69,7 +69,7 @@ pub trait Reader: Constructable {

/// Returns the maximum key size allowed in the WAL.
#[inline]
fn maximum_key_size(&self) -> u32 {
fn maximum_key_size(&self) -> KeySize {
self.as_wal().maximum_key_size()
}

Expand Down
4 changes: 2 additions & 2 deletions src/wal/multiple_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dbutils::{
};
use rarena_allocator::Allocator;
use ref_cast::RefCast;
use skl::either::Either;
use skl::{either::Either, KeySize};

use crate::{
batch::Batch,
Expand Down Expand Up @@ -48,7 +48,7 @@ pub trait Reader: Constructable {

/// Returns the maximum key size allowed in the WAL.
#[inline]
fn maximum_key_size(&self) -> u32 {
fn maximum_key_size(&self) -> KeySize {
self.as_wal().maximum_key_size()
}

Expand Down

0 comments on commit 9f825ec

Please sign in to comment.