Skip to main content

FileTransitionLog

Struct FileTransitionLog 

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

Append-only, line-oriented transitions log backed by a single file.

Appending costs one write and one fsync regardless of how many entries the log already holds. Retention policies compact it through compact_log_entries, which writes the retained entries to <path>.compact, syncs it and renames it over the log, so the journal on disk stays bounded (issue #195).

§Durability

With sync_on_append enabled (the default) every append_log_entry returns only after the entry has reached stable storage, which is what makes the write-ahead ordering of the transactions layer meaningful: a transition is always durable before the data-store write it describes is reported as committed. Disabling it trades that guarantee for throughput — the log is then durable only as far as the last flush_log.

An interrupted append can leave a partial final line. Opening the log, or reading, appending or flushing after a writer I/O error, repairs that suffix before proceeding. A failed repair is retried on the next operation. Complete records remain intact, including records written before an error was returned; callers must discover an uncertain transaction’s outcome rather than blindly retry it. Repair scans backwards with an 8 KiB buffer; successful operations do not rescan. This framing protocol assumes storage honors flush and does not prove device-sector atomicity after power loss.

Implementations§

Source§

impl FileTransitionLog

Source

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

Opens (creating if needed) the log at path, discarding a trailing entry left half-written by a crash.

Source

pub fn open_exclusive<P: AsRef<Path>>(path: P) -> Result<Self, LinkError>

Holds the conventional sidecar lock until drop. Contention fails fast; all writers must follow the same advisory locking convention.

Source

pub fn path(&self) -> &Path

Path of the backing file.

Source

pub fn sync_on_append(&self) -> bool

Whether every append is fsynced. Enabled by default.

Source

pub fn set_sync_on_append(&mut self, value: bool)

Turns per-append fsync on or off — see the durability notes.

Trait Implementations§

Source§

impl Debug for FileTransitionLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ReplaceableTransitionLogStore for FileTransitionLog

Source§

fn replace_log_entries(&mut self, entries: &[String]) -> Result<bool, LinkError>

Returns false when an identical committed journal needs no replacement. Pending unflushed records must be rejected before changing durable state.
Source§

fn supports_replacement(&self) -> bool

Dynamic adapters can expose the capability only when their inner log can.
Source§

impl TransitionLogStore for FileTransitionLog

Source§

fn supports_durable_flush(&self) -> bool

Whether flush requests persistent storage. Custom/volatile logs default to false; this describes an adapter, not the reliability of its hardware.
Source§

fn supports_compaction(&self) -> bool

Whether compact_log_entries can rewrite the durable journal. Retention uses it to bound the journal on disk; logs without it keep every entry, as before.
Source§

fn compact_log_entries(&mut self, entries: &[String]) -> Result<(), LinkError>

Atomically and durably replaces every entry with entries, the retained journal. After a crash the log holds either the old or the new journal, never a mixture. Called only between transactions and only when supports_compaction is true.
Source§

fn append_log_entry(&mut self, entry: &str) -> Result<(), LinkError>

Appends one entry. Entries never contain newlines.
Source§

fn read_log_entries(&mut self) -> Result<Vec<String>, LinkError>

Reads every entry back, oldest first.
Source§

fn flush_log(&mut self) -> Result<(), LinkError>

Makes every appended entry durable.

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

Source§

type Output = T

Should always be Self
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.