Skip to main content

RecordLogWriter

Struct RecordLogWriter 

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

Append-only record log writer.

Single-writer assumption: unlike crate::walog::WalWriter, this type does not use an advisory lockfile. Two writers on the same path will interleave writes and corrupt the log. Callers are responsible for ensuring at most one active writer per path.

§Example

use durability::recordlog::{RecordLogWriter, RecordLogReader, RecordLogReadMode};
use durability::storage::MemoryDirectory;

let dir = MemoryDirectory::arc();
let mut w = RecordLogWriter::new(dir.clone(), "log.bin");
w.append_postcard(&"hello").unwrap();
w.append_postcard(&"world").unwrap();
w.flush().unwrap();

let r = RecordLogReader::new(dir, "log.bin");
let msgs: Vec<String> = r.read_all_postcard(RecordLogReadMode::Strict).unwrap();
assert_eq!(msgs, vec!["hello", "world"]);

Implementations§

Source§

impl RecordLogWriter

Source

pub fn new(dir: impl Into<Arc<dyn Directory>>, path: impl Into<String>) -> Self

Create a record log writer that appends to path.

Source

pub fn with_flush_policy( dir: impl Into<Arc<dyn Directory>>, path: impl Into<String>, flush_policy: FlushPolicy, ) -> Self

Create a record log writer with an explicit flush policy.

Source

pub fn with_options( dir: impl Into<Arc<dyn Directory>>, path: impl Into<String>, flush_policy: FlushPolicy, write_buffer_limit_bytes: usize, ) -> Self

Create a record log writer with explicit flush policy and write buffer size.

write_buffer_limit_bytes == 0 disables buffering (writes are issued on each append).

Source

pub fn flush(&mut self) -> PersistenceResult<()>

Flush the underlying writer (if one is open).

Source

pub fn flush_and_sync(&mut self) -> PersistenceResult<()>

Flush buffered bytes and attempt to make the record log durable on stable storage.

This is an opt-in stronger guarantee than flush():

  • flush() is a visibility boundary (userspace → OS / underlying writer).
  • flush_and_sync() additionally calls sync_all on the underlying file.

Returns NotSupported if the underlying Directory does not provide file_path().

Source

pub fn append_bytes(&mut self, payload: &[u8]) -> PersistenceResult<()>

Append one record containing payload.

Source

pub fn append_postcard<T: Serialize>( &mut self, value: &T, ) -> PersistenceResult<()>

Append one postcard-encoded value as a record payload.

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.