Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 26, 2024
1 parent 329f988 commit 64fe3f7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
13 changes: 7 additions & 6 deletions src/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ pub trait Wal<K: ?Sized, V: ?Sized, S> {
/// ## Safety
/// - The caller must ensure that the there is no others accessing reserved slice for either read or write.
/// - This method is not thread-safe, so be careful when using it.
unsafe fn reserved_slice_mut<'a>(&'a mut self) -> &'a mut [u8]
#[allow(clippy::mut_from_ref)]
unsafe fn reserved_slice_mut<'a>(&'a self) -> &'a mut [u8]
where
Self::Allocator: 'a,
{
Expand Down Expand Up @@ -454,7 +455,7 @@ pub trait Wal<K: ?Sized, V: ?Sized, S> {
}

fn insert<KE, VE>(
&mut self,
&self,
version: Option<u64>,
kb: KE,
vb: VE,
Expand All @@ -470,7 +471,7 @@ pub trait Wal<K: ?Sized, V: ?Sized, S> {
}

fn remove<KE>(
&mut self,
&self,
version: Option<u64>,
kb: KE,
) -> Result<(), Either<KE::Error, Error<Self::Memtable>>>
Expand Down Expand Up @@ -504,7 +505,7 @@ pub trait Wal<K: ?Sized, V: ?Sized, S> {
}

fn update<KE, VE>(
&mut self,
&self,
version: Option<u64>,
kb: KE,
vb: Option<VE>,
Expand Down Expand Up @@ -638,7 +639,7 @@ pub trait Wal<K: ?Sized, V: ?Sized, S> {
}

fn insert_batch<W, B>(
&mut self,
&self,
batch: &mut B,
) -> Result<
(),
Expand Down Expand Up @@ -885,7 +886,7 @@ pub trait Constructable<K: ?Sized, V: ?Sized>: Sized {

fn as_wal(&self) -> &Self::Wal;

fn as_wal_mut(&mut self) -> &mut Self::Wal;
// fn as_wal_mut(&mut self) -> &mut Self::Wal;

fn new_in(
arena: Self::Allocator,
Expand Down
13 changes: 6 additions & 7 deletions src/swmr/reader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::cell::UnsafeCell;
use std::sync::Arc;

use rarena_allocator::sync::Arena;
Expand All @@ -23,7 +22,7 @@ where
{
/// Creates a new read-only WAL reader.
#[inline]
pub(super) fn new(wal: Arc<UnsafeCell<OrderCore<K, V, P, S>>>) -> Self {
pub(super) fn new(wal: Arc<OrderCore<K, V, P, S>>) -> Self {
Self(GenericOrderWal::construct(wal))
}
}
Expand All @@ -47,15 +46,15 @@ where
self.0.as_wal()
}

#[inline]
fn as_wal_mut(&mut self) -> &mut Self::Wal {
self.0.as_wal_mut()
}
// #[inline]
// fn as_wal_mut(&mut self) -> &mut Self::Wal {
// self.0.as_wal_mut()
// }

#[inline]
fn from_core(core: Self::Wal) -> Self {
Self(GenericOrderWal {

Check warning on line 56 in src/swmr/reader.rs

View check run for this annotation

Codecov / codecov/patch

src/swmr/reader.rs#L56

Added line #L56 was not covered by tests
core: Arc::new(UnsafeCell::new(core)),
core: Arc::new(core),
})
}
}
17 changes: 8 additions & 9 deletions src/swmr/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use crate::{
use dbutils::{checksum::Crc32, traits::Type};
use rarena_allocator::{sync::Arena, Allocator};

use core::cell::UnsafeCell;
use std::sync::Arc;

use super::{reader::GenericOrderWalReader, wal::OrderCore};

/// A ordered write-ahead log implementation for concurrent thread environments.
pub struct GenericOrderWal<K: ?Sized, V: ?Sized, M, S = Crc32> {
pub(super) core: Arc<UnsafeCell<OrderCore<K, V, M, S>>>,
pub(super) core: Arc<OrderCore<K, V, M, S>>,
}

unsafe impl<K: ?Sized, V: ?Sized, M: Send, S: Send> Send for GenericOrderWal<K, V, M, S> {}
Expand All @@ -24,7 +23,7 @@ unsafe impl<K: ?Sized, V: ?Sized, M: Send + Sync, S: Send + Sync> Sync

impl<K: ?Sized, V: ?Sized, P, S> GenericOrderWal<K, V, P, S> {
#[inline]
pub(super) const fn construct(core: Arc<UnsafeCell<OrderCore<K, V, P, S>>>) -> Self {
pub(super) const fn construct(core: Arc<OrderCore<K, V, P, S>>) -> Self {
Self { core }
}
}
Expand All @@ -45,18 +44,18 @@ where

#[inline]
fn as_wal(&self) -> &Self::Wal {
unsafe { &*self.core.get() }
&self.core
}

#[inline]
fn as_wal_mut(&mut self) -> &mut Self::Wal {
unsafe { &mut *self.core.get() }
}
// #[inline]
// fn as_wal_mut(&mut self) -> &mut Self::Wal {
// unsafe { &mut *self.core.get() }
// }

#[inline]
fn from_core(core: Self::Wal) -> Self {
Self {
core: Arc::new(UnsafeCell::new(core)),
core: Arc::new(core),
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/wal/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ where
where
Self::Allocator: 'a,
{
self.as_wal_mut().reserved_slice_mut()
self.as_wal().reserved_slice_mut()
}

/// Flushes the to disk.
Expand Down Expand Up @@ -432,7 +432,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(None, kb, value.into())
self.as_wal().insert(None, kb, value.into())

Check warning on line 435 in src/wal/base.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/base.rs#L435

Added line #L435 was not covered by tests
}

/// Inserts a key-value pair into the WAL. This method
Expand All @@ -451,7 +451,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(None, key.into(), vb)
self.as_wal().insert(None, key.into(), vb)
}

/// Inserts a key-value pair into the WAL. This method
Expand All @@ -468,7 +468,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(None, kb, vb)
self.as_wal().insert(None, kb, vb)
}

/// Inserts a key-value pair into the WAL.
Expand All @@ -484,7 +484,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(None, key.into(), value.into())
self.as_wal().insert(None, key.into(), value.into())
}

/// Removes a key-value pair from the WAL. This method
Expand All @@ -499,7 +499,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().remove(None, kb)
self.as_wal().remove(None, kb)

Check warning on line 502 in src/wal/base.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/base.rs#L502

Added line #L502 was not covered by tests
}

/// Removes a key-value pair from the WAL.
Expand All @@ -513,7 +513,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().remove(None, key.into())
self.as_wal().remove(None, key.into())

Check warning on line 516 in src/wal/base.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/base.rs#L516

Added line #L516 was not covered by tests
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -533,7 +533,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -550,7 +550,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -567,7 +567,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -583,6 +583,6 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)
}
}
22 changes: 11 additions & 11 deletions src/wal/multiple_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ where
where
Self::Allocator: 'a,
{
self.as_wal_mut().reserved_slice_mut()
self.as_wal().reserved_slice_mut()

Check warning on line 530 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L530

Added line #L530 was not covered by tests
}

/// Flushes the to disk.
Expand Down Expand Up @@ -562,7 +562,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(Some(version), kb, value.into())
self.as_wal().insert(Some(version), kb, value.into())

Check warning on line 565 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L565

Added line #L565 was not covered by tests
}

/// Inserts a key-value pair into the WAL. This method
Expand All @@ -582,7 +582,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(Some(version), key.into(), vb)
self.as_wal().insert(Some(version), key.into(), vb)

Check warning on line 585 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L585

Added line #L585 was not covered by tests
}

/// Inserts a key-value pair into the WAL. This method
Expand All @@ -600,7 +600,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert(Some(version), kb, vb)
self.as_wal().insert(Some(version), kb, vb)

Check warning on line 603 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L603

Added line #L603 was not covered by tests
}

/// Inserts a key-value pair into the WAL.
Expand All @@ -618,7 +618,7 @@ where
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self

Check warning on line 620 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L620

Added line #L620 was not covered by tests
.as_wal_mut()
.as_wal()
.insert(Some(version), key.into(), value.into())

Check warning on line 622 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L622

Added line #L622 was not covered by tests
}

Expand All @@ -635,7 +635,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().remove(Some(version), kb)
self.as_wal().remove(Some(version), kb)

Check warning on line 638 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L638

Added line #L638 was not covered by tests
}

/// Removes a key-value pair from the WAL.
Expand All @@ -650,7 +650,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().remove(Some(version), key.into())
self.as_wal().remove(Some(version), key.into())

Check warning on line 653 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L653

Added line #L653 was not covered by tests
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -670,7 +670,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)

Check warning on line 673 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L673

Added line #L673 was not covered by tests
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -687,7 +687,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)

Check warning on line 690 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L690

Added line #L690 was not covered by tests
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -704,7 +704,7 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)

Check warning on line 707 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L707

Added line #L707 was not covered by tests
}

/// Inserts a batch of key-value pairs into the WAL.
Expand All @@ -720,6 +720,6 @@ where
Self::Checksumer: BuildChecksumer,
<Self::Memtable as memtable::BaseTable>::Pointer: Pointer + Ord + 'static,
{
self.as_wal_mut().insert_batch::<Self, _>(batch)
self.as_wal().insert_batch::<Self, _>(batch)

Check warning on line 723 in src/wal/multiple_version.rs

View check run for this annotation

Codecov / codecov/patch

src/wal/multiple_version.rs#L723

Added line #L723 was not covered by tests
}
}

0 comments on commit 64fe3f7

Please sign in to comment.