Skip to content

Commit

Permalink
Use flush_header_and_range instead of flush_range
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 30, 2024
1 parent ece485f commit 34f8235
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ impl<C, S> Builder<C, S> {
/// use orderwal::Builder;
///
/// let options = Builder::new();
/// assert_eq!(options.sync_on_write(), true);
/// assert_eq!(options.sync(), true);
/// ```
#[inline]
pub const fn sync_on_write(&self) -> bool {
self.opts.sync_on_write()
pub const fn sync(&self) -> bool {
self.opts.sync()
}

/// Sets the capacity of the WAL.
Expand Down Expand Up @@ -316,12 +316,12 @@ impl<C, S> Builder<C, S> {
/// ```rust
/// use orderwal::Builder;
///
/// let options = Builder::new().with_sync_on_write(false);
/// assert_eq!(options.sync_on_write(), false);
/// let options = Builder::new().with_sync(false);
/// assert_eq!(options.sync(), false);
/// ```
#[inline]
pub const fn with_sync_on_write(mut self, sync: bool) -> Self {
self.opts = self.opts.with_sync_on_write(sync);
pub const fn with_sync(mut self, sync: bool) -> Self {
self.opts = self.opts.with_sync(sync);
self
}

Expand Down
18 changes: 9 additions & 9 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pub struct Options {
maximum_key_size: u32,
maximum_value_size: u32,
sync_on_write: bool,
sync: bool,
magic_version: u16,
cap: Option<u32>,
reserved: u32,
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Options {
Self {
maximum_key_size: u16::MAX as u32,
maximum_value_size: u32::MAX,
sync_on_write: true,
sync: true,
magic_version: 0,
huge: None,
cap: None,
Expand Down Expand Up @@ -229,11 +229,11 @@ impl Options {
/// use orderwal::Options;
///
/// let options = Options::new();
/// assert_eq!(options.sync_on_write(), true);
/// assert_eq!(options.sync(), true);
/// ```
#[inline]
pub const fn sync_on_write(&self) -> bool {
self.sync_on_write
pub const fn sync(&self) -> bool {
self.sync
}

/// Sets the capacity of the WAL.
Expand Down Expand Up @@ -297,12 +297,12 @@ impl Options {
/// ```rust
/// use orderwal::Options;
///
/// let options = Options::new().with_sync_on_write(false);
/// assert_eq!(options.sync_on_write(), false);
/// let options = Options::new().with_sync(false);
/// assert_eq!(options.sync(), false);
/// ```
#[inline]
pub const fn with_sync_on_write(mut self, sync: bool) -> Self {
self.sync_on_write = sync;
pub const fn with_sync(mut self, sync: bool) -> Self {
self.sync = sync;
self
}

Expand Down
8 changes: 4 additions & 4 deletions src/swmr/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,9 @@ where
buf[0] = committed_flag.bits;
let buf_cap = buf.capacity();

if self.core.opts.sync_on_write() && allocator.is_ondisk() {
if self.core.opts.sync() && allocator.is_ondisk() {
allocator
.flush_range(buf.offset(), buf_cap)
.flush_header_and_range(buf.offset(), buf_cap)
.map_err(|e| Among::Right(e.into()))?;
}
buf.detach();
Expand Down Expand Up @@ -903,11 +903,11 @@ where
// commit the entry
buf[0] |= Flags::COMMITTED.bits();

if self.core.opts.sync_on_write() && self.core.arena.is_ondisk() {
if self.core.opts.sync() && self.core.arena.is_ondisk() {
self
.core
.arena
.flush_range(buf.offset(), elen as usize)
.flush_header_and_range(buf.offset(), elen as usize)
.map_err(|e| Among::Right(e.into()))?;
}
buf.detach();
Expand Down
14 changes: 7 additions & 7 deletions src/swmr/generic/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ impl<S> GenericBuilder<S> {
/// use orderwal::swmr::GenericBuilder;
///
/// let options = GenericBuilder::new();
/// assert_eq!(options.sync_on_write(), true);
/// assert_eq!(options.sync(), true);
/// ```
#[inline]
pub const fn sync_on_write(&self) -> bool {
self.opts.sync_on_write()
pub const fn sync(&self) -> bool {
self.opts.sync()
}

/// Sets the capacity of the WAL.
Expand Down Expand Up @@ -250,12 +250,12 @@ impl<S> GenericBuilder<S> {
/// ```rust
/// use orderwal::swmr::GenericBuilder;
///
/// let options = GenericBuilder::new().with_sync_on_write(false);
/// assert_eq!(options.sync_on_write(), false);
/// let options = GenericBuilder::new().with_sync(false);
/// assert_eq!(options.sync(), false);
/// ```
#[inline]
pub const fn with_sync_on_write(mut self, sync: bool) -> Self {
self.opts = self.opts.with_sync_on_write(sync);
pub const fn with_sync(mut self, sync: bool) -> Self {
self.opts = self.opts.with_sync(sync);
self
}

Expand Down
4 changes: 2 additions & 2 deletions src/wal/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub trait Sealed<C, S>: Constructor<C, S> {
// commit the entry
buf[0] |= Flags::COMMITTED.bits();

if self.options().sync_on_write() && is_ondisk {
if self.options().sync() && is_ondisk {
allocator
.flush_header_and_range(buf.offset(), elen as usize)
.map_err(|e| Among::Right(e.into()))?;
Expand Down Expand Up @@ -395,7 +395,7 @@ trait SealedExt<C, S>: Sealed<C, S> {
buf[0] = committed_flag.bits;
let buf_cap = buf.capacity();

if self.options().sync_on_write() && allocator.is_ondisk() {
if self.options().sync() && allocator.is_ondisk() {
allocator.flush_header_and_range(buf.offset(), buf_cap)?;
}
buf.detach();
Expand Down

0 comments on commit 34f8235

Please sign in to comment.