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).