Complete WAL implementation with file rotation
This commit completes the Write-Ahead Log (WAL) implementation for the metadata server, including all missing functionality and error fixes: File System Changes (src/file_system.c): - Implemented file_set_offset() using lseek (Linux) and SetFilePointer (Windows) - Implemented file_get_offset() to get current file position WAL Header Changes (src/wal.h): - Added file_tree pointer to WAL structure for snapshot serialization - Added file_path to WAL structure for rotation operations WAL Implementation (src/wal.c): - Fixed handle assignment bug in wal_open (was using wal->handle before assignment) - Fixed missing return statement in append_begin() - Implemented serialize_callback for writing file tree snapshots to WAL - Implemented deserialize_callback for reading file tree snapshots from WAL - Implemented next_entry() to read WAL entries from file during recovery - Implemented wal_append_write() to write file modifications to WAL - Implemented swap_file() for complete WAL file rotation: * Creates temporary file with new snapshot * Writes WAL header and serialized file tree * Atomically replaces old WAL file * Resets entry counter for new rotation cycle - Added WAL file initialization for newly created files - Added helper functions: read_exact, read_u8, read_u16, read_u32, read_u64, write_u32 - Fixed typo in comment (Not -> Now) The WAL now supports: - Full crash recovery by replaying logged operations - Automatic file rotation when entry limit is reached - Atomic file replacement to ensure durability - Proper file locking throughout rotation process
This commit is contained in: