Skip to main content

SeqLog

Struct SeqLog 

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

SeqLog instance. It is also the Writer.

Implementations§

Source§

impl SeqLog

Source

pub fn create<P: AsRef<Path>>(path: P, start_seq: u64) -> Result<Self>

Create a SeqLog instance with start sequence number, and open it.

This requires that the parent directory of the given path already exists and the path itself does not exist.

This method creates the directory and some required files. If you want to create it out of your program, use this script:

mkdir $path
touch $path/LOCK
touch $path/`printf "%020d.data" $start_seq`   # first data file
touch $path/`printf "%020d.index" $start_seq`  # first index file
Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an existing SeqLog instance.

Source

pub fn append<T>(&mut self, entries: &[T]) -> Result<()>
where T: AsRef<[u8]>,

Append a batch of entries.

This issues one write(2) syscall. Therefore, appending in batches reduces the number of system calls.

This writes data into file (page cache), but does not synchronize disk. Use Self::sync or SeqLogSyncer if needed.

Source

pub fn purge(&mut self, seq: u64) -> Result<()>

Remove files containing only entries before the sequence number.

If a data file contains entries both before and after the sequence number, it will not be removed.

If a data file is in read by any reader, it will not be removed.

The current file is never removed.

Source

pub fn truncate(&mut self, seq: u64) -> Result<()>

Truncate entries from the sequence number, inclusive.

This does not check if any reader are reading these entries.

Source

pub fn next_seq(&self) -> u64

Return the next sequence number.

Source

pub fn sync_seq(&self) -> u64

Return the next sequence number to synchronize to disk.

This is the synchronization version of Self::next_seq.

Source

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

Synchronizes entries to disk.

Syncing data to disk is a relatively slow and blocking operation. If you do not want to block the current thread, create a SeqLogSyncer via Self::syncer and send it to another thread to perform synchronization there.

Source

pub fn syncer(&self) -> Result<SeqLogSyncer>

Create a SeqLogSyncer.

Source

pub fn reader(&self, next_seq: u64, synced_only: bool) -> Result<SeqLogReader>

Create a new SeqLogReader with the sequence number.

If synced_only is set to true, the reader will only read entries that have been synchronized to disk via Self::sync or SeqLogSyncer::sync.

Source

pub fn set_rotate(&mut self, size: usize, count: usize)

Configrate rotation.

size: Rotate a data file when it exceeds this size. The default value is 1G. Setting to 0 means never rotating, and you can call Self::rotate to rotate manaully.

count: Number of files to retain. The default value is 10. Setting to 0 means keeping all files, and you can call Self::purge to delete manually.

Source

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

Rotate the data file manually, e.g. by time or sequence number.

It does not rotate if the current file is empty.

You should have called Self::set_rotate with size=0 to disable the automatic rotation.

Auto Trait Implementations§

§

impl Forget for SeqLog

§

impl Freeze for SeqLog

§

impl Move for SeqLog

§

impl RefUnwindSafe for SeqLog

§

impl Send for SeqLog

§

impl Sync for SeqLog

§

impl Unpin for SeqLog

§

impl UnsafeUnpin for SeqLog

§

impl UnwindSafe for SeqLog

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.