357447923 opened a new pull request, #9287:
URL: https://github.com/apache/opendal/pull/9287

   # Which issue does this PR close?
   
   Closes #9150 
   
   # Rationale for this change
   
   `Hf3fsBackend` advertises `write_with_if_not_exists`, but the writer opened 
the target path itself. A conditional write was therefore not atomic with its 
visible commit.
   
   Reproduced on a real single-node 3FS cluster (3FS commit `22fca045`, the 
commit `ffi.rs` links to) with a streaming `if_not_exists` writer on 
`aa551d2ad`:
   
   - The target existed and grew while chunks were written, before `close()`.
   - `abort()` returned `Unsupported`, and the partial file stayed at the 
target path.
   - A later `if_not_exists` write to the same path failed with 
`ConditionNotMatch`.
   
   3FS offers no rename that keeps an existing destination. `hf3fs_rename` 
rejects every `renameat2` flag with `ENOSYS` (`src/fuse/FuseOps.cc`), and 
`renameat2(RENAME_NOREPLACE)` fails with `EINVAL` on the mount. But a hard link 
does offer one: `link(staged, target)` fails with `EEXIST` when the target 
exists. A probe on the same cluster ran 16 concurrent `link()` calls to one 
target and got exactly one winner and 15 `EEXIST`.
   
   With this change, the same reproduction shows no target before `close()`, a 
successful `abort()`, and an accepted `if_not_exists` retry. A retry is still 
rejected with `ConditionNotMatch` when the target already exists.
   
   # What changes are included in this PR?
   
   - An `if_not_exists` write opens a staged file in the target's directory 
instead of the target. The staged name is the target name plus a random suffix.
   - `close()` syncs the staged file, links it to the target, and then removes 
the staged name. `EEXIST` from the link becomes `ConditionNotMatch`.
   - `abort()` removes the staged file and succeeds for `if_not_exists` writes. 
Writes without `if_not_exists` still return `Unsupported`.
   - `StagedFile` records whether a staged file is pending, published, or 
discarded, guarded by a lock:
     - A `close()` that is cancelled and retried returns the committed result 
instead of linking twice.
     - A publish that fails with a permanent error removes the staged file. A 
temporary error keeps it so that a retried `close()` can publish it.
     - Aborting an already published write still fails, but removes a staged 
name that `close()` failed to remove.
   - An existing target is rejected before the staged file is created.
   - Tests: six unit tests in `writer.rs`, and three tests in 
`tests/real_service.rs` that run against a real 3FS mount.
   - README updated for the new behavior.
   
   Writes without `if_not_exists` keep their previous behavior.
   
   # Are there any user-facing changes?
   
   Yes, for `if_not_exists` writes:
   
   - The target path does not exist until `close()` commits the write, so 
readers no longer see a partial conditional write.
   - `abort()` succeeds and leaves no file behind. It returned `Unsupported` 
and left a partial file before.
   - A temporary file is visible in listings while the write is in progress.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: ZCode (two agents)
   - Model: GLM-5.3-Flash, GLM-5.4
   - Effort: MAX
   - Role: One AI agent investigated the issue and the 3FS source 
(GLM-5.3-Flash) and wrote the implementation, the tests, and this description 
(GLM-5.4). A second AI agent (GLM-5.4) set up the single-node 3FS cluster and 
wrote the link probe and the reproduction program. Assumptions and unknowns 
that affect review:
     - Verified only on a single-node 3FS cluster at commit `22fca045`. 
Multi-node clusters and other 3FS versions were not tested. The 3FS hard-link 
support (`hf3fs_link`, `src/meta/store/ops/HardLink.cc`) is present in the 
first public 3FS commit (`815e55e4`).
     - The path that keeps the staged file after a temporary publish error has 
no test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to