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

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements. You can link an issue to this PR using the GitHub syntax. For 
example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   None.
   
   # Rationale for this change
   
   Three write-path bugs existed in `opendal-service-fs`:
   
   1. **Staged file leak and retry mismatch on `close()` failure**: When 
`atomic_write_dir` is enabled, an unconditional `rename` failure (for example 
`IsADirectory`, `NotADirectory`, `PermissionDenied`, or cross-device `EXDEV`) 
left the staging file behind in `atomic_write_dir`, and `IsADirectory` / 
`NotADirectory` / `EXDEV` were classified as temporary `Unexpected` errors. 
Conversely, conditional publish (`if_not_exists`) unconditionally discarded the 
staging file and forced errors permanent even on transient failures, preventing 
retry layers from retrying `close()`.
   2. **Non-atomic user metadata application on staged writes**: On Unix, 
`FsWriter::close()` applied `user.*` extended attributes to `target_path` 
*after* publishing the staged file. Concurrent readers could observe a newly 
published file without its user metadata, and a failure while setting xattrs 
left the target file already created or overwritten without metadata.
   3. **Orphaned empty file on failed `direct_io` create**: On Linux with 
`direct_io(true)` and without `atomic_write_dir` or `if_not_exists`, opening a 
non-existent file used `O_CREAT` with `cleanup_on_error = false`. On 
filesystems such as `tmpfs` that accept `open(O_DIRECT | O_CREAT)` and then 
fail direct I/O alignment discovery, the failed write leaked an empty file at 
the target path.
   
   # What changes are included in this PR?
   
   - Classify `IsADirectory`, `NotADirectory`, and Unix `EXDEV` as permanent 
errors in `core/services/fs/src/core.rs` (`parse_error` / 
`parse_rename_error`), classify unsupported/invalid/oversized xattr errors as 
permanent in `FsCore::set_user_metadata`, and mark non-Linux post-`hard_link` 
staging removal failures permanent so retries do not re-run `hard_link` against 
an already-published target.
   - Clean up the staged temp file on permanent `close()` failures (both 
conditional and unconditional writes, and before/during publish) while 
preserving the staged temp file and temporary error status when a failure is 
retryable.
   - Apply Unix `user_metadata` xattrs to the staging file before `sync_all()` 
and atomic publish in both `oio::Write::close` and `oio::PositionWrite::close`.
   - In `DirectIoAlignment::open_for_write`, probe existing files without 
`O_CREAT` first and create missing files exclusively (`O_CREAT | O_EXCL`), so 
failed alignment discovery removes newly created files without touching 
pre-existing ones (with dangling-symlink handling to avoid spinning).
   - Add regression tests in `core/services/fs/src/core.rs`, 
`core/services/fs/src/writer.rs`, and `core/services/fs/tests/direct_io.rs`.
   
   # Are there any user-facing changes?
   
   - Staged writes with `atomic_write_dir` now publish `user_metadata` 
atomically with the file on Unix and clean up staging files on permanent close 
failures while preserving retryability for transient failures.
   - Failed `direct_io` writes to non-existent targets on Linux no longer leave 
empty orphaned files behind.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Verified all three bugs against `core/services/fs`, implemented the 
fixes and deterministic regression tests, and validated formatting, clippy, 
docs, unit/integration tests, and `fs` behavior tests on Linux.
   


-- 
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