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
This commit is contained in:
+8
-3
@@ -34,9 +34,14 @@ PUT
|
||||
??? (TODO) is returned. If the payload the request is not empty, the
|
||||
operation fails with code 400.
|
||||
|
||||
If the path refers to a file, it creates that file with the specified
|
||||
contents. If a file or directory already existed at that path, it is
|
||||
overwritten unless the header "X-ToastyFS-Overwrite: no" is sent.
|
||||
If the path refers to a file, the file is automatically created if it
|
||||
doesn't exist, then the specified contents are written to it. This is
|
||||
implemented using the TOASTY_WRITE_CREATE_IF_MISSING flag which performs
|
||||
file creation and write atomically on the metadata server. Files are
|
||||
created with a default chunk size of 4096 bytes.
|
||||
|
||||
If a file or directory already existed at that path, it is overwritten
|
||||
unless the header "X-ToastyFS-Overwrite: no" is sent.
|
||||
(TODO error codes)
|
||||
|
||||
DELETE
|
||||
|
||||
+4
-1
@@ -7,8 +7,11 @@ bool process_request_put(ProxyState *state, ProxyOperation *operation,
|
||||
request->url.path.ptr,
|
||||
request->url.path.len,
|
||||
};
|
||||
// Use TOASTY_WRITE_CREATE_IF_MISSING to automatically create files
|
||||
// when they don't exist, enabling PUT operations to create new files
|
||||
ToastyHandle handle = toasty_begin_write(state->backend, path, 0,
|
||||
request->body.ptr, request->body.len, TOASTY_VERSION_TAG_EMPTY);
|
||||
request->body.ptr, request->body.len, TOASTY_VERSION_TAG_EMPTY,
|
||||
TOASTY_WRITE_CREATE_IF_MISSING);
|
||||
if (handle == TOASTY_INVALID) {
|
||||
http_response_builder_status(builder, 500); // Internal Server Error
|
||||
http_response_builder_send(builder);
|
||||
|
||||
Reference in New Issue
Block a user