pub struct VersionedLog { /* private fields */ }Expand description
A transaction log split into per-lease-version files for HA append
isolation (see docs/design/log-and-transactor.md).
The active writer under lease version V appends only to
{name}.v{V}.log (the pre-HA {name}.log reads as version 0). Readers
merge the files in version order and drop any record in an older file
whose t is at or past the first record of a later file: such records
were appended by a deposed writer after a takeover and were never
acknowledged, because acknowledgement re-verifies lease ownership after
the durable append. A deposed writer therefore cannot corrupt or fork
the log — its stale appends land in a file nobody considers current.
Implementations§
Source§impl VersionedLog
impl VersionedLog
Sourcepub fn open(
dir: impl AsRef<Path>,
name: &str,
write_version: u64,
) -> Result<Self, LogError>
pub fn open( dir: impl AsRef<Path>, name: &str, write_version: u64, ) -> Result<Self, LogError>
Opens the log for writing under write_version, creating the
version file if needed and dropping any torn tail it carries.
Files of other versions are never modified.
§Errors
Returns an error if files cannot be read/created or a fully written record is corrupt.
Sourcepub fn open_sealed(
dir: impl AsRef<Path>,
name: &str,
write_version: u64,
cipher: Arc<LogCipher>,
) -> Result<Self, LogError>
pub fn open_sealed( dir: impl AsRef<Path>, name: &str, write_version: u64, cipher: Arc<LogCipher>, ) -> Result<Self, LogError>
Opens the log for writing with record payloads sealed under cipher.
Every version file is read through the same cipher, and each frame is authenticated against the version of the file holding it.
§Errors
Returns an error if files cannot be read/created, a fully written record is corrupt, or a record cannot be authenticated.
Sourcepub fn open_read_only(
dir: impl AsRef<Path>,
name: &str,
) -> Result<Self, LogError>
pub fn open_read_only( dir: impl AsRef<Path>, name: &str, ) -> Result<Self, LogError>
Opens the log read-only (independent inspection or backup); appends fail.
§Errors
Returns an error when the directory cannot be read or a fully written record is corrupt.
Sourcepub fn open_read_only_sealed(
dir: impl AsRef<Path>,
name: &str,
cipher: Arc<LogCipher>,
) -> Result<Self, LogError>
pub fn open_read_only_sealed( dir: impl AsRef<Path>, name: &str, cipher: Arc<LogCipher>, ) -> Result<Self, LogError>
Opens the log read-only, opening sealed record payloads with cipher.
§Errors
Returns an error when the directory cannot be read, a fully written record is corrupt, or a record cannot be authenticated.
Trait Implementations§
Source§impl TransactionLog for VersionedLog
impl TransactionLog for VersionedLog
Source§fn append(&self, record: &TxRecord) -> Result<(), LogError>
fn append(&self, record: &TxRecord) -> Result<(), LogError>
Source§fn tx_range(
&self,
start: u64,
end: Option<u64>,
) -> Result<Vec<TxRecord>, LogError>
fn tx_range( &self, start: u64, end: Option<u64>, ) -> Result<Vec<TxRecord>, LogError>
[start, end). Read moreSource§fn append_async<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 TxRecord,
) -> Pin<Box<dyn Future<Output = Result<(), LogError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn append_async<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 TxRecord,
) -> Pin<Box<dyn Future<Output = Result<(), LogError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self::append by default;
storage-backed logs override this method and await their backend. Read moreSource§fn append_batch_async<'life0, 'life1, 'async_trait>(
&'life0 self,
records: &'life1 [TxRecord],
) -> Pin<Box<dyn Future<Output = Result<(), LogError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn append_batch_async<'life0, 'life1, 'async_trait>(
&'life0 self,
records: &'life1 [TxRecord],
) -> Pin<Box<dyn Future<Output = Result<(), LogError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fsync, one
object, one database transaction), so group commit amortizes the
per-append cost across the batch. records must be contiguous in t
starting at the log’s next expected t; an empty slice is a no-op. The
default appends them one at a time; batching backends override this. Read more