Append AND sync atomically. This is the primary durable write path.
(&self, audit_bytes: &[u8], data_lsn: u64)
| 82 | |
| 83 | /// Append AND sync atomically. This is the primary durable write path. |
| 84 | pub fn append_durable(&self, audit_bytes: &[u8], data_lsn: u64) -> crate::Result<u64> { |
| 85 | let mut wal = self.wal.lock().map_err(|_| crate::Error::Internal { |
| 86 | detail: "audit WAL lock poisoned".into(), |
| 87 | })?; |
| 88 | |
| 89 | let mut payload = Vec::with_capacity(8 + audit_bytes.len()); |
| 90 | payload.extend_from_slice(&data_lsn.to_le_bytes()); |
| 91 | payload.extend_from_slice(audit_bytes); |
| 92 | |
| 93 | let lsn = wal |
| 94 | .append(RecordType::Put as u32, 0, 0, 0, &payload) |
| 95 | .map_err(crate::Error::Wal)?; |
| 96 | wal.sync().map_err(crate::Error::Wal)?; |
| 97 | |
| 98 | Ok(lsn) |
| 99 | } |
| 100 | |
| 101 | /// Replay all audit WAL entries for crash recovery. |
| 102 | /// |