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.
This commit is contained in:
@@ -13,6 +13,21 @@ All messages start with a shared header, defined as:
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
1.1 Generation Counter Special Values
|
||||
|
||||
Generation counters (uint64_t) have two special values:
|
||||
|
||||
NO_GENERATION (0):
|
||||
When used in expect_gen, means "skip generation check entirely".
|
||||
Files/directories are never assigned this generation value.
|
||||
|
||||
MISSING_FILE_GENERATION (UINT64_MAX):
|
||||
When used in expect_gen, means "expect file/directory to NOT exist".
|
||||
- For DELETE: succeeds if file doesn't exist (no-op)
|
||||
- For WRITE: fails with BADGEN if file exists, fails with NOENT if missing
|
||||
- For existing operations: causes generation mismatch if file exists
|
||||
Files/directories are never assigned this generation value.
|
||||
|
||||
2. Client Messages
|
||||
|
||||
2.1 Client to Metadata Server messages
|
||||
|
||||
Reference in New Issue
Block a user