Write a WAL entry to persistent storage
(&self, entry: WALEntry)
| 471 | |
| 472 | /// Write a WAL entry to persistent storage |
| 473 | pub fn write_entry(&self, entry: WALEntry) -> Result<(), WALError> { |
| 474 | let serialized = entry.serialize(); |
| 475 | |
| 476 | // Check if we need to rotate to a new file |
| 477 | { |
| 478 | let current_size = *self.current_file_size.lock().unwrap(); |
| 479 | if current_size + serialized.len() as u64 > MAX_WAL_FILE_SIZE { |
| 480 | self.rotate_wal_file()?; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // Write to current file |
| 485 | { |
| 486 | let mut writer_guard = self.current_writer.lock().unwrap(); |
| 487 | if let Some(writer) = writer_guard.as_mut() { |
| 488 | writer |
| 489 | .write_all(&serialized) |
| 490 | .map_err(|e| WALError::IOError(format!("Failed to write WAL entry: {}", e)))?; |
| 491 | |
| 492 | // Force write to disk for durability |
| 493 | writer |
| 494 | .flush() |
| 495 | .map_err(|e| WALError::IOError(format!("Failed to flush WAL: {}", e)))?; |
| 496 | |
| 497 | // Ensure data is written to disk |
| 498 | writer |
| 499 | .get_mut() |
| 500 | .sync_data() |
| 501 | .map_err(|e| WALError::IOError(format!("Failed to sync WAL: {}", e)))?; |
| 502 | |
| 503 | // Update file size |
| 504 | *self.current_file_size.lock().unwrap() += serialized.len() as u64; |
| 505 | } else { |
| 506 | return Err(WALError::IOError("No active WAL file".to_string())); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | // Also write to catalog WAL if it affects catalog |
| 511 | if entry.affects_catalog() { |
| 512 | if let Some(catalog_wal) = &self.catalog_wal { |
| 513 | catalog_wal.write_entry(&serialized)?; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | Ok(()) |
| 518 | } |
| 519 | |
| 520 | /// Mark a transaction as committed |
| 521 | #[allow(dead_code)] // ROADMAP v0.3.0 - WAL commit marker for transaction durability |
no test coverage detected