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:
+13
-2
@@ -56,6 +56,9 @@ typedef uint64_t ToastyVersionTag;
|
||||
// TODO: comment
|
||||
#define TOASTY_VERSION_TAG_EMPTY ((ToastyVersionTag) 0)
|
||||
|
||||
// Write operation flags
|
||||
#define TOASTY_WRITE_CREATE_IF_MISSING (1 << 0) // Create file if it doesn't exist
|
||||
|
||||
// Creates a directory at the specified path.
|
||||
// Returns 0 on success, -1 on error.
|
||||
//
|
||||
@@ -125,8 +128,12 @@ int toasty_read(ToastyFS *toasty, ToastyString path, int off,
|
||||
// on success, or -1 on error.
|
||||
//
|
||||
// For how vtag works, see toasty_read.
|
||||
//
|
||||
// The flags parameter can be set to TOASTY_WRITE_CREATE_IF_MISSING
|
||||
// to automatically create the file if it doesn't exist. A default
|
||||
// chunk size of 4096 bytes will be used for the created file.
|
||||
int toasty_write(ToastyFS *toasty, ToastyString path, int off,
|
||||
void *src, int len, ToastyVersionTag *vtag);
|
||||
void *src, int len, ToastyVersionTag *vtag, uint32_t flags);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASYNCHRONOUS API
|
||||
@@ -177,8 +184,12 @@ ToastyHandle toasty_begin_read(ToastyFS *toasty, ToastyString path,
|
||||
//
|
||||
// If vtag is not 0, the operation only succedes if the
|
||||
// tag matches the remote entity's.
|
||||
//
|
||||
// The flags parameter can be set to TOASTY_WRITE_CREATE_IF_MISSING
|
||||
// to automatically create the file if it doesn't exist. A default
|
||||
// chunk size of 4096 bytes will be used for the created file.
|
||||
ToastyHandle toasty_begin_write(ToastyFS *toasty, ToastyString path,
|
||||
int off, void *src, int len, ToastyVersionTag vtag);
|
||||
int off, void *src, int len, ToastyVersionTag vtag, uint32_t flags);
|
||||
|
||||
// Associate the pointer "user" to the handle. The user
|
||||
// pointer will be returned in the ToastyResult when the
|
||||
|
||||
Reference in New Issue
Block a user