Struct RotateLog

Source
pub struct RotateLog { /* private fields */ }
Expand description

A collection of Logs that get rotated or deleted automatically when they exceed size or count limits.

Writes go to the active Log. Reads scan through all Logs.

Implementations§

Source§

impl RotateLog

Source

pub fn append(&mut self, data: impl AsRef<[u8]>) -> Result<()>

Append data to the writable Log.

Source

pub fn lookup( &self, index_id: usize, key: impl Into<Bytes>, ) -> Result<RotateLogLookupIter<'_>>

Look up an entry using the given index. The index_id is the index of index_defs stored in OpenOptions.

Source

pub fn slice_to_bytes(&self, slice: &[u8]) -> Bytes

Convert a slice to Bytes.

Do not copy the slice if it’s from the main on-disk buffer of one of the loaded logs.

Source

pub fn lookup_latest( &self, index_id: usize, key: impl AsRef<[u8]>, ) -> Result<LogLookupIter<'_>>

Look up an entry using the given index. The index_id is the index of index_defs stored in OpenOptions.

Unlike RotateLog::lookup, this function only checks the “latest” (i.e. “writable”) Log without checking others. It is useful to make sure certain contents depending on other entries are inserted into the same Log.

Practically, a flush_filter should also be used to make sure dependent entries are stored in a same Log. So this function will panic if flush_filter is not set on OpenOptions.

Source

pub fn sync(&mut self) -> Result<u8>

Read latest data from disk. Write in-memory entries to disk.

Return the index of the latest Log.

For in-memory RotateLog, this function always returns 0.

Source

pub fn remove_old_logs(&mut self) -> Result<()>

Attempt to remove outdated logs.

Does nothing if the content of the ‘latest’ file has changed on disk, which indicates rotation was triggered elsewhere, or the RotateLog is in-memory.

Source

pub fn is_changed_on_disk(&self) -> bool

Returns true if sync will load more data on disk.

This function is optimized to be called frequently. It does not access the filesystem directly, but communicate using a shared mmap buffer.

This is not about testing buffered pending changes. To access buffered pending changes, use RotateLog::iter_dirty instead.

Source

pub fn flush(&mut self) -> Result<u8>

Renamed. Use RotateLog::sync instead.

Source

pub fn iter(&self) -> impl Iterator<Item = Result<&[u8]>>

Iterate over all the entries.

The entries are returned in FIFO order.

Source

pub fn iter_dirty(&self) -> impl Iterator<Item = Result<&[u8]>>

Iterate over all dirty entries.

Trait Implementations§

Source§

impl RotateLowLevelExt for RotateLog

Source§

fn logs(&self) -> Vec<&Log>

Get a view of all individual logs. Newest first.
Source§

fn force_rotate(&mut self) -> Result<()>

Forced rotate. This can be useful as a quick way to ensure new data can be written when data corruption happens. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more