Commit Graph
283 Commits
Author SHA1 Message Date
Claude 8b5a5cb95e Handle allocation and I/O failures gracefully in simulation
Replace assert(0) with proper error handling for:
- malloc failures in client write operations
- binary_read failures during message parsing
- WAL append failures in metadata server
- Chunk server timeout (now drops unresponsive servers)

This fixes crashes exposed by fault injection testing.
2026-01-24 11:28:10 +00:00
cozis d4c2137eaa Add allocation failure injection 2026-01-24 12:12:48 +01:00
cozis bf989864a3 Add random connect() letencies and disk bit corruption 2026-01-24 12:09:28 +01:00
cozis 07bc952cb9 Add fault injection of disk operations 2026-01-24 11:53:38 +01:00
cozis 7306bd1203 Add fault injection for partial read/writes and random send() delays 2026-01-24 11:40:45 +01:00
cozis 18817203bf Add second client to the simulation 2026-01-24 11:23:19 +01:00
Claude 3d44676a96 Fix upload tag overflow by increasing TAG_UPLOAD_CHUNK_MAX
The upload tag is computed as TAG_UPLOAD_CHUNK_MIN + upload_index, and the
assertion tag <= TAG_UPLOAD_CHUNK_MAX was failing when the number of uploads
exceeded 1000. This can happen with small chunk sizes (e.g., 1 byte) and
large writes, where each chunk needs multiple upload operations for
replication.

Increase TAG_UPLOAD_CHUNK_MAX from 2000 to 100000 to accommodate up to 99000
concurrent upload operations per write.
2026-01-24 01:13:59 +00:00
cozis a5296434d8 Merge branch 'claude/add-coverage-report-fpLp1' into add-quakey-simulator 2026-01-24 02:07:30 +01:00
Claude b1541915ce Fix uninitialized target_len bug in chunk download response
When responding to a full chunk download request (full == 1), the code
was writing uninitialized target_len to the response message instead of
the actual data length. This caused chunk-to-chunk downloads to fail,
preventing proper replication and blocking coverage of download-related
code paths.
2026-01-24 01:04:13 +00:00
cozis d5700bf45c Initialize static array 2026-01-24 01:26:55 +01:00
Claude 282bb9632f Improve simulation coverage by adding multiple chunk servers
Two changes to improve code coverage in deterministic simulation testing:

1. Add 3 chunk servers (was 1) to match the replication factor
   - This enables testing of chunk replication and chunk-to-chunk
     server communication code paths in chunk_server.c
   - Covers: process_chunk_server_download_*, start_download,
     download_targets_* functions

2. Fix Quakey bug where events targeting a closed descriptor caused
   assertion failures
   - Added remove_events_targeting_desc() to clean up DISCONNECT and
     DATA events when a descriptor is freed
   - Modified desc_free() to accept Sim pointer and call cleanup
   - This was exposed by running multiple chunk servers which create
     more connection activity
2026-01-23 21:25:10 +00:00
Claude 6a3987d418 Fix DFS simulation infinite loop due to time event scheduling issues
Three related issues were causing the simulation to get stuck:

1. Network events (connect, disconnect, send_data) were scheduled with
   relative times instead of absolute times, causing events to be
   scheduled in the past once simulation time exceeded 10-100ms.

2. When DATA events couldn't be fully consumed (receiver buffer full),
   they stayed at their original time, preventing time from advancing.
   Now they are rescheduled to current_time + 10ms.

3. When poll_timeout was 0, WAKEUP events were created at current_time,
   causing an infinite loop where time never advanced. Now timeout=0
   sets timedout immediately without creating an event.
2026-01-23 20:26:52 +00:00
cozis 30c60d84df Bug fix 2026-01-23 20:57:14 +01:00
cozis 776f8c1015 Fix scheduling issue where time didn't advance if a host was always ready 2026-01-23 18:37:26 +01:00
cozis bde2d5a1ca Replace LittleFS with MockFS 2026-01-23 17:51:59 +01:00
cozis 028f25b942 Fix signed integer overflow in time calculation 2026-01-17 01:14:51 +01:00
Claude 9948716be8 Fix assertion failure in file_tree_read when read operation fails
Initialize *gen to NO_GENERATION at the start of file_tree_read so that
error paths (FILETREE_BADPATH, FILETREE_NOENT, FILETREE_ISDIR) have a
well-defined value. Previously, when file_tree_read failed, gen was
uninitialized, causing the assertion in process_client_read to fire.

The assertion checking gen != NO_GENERATION before the error check was
removed since:
1. On error paths, gen is not used
2. On success paths, the assertion at line 482 already validates gen
2026-01-16 18:48:23 +00:00
cozis 6ef5e1a94c Fix simulation setup 2026-01-16 19:38:36 +01:00
Claude b0484eedef Clean up build_coverage.sh to run all steps in sequence
Simplifies the script to automatically compile, run (60s), and generate
the coverage report in a single invocation. Removes the two-step --report
flag approach and adds quieter output with clear step markers.
2026-01-16 18:01:31 +00:00
Claude 4cac3a721e Add branch coverage build for simulation
Adds build_coverage.sh script that:
- Builds the simulation with GCC branch coverage instrumentation
- Supports --report flag to run simulation and generate lcov HTML report
- Uses 60 second timeout with SIGINT for graceful shutdown

Also adds SIGINT handler to simulation to exit cleanly and flush coverage data.
2026-01-16 16:47:58 +00:00
cozis c10493881b Add Quakey 2026-01-16 14:45:09 +01:00
cozis 18e74a92c0 Rename inc/ to include/ 2025-12-05 09:52:49 +01:00
cozis d2c5c42537 Update the synchronization app to periodically query the remote root directory listing 2025-12-05 09:44:42 +01:00
cozis 49cee347f5 Add the terminator "/" to directory names when returning directory listings from the web interface 2025-12-05 09:19:25 +01:00
cozis 1e2223aeb0 Fix bad usage of the toastyfs client API in the web interface GET handler 2025-12-05 09:10:25 +01:00
cozis acc9c097d3 Forward declare struct pollfd in ToastyFS.h to avoid including winsock2.h and poll.h 2025-12-05 09:10:25 +01:00
Claudeandcozis 6746b0d5fb Add MISSING_FILE_GENERATION special value for "file does not exist"
Implements a new special generation counter value (UINT64_MAX) that
allows clients to assert that a file should NOT exist when performing
operations.

Primary use case: Atomic "create-if-not-exists" operations
When combined with TOASTY_WRITE_CREATE_IF_MISSING flag:
- File doesn't exist → server creates file and writes (SUCCESS)
- File exists → gen_match fails → BADGEN error (prevents overwrite)

This enables race-condition-free file creation where you want to
create a NEW file or fail if it already exists.

Key changes:
- Added MISSING_FILE_GENERATION constant to file_tree.h
- Updated gen_match() to return false when checking existing entities
  against MISSING_FILE_GENERATION
- Modified file_tree_delete_entity() to succeed (no-op) when file is
  missing and MISSING_FILE_GENERATION is specified (idempotent delete)
- Modified file_tree_write() to validate against the new value
- Added documentation in metadata_server.c explaining how
  MISSING_FILE_GENERATION works WITH CREATE_IF_MISSING
- Updated protocol documentation in PROTOCOL.txt
- Added comprehensive feature documentation in MISSING_FILE_GENERATION.md

Additional use cases:
- Idempotent delete operations (delete only if not already gone)
- Detecting unexpected file creation in validation/testing scenarios

The implementation is backward compatible and type-safe. Files are
never assigned MISSING_FILE_GENERATION as their actual generation value.
2025-12-05 09:10:17 +01:00
cozis e73bb3a7d8 Add crash logger 2025-12-04 12:25:19 +01:00
cozis 5c192a1e52 Fix wrong error code returned by file_tree_read 2025-12-03 21:15:54 +01:00
Claude 4bcee9a617 Add TOASTY_WRITE_TRUNCATE_AFTER flag for HTTP PUT semantics
Adds support for truncating files after write operations, enabling proper
HTTP PUT semantics where the entire file content should be replaced.

Implementation:
- Added TOASTY_WRITE_TRUNCATE_AFTER flag (0x02) to ToastyFS API
- Updated file_tree_write() to accept truncate_after parameter:
  * When true, sets file size to exactly offset+length
  * Removes chunks beyond the new file size
  * Marks removed chunks for garbage collection
- Metadata server extracts and passes truncate flag to file_tree_write()
- WAL replay passes false for truncate_after (already handled in original write)
- Web proxy PUT now uses both CREATE_IF_MISSING and TRUNCATE_AFTER flags
- Updated documentation in PROTOCOL.txt, DESIGN.txt, and web/DESIGN.txt

Benefits:
- Proper HTTP PUT semantics (replace entire file content)
- Efficient: single write operation truncates and updates file
- Works with both sync and async APIs
- Garbage collection automatically removes orphaned chunks
2025-12-03 19:49:48 +00:00
Claude 8160c5ac51 Add TOASTY_WRITE_CREATE_IF_MISSING flag for server-side file auto-creation
Adds support for automatically creating files when write operations target
non-existent files. This is essential for REST PUT operations which should
be able to create new resources.

Implementation:
- Added TOASTY_WRITE_CREATE_IF_MISSING flag to ToastyFS API header
- Updated toasty_write() and toasty_begin_write() to accept flags parameter
- Client sends write flags in MESSAGE_TYPE_WRITE message to metadata server
- Metadata server parses flags and handles file auto-creation atomically:
  * When write fails with FILETREE_NOENT and flag is set
  * Logs creation to WAL for crash consistency
  * Creates file with default 4096-byte chunk size
  * Retries write with newly created file's generation tag
- Updated web proxy PUT handler to use TOASTY_WRITE_CREATE_IF_MISSING
- Updated examples and simulation client for new API signature

Benefits:
- Works for both sync and async APIs
- Single round trip (atomic server-side operation)
- Prevents race conditions
- Proper WAL logging ensures crash consistency
2025-12-03 18:48:42 +00:00
cozis a082f46b78 Update TODO.txt 2025-12-03 19:12:35 +01:00
cozis 6519b0c1bb Fix incorrect call to http_response_builder_body_cap in toastyfs_web 2025-12-03 18:01:39 +01:00
cozis 012b31df3a Fix compilation warnings 2025-12-03 00:03:44 +01:00
cozis b0b2d576cc Refactoring of toastyfs_web 2025-12-03 00:03:36 +01:00
cozis 09ec872591 Merge branch 'main' into synchronization_app 2025-12-02 12:21:39 +01:00
cozis f665dae9ed Update chttp.c/.h 2025-12-02 12:07:10 +01:00
cozis 0d099a1fa6 Return version tags in directory listing 2025-11-25 12:08:33 +01:00
cozis afad13f44f Allow users of libtoastyfs to operate on files/directories with specific version tags 2025-11-24 14:34:57 +01:00
Claude 1281bf0822 Reject write operations with expect_gen=0
Per PROTOCOL.txt specification, WRITE operations must provide a valid
generation counter and cannot use expect_gen=0 (unlike other operations).

This ensures the client has retrieved the file's metadata and knows the
correct chunk size before writing.

Changes:
- Added FILETREE_BADGEN error code (-8)
- Modified file_tree_write() to reject expect_gen=0
- Added error message for FILETREE_BADGEN
2025-11-24 12:46:27 +00:00
Claude acb1336d47 Implement synchronization protocol from PROTOCOL.txt
Updated both client.c and metadata_server.c to match the protocol
specification in misc/PROTOCOL.txt:

Client-to-Server Messages:
- Added expect_gen field to DELETE, LIST, READ, and WRITE messages
- Removed old_hash and chunk_size from WRITE message chunks

Server-to-Client Responses:
- Added generation counter to CREATE_SUCCESS response
- Added generation counter to LIST_SUCCESS response
- Fixed LIST_SUCCESS field order (gen, truncated, item_count)
- Added generation counter to READ_SUCCESS response
- Added generation counter to WRITE_SUCCESS response

All changes compile successfully and pass valgrind memory checks.
2025-11-24 12:16:55 +00:00
cozis 49091aff6d Document communication between metadata server and clients in the misc/PROTOCOL.txt file and add generation counters for files 2025-11-24 13:04:29 +01:00
cozis 1c768bb8f1 Add logging to app.py 2025-11-23 11:33:30 +01:00
cozis 8e37bc674f Draft of app.py, a python script which synchronized local folders to ToastyFS through the web interface 2025-11-23 11:21:34 +01:00
cozis 70a3a91783 Change README.md to refer to the cluster demo script 2025-11-23 09:53:36 +01:00
Claudeandcozis 3b0ef325fa Fix web server hanging issues
Fixed two bugs in the HTTP server that could cause hangs:

1. web/chttp.c:4060 - Fixed incorrect error buffer check
   - Was checking output buffer for errors after a read operation
   - Should check input buffer instead
   - This could cause the server to miss read errors and not close
     bad connections properly

2. web/main.c:334 - Added loop to process multiple queued requests
   - Previously only processed one request per event loop iteration
   - Now processes all queued requests before returning to poll()
   - This prevents requests from being stuck in the queue when the
     socket is in ESTABLISHED_READY state

These fixes improve the server's ability to handle multiple requests
on Keep-Alive connections.
2025-11-23 09:48:07 +01:00
cozis e99c574767 Add options --reuse-addr and --trace-bytes to toastyfs_web 2025-11-23 09:08:45 +01:00
Claudeandcozis cc758a5d3a Add web server to cluster demo and fix port bug
- Add web server integration to cluster_demo.sh script
  - Configure web server port (8090)
  - Update build_if_needed() to check for toastyfs_web binary
  - Add get_web_binary() function
  - Start web server after chunk servers
  - Update status display to show web server
  - Update help text to show HTTP interface

- Fix bug in web/main.c where --local-port incorrectly set
  upstream_port instead of local_port

The cluster demo now starts a full cluster with:
- Metadata server on port 8080 (ToastyFS protocol)
- N chunk servers starting from port 8081
- Web server on port 8090 (HTTP interface)
2025-11-23 09:03:13 +01:00
cozis b661f18214 Fix bug 2025-11-23 00:55:07 +01:00
cozis 0dbb5b1fc5 Add command-line arguments to toastyfs_web 2025-11-23 00:46:27 +01:00