Claude 52bc1ff450 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
2025-11-17 21:02:19 +00:00
2025-11-17 21:52:44 +01:00
2025-11-16 02:10:59 +01:00

ToastyFS

ToastyFS is a distributed file system designed for self-hosting, so it aims to be pragmatic, understandable, and robust. You can use ToastyFS to store your files reliably over multiple machines knowing they will be automatically replicated and healed in case of hardware failure. ToastyFS works by running nodes on multiple machines. Clients using the ToastyFS C library can then send file operations to the cluster. Here's a quick example:

#include <ToastyFS.h>

int main(void)
{
    ToastyString addr = TOASTY_STR("127.0.0.1");
    int          port = 8080;
    ToastyString file = TOASTY_STR("/my_file.txt");
    
    // Connect to cluster
    ToastyFS *toasty = toasty_connect(addr, port);
    
    // Create and write to a file
    toasty_create_file(toasty, file, 4096);
    toasty_write(toasty, file, 0, "Hello!", 6);
    
    // Read it back
    char buf[6];
    toasty_read(toasty, file, 0, buf, 6);
    
    // Done!
    toasty_disconnect(toasty);
    return 0;
}

⚠️ Note that ToastyFS is still in early development ⚠️

🎵 Now let's get toasty 🎵

Features

  • Cross-platform (runs on Windows and Linux)
  • Automatic Replication & Self-Healing
  • Automatic content deduplication via internal content-addressing
  • Configurable file chunk sizes
  • Small and understandable

But ToastyFS is still in early development, so here are the missing features:

  • No master replication
  • No authentication or encryption

Testing

ToastyFS is tested by running an in-memory simulation of a cluster with many clients running hundreds of random operations in parallel. The test is run for long periods of times under valgrind or compiled with sanitizers.

S
Description
A simple, fault-tolerant, highly available object storage
Readme MIT
1.1 MiB
Languages
C 98.4%
Shell 1%
Zig 0.4%
Batchfile 0.2%