Skip to content

Commit

Permalink
Remove getter/setter from Segment, we can access private fields directly
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Sep 15, 2023
1 parent 3a59461 commit 022ab10
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ impl Segment {
unsafe { self.mmap.as_mut_slice() }
}

fn flush_offset(&self) -> usize {
self.flush_offset
}

fn set_flush_offset(&mut self, offset: usize) {
self.flush_offset = offset;
}

/// Returns the segment entry at the specified index, or `None` if no such
/// entry exists.
pub fn entry(&self, index: usize) -> Option<Entry> {
Expand Down Expand Up @@ -430,7 +422,7 @@ impl Segment {
// flush new elements added since last flush
trace!("{:?}: flushing byte range [{}, {})", self, start, end);
let mut view = unsafe { self.mmap.clone() };
self.set_flush_offset(end);
self.flush_offset = end;
view.restrict(start, end - start)?;
view.flush()
}
Expand All @@ -439,7 +431,7 @@ impl Segment {
// register new flush offset & flush the whole segment
trace!("{:?}: flushing after truncation", self);
let view = unsafe { self.mmap.clone() };
self.set_flush_offset(end);
self.flush_offset = end;
view.flush()
}
}
Expand All @@ -448,15 +440,15 @@ impl Segment {
/// Flushes recently written entries to durable storage.
pub fn flush_async(&mut self) -> thread::JoinHandle<Result<()>> {
trace!("{:?}: async flushing", self);
let start = self.flush_offset();
let start = self.flush_offset;
let end = self.size();

match start.cmp(&end) {
Ordering::Equal => thread::spawn(move || Ok(())), // nothing to flush
Ordering::Less => {
// flush new elements added since last flush
let mut view = unsafe { self.mmap.clone() };
self.set_flush_offset(end);
self.flush_offset = end;

let log_msg = if log_enabled!(log::Level::Trace) {
format!(
Expand All @@ -476,7 +468,7 @@ impl Segment {
// most likely truncated in between flushes
// register new flush offset & flush the whole segment
let view = unsafe { self.mmap.clone() };
self.set_flush_offset(end);
self.flush_offset = end;

let log_msg = if log_enabled!(log::Level::Trace) {
format!("{:?}: async flushing after truncation", &self)
Expand Down

0 comments on commit 022ab10

Please sign in to comment.