pub struct WalRecord {
pub header: RecordHeader,
pub payload: Vec<u8>,
}Expand description
A complete WAL record: header + payload.
Fields§
§header: RecordHeader§payload: Vec<u8>Implementations§
Source§impl WalRecord
impl WalRecord
Sourcepub fn new(
record_type: u32,
lsn: u64,
tenant_id: u64,
vshard_id: u32,
database_id: u64,
payload: Vec<u8>,
encryption_key: Option<&WalEncryptionKey>,
preamble_bytes: Option<&[u8; 16]>,
) -> Result<Self>
pub fn new( record_type: u32, lsn: u64, tenant_id: u64, vshard_id: u32, database_id: u64, payload: Vec<u8>, encryption_key: Option<&WalEncryptionKey>, preamble_bytes: Option<&[u8; 16]>, ) -> Result<Self>
Create a new WAL record with computed CRC32C.
If encryption_key is provided, the payload is encrypted before
CRC computation. The ciphertext includes a 16-byte auth tag.
preamble_bytes — when encryption is active, the 16-byte segment
preamble that was written at offset 0 of this segment file. It is
concatenated with the record header bytes to form the AAD, binding
the ciphertext to its segment (preamble-swap defense). Pass None
for unencrypted records (the argument is ignored in that case).
database_id is stored in header bytes 34-41 (previously reserved,
zero-filled). Pre-existing records with zeros decode to DatabaseId(0)
(the default database), preserving backward compatibility.
Sourcepub fn decrypt_payload(
&self,
epoch: &[u8; 4],
preamble_bytes: Option<&[u8; 16]>,
encryption_key: Option<&WalEncryptionKey>,
) -> Result<Vec<u8>>
pub fn decrypt_payload( &self, epoch: &[u8; 4], preamble_bytes: Option<&[u8; 16]>, encryption_key: Option<&WalEncryptionKey>, ) -> Result<Vec<u8>>
Decrypt the payload if the record is encrypted.
epoch must come from the on-disk segment preamble, not from the
current in-memory key. preamble_bytes must be the same 16-byte
preamble that was used as part of the AAD during encryption.
Sourcepub fn decrypt_payload_ring(
&self,
epoch: &[u8; 4],
preamble_bytes: Option<&[u8; 16]>,
ring: Option<&KeyRing>,
) -> Result<Vec<u8>>
pub fn decrypt_payload_ring( &self, epoch: &[u8; 4], preamble_bytes: Option<&[u8; 16]>, ring: Option<&KeyRing>, ) -> Result<Vec<u8>>
Decrypt the payload using a key ring (supports dual-key rotation).
epoch must come from the on-disk segment preamble. preamble_bytes
must match the preamble bytes written at the start of this segment.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Whether this record’s payload is encrypted.
Sourcepub fn logical_record_type(&self) -> u32
pub fn logical_record_type(&self) -> u32
Logical record type with the encryption flag stripped.
Sourcepub fn verify_checksum(&self) -> Result<()>
pub fn verify_checksum(&self) -> Result<()>
Verify the CRC32C checksum.