pub struct SeqLog { /* private fields */ }Expand description
SeqLog instance. It is also the Writer.
Implementations§
Source§impl SeqLog
impl SeqLog
Sourcepub fn create<P: AsRef<Path>>(path: P, start_seq: u64) -> Result<Self>
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 fileSourcepub fn append<T>(&mut self, entries: &[T]) -> Result<()>
pub fn append<T>(&mut self, entries: &[T]) -> Result<()>
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.
Sourcepub fn purge(&mut self, seq: u64) -> Result<()>
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.
Sourcepub fn truncate(&mut self, seq: u64) -> Result<()>
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.
Sourcepub fn sync_seq(&self) -> u64
pub fn sync_seq(&self) -> u64
Return the next sequence number to synchronize to disk.
This is the synchronization version of Self::next_seq.
Sourcepub fn sync(&self) -> Result<()>
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.
Sourcepub fn syncer(&self) -> Result<SeqLogSyncer>
pub fn syncer(&self) -> Result<SeqLogSyncer>
Create a SeqLogSyncer.
Sourcepub fn reader(&self, next_seq: u64, synced_only: bool) -> Result<SeqLogReader>
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.
Sourcepub fn set_rotate(&mut self, size: usize, count: usize)
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.
Sourcepub fn rotate(&mut self) -> Result<()>
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.