pub struct WalWriter { /* private fields */ }Expand description
Append-only WAL writer.
Implementations§
Source§impl WalWriter
impl WalWriter
Sourcepub fn open(path: &Path, config: WalWriterConfig) -> Result<Self>
pub fn open(path: &Path, config: WalWriterConfig) -> Result<Self>
Open or create a WAL file at the given path.
Sourcepub fn set_encryption_key(&mut self, key: WalEncryptionKey) -> Result<()>
pub fn set_encryption_key(&mut self, key: WalEncryptionKey) -> Result<()>
Set the encryption key. When set, all subsequent records will have their payloads encrypted with AES-256-GCM.
Writes the 16-byte WAL segment preamble at the current file offset.
Must be called before the first append. Calling it after records
have already been written to this file returns an error.
Sourcepub fn set_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
pub fn set_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
Set the key ring directly (for key rotation with dual-key reads).
Writes the 16-byte WAL segment preamble at the current file offset.
Must be called before the first append. Calling it after records
have already been written to this file returns an error.
Sourcepub fn encryption_ring(&self) -> Option<&KeyRing>
pub fn encryption_ring(&self) -> Option<&KeyRing>
Access the key ring (for decryption during replay).
Sourcepub fn segment_preamble(&self) -> Option<&SegmentPreamble>
pub fn segment_preamble(&self) -> Option<&SegmentPreamble>
The preamble for this segment, if encryption was enabled.
Sourcepub fn open_with_start_lsn(
path: &Path,
config: WalWriterConfig,
start_lsn: u64,
) -> Result<Self>
pub fn open_with_start_lsn( path: &Path, config: WalWriterConfig, start_lsn: u64, ) -> Result<Self>
Open a new WAL segment file with a specific starting LSN.
Used by SegmentedWal when rolling to a new segment. The file must
not already exist (or be empty). The writer will assign LSNs starting
from start_lsn.
Sourcepub fn open_without_direct_io(path: &Path) -> Result<Self>
pub fn open_without_direct_io(path: &Path) -> Result<Self>
Open a WAL writer with O_DIRECT disabled (for testing on tmpfs, etc.).
Sourcepub fn append(
&mut self,
record_type: u32,
tenant_id: u64,
vshard_id: u32,
database_id: u64,
payload: &[u8],
) -> Result<u64>
pub fn append( &mut self, record_type: u32, tenant_id: u64, vshard_id: u32, database_id: u64, payload: &[u8], ) -> Result<u64>
Append a record to the WAL. Returns the assigned LSN.
The record is written to the in-memory buffer. Call sync() to
flush to disk and make the write durable.
database_id is stored in header bytes 34-41. Pass 0 for the
default database (backward-compatible with pre-existing records).
Sourcepub fn sync(&mut self) -> Result<()>
pub fn sync(&mut self) -> Result<()>
Flush the write buffer to disk (group commit).
This issues a single write + fsync for all records accumulated since the last flush. The DWB is also fsynced (one fsync for all deferred DWB writes in this batch).
Sourcepub fn seal(&mut self) -> Result<()>
pub fn seal(&mut self) -> Result<()>
Seal the WAL — no more writes will be accepted.
Flushes any buffered data before sealing.
Sourcepub fn file_offset(&self) -> u64
pub fn file_offset(&self) -> u64
Current file size (bytes written to disk).
Auto Trait Implementations§
impl !Freeze for WalWriter
impl !Sync for WalWriter
impl RefUnwindSafe for WalWriter
impl Send for WalWriter
impl Unpin for WalWriter
impl UnsafeUnpin for WalWriter
impl UnwindSafe for WalWriter
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.