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)
pub fn set_encryption_key(&mut self, key: WalEncryptionKey)
Set the encryption key. When set, all subsequent records will have their payloads encrypted with AES-256-GCM.
Sourcepub fn set_encryption_ring(&mut self, ring: KeyRing)
pub fn set_encryption_ring(&mut self, ring: KeyRing)
Set the key ring directly (for key rotation with dual-key reads).
Sourcepub fn encryption_ring(&self) -> Option<&KeyRing>
pub fn encryption_ring(&self) -> Option<&KeyRing>
Access the key ring (for decryption during replay).
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: u16,
tenant_id: u32,
vshard_id: u16,
payload: &[u8],
) -> Result<u64>
pub fn append( &mut self, record_type: u16, tenant_id: u32, vshard_id: u16, 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.
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).