Append a record to the WAL. Returns the assigned LSN. If the active segment has exceeded the target size, a new segment is created before appending. The rollover is transparent to the caller. `database_id` is stored in header bytes 34-41. Pass `0` for the default database (backward-compatible with pre-existing records).
(
&mut self,
record_type: u32,
tenant_id: u64,
vshard_id: u32,
database_id: u64,
payload: &[u8],
)
| 156 | /// `database_id` is stored in header bytes 34-41. Pass `0` for the |
| 157 | /// default database (backward-compatible with pre-existing records). |
| 158 | pub fn append( |
| 159 | &mut self, |
| 160 | record_type: u32, |
| 161 | tenant_id: u64, |
| 162 | vshard_id: u32, |
| 163 | database_id: u64, |
| 164 | payload: &[u8], |
| 165 | ) -> Result<u64> { |
| 166 | // Check if we need to roll to a new segment. |
| 167 | if self.writer.file_offset() >= self.segment_target_size { |
| 168 | self.roll_segment()?; |
| 169 | } |
| 170 | |
| 171 | self.writer |
| 172 | .append(record_type, tenant_id, vshard_id, database_id, payload) |
| 173 | } |
| 174 | |
| 175 | /// Flush all buffered records and fsync the active segment. |
| 176 | pub fn sync(&mut self) -> Result<()> { |