Skip to main content

LogWriter

Struct LogWriter 

pub struct LogWriter { /* private fields */ }
Expand description

Appends records to a shard log in memory. Assigns LSNs, interns names per segment and decides segment boundaries. Pure: no files.

Implementations§

§

impl LogWriter

pub fn new( shard: u32, segment: u64, next_lsn: Lsn, segment_bytes: u64, now_ms: u64, ) -> Self

Starts a new segment segment whose first record will be next_lsn.

pub fn next_lsn(&self) -> Lsn

pub fn last_lsn(&self) -> Lsn

pub fn segment(&self) -> u64

pub fn segment_bytes(&self) -> u64

pub fn limit_first_segment(&mut self, bytes: u64)

The segment opened at recovery may be smaller. Later segments retain their configured capacity and the maximum record size is unchanged.

pub fn offset(&self) -> u64

Bytes used in the current segment.

pub fn has_pending(&self) -> bool

Whether records or a new segment’s header wait for a flush. The header of the segment an open starts is flushed on its own: replicated mode anchors a checkpoint on the batch that ends at the checkpoint’s position, which must lie in a segment the checkpoint keeps. A header alone holds no record, so the next open may replace that segment.

pub fn pending_records(&self) -> u32

pub fn append<S: AsRef<str>, B: AsRef<[u8]>>( &mut self, rec: &Record<S, B>, now_ms: u64, ) -> Result<Lsn, TooLarge>

Appends one record and returns its LSN.

pub fn take(&mut self) -> Option<Batch>

Takes everything appended since the last call.

pub fn roll(&mut self, now_ms: u64)

Ends the current segment; the next append starts a new one.

pub fn segment_first_lsn(&self, segment: u64) -> Option<Lsn>

First LSN of each segment written by this writer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.