Xuanwo opened a new pull request, #8916:
URL: https://github.com/apache/opendal/pull/8916
# Which issue does this PR close?
None. Found during maintenance; no separate issue was filed.
# Rationale for this change
Three correctness issues were verified in `opendal-service-monoiofs`:
1. **`MonoiofsBackend::copy` destroys destination on directory source
without trailing slash:** `Operator::copy_inner` only rejects directory paths
ending with `/`. When `from` is an existing directory without a trailing slash,
`MonoiofsBackend::copy` creates destination parent directories and opens `to`
with `.create(true).truncate(true)` before reading `from` fails with `EISDIR`,
truncating an existing destination file to 0 bytes or leaving spurious parent
directories and a 0-byte file behind.
2. **`MonoiofsWriter` panics in `propagate_worker_panic` after worker task
exit:** On `WriterRequest::Close`, the writer worker task unconditionally broke
out of its loop and dropped `rx` even if `sync_all()` failed, while the worker
thread remained alive. Retrying `close()` after a failure or calling
`write()`/`close()` on a closed `MonoiofsWriter` then failed `tx.send(...)`,
invoked `propagate_worker_panic()`, found no finished worker thread, and
panicked with `unreachable!("this method should panic")`.
3. **`MonoiofsWriter::new` hardcodes `pos = 0` when `append == true`:**
Writes are submitted via `file.write_all_at(buf, pos)`. On Linux, `O_APPEND`
causes `pwrite`/`io_uring` to ignore `pos`, masking the bug, whereas
POSIX-compliant platforms (macOS/BSD) honor the offset and overwrite from byte
0 instead of appending.
# What changes are included in this PR?
- `core/services/monoiofs/src/backend.rs`:
- Check `from_meta.is_dir()` after `monoio::fs::metadata(from)` and return
`ErrorKind::IsADirectory` before calling `prepare_write_path` or
opening/truncating `to`.
- Map `io::ErrorKind::IsADirectory` during copy execution to
`ErrorKind::IsADirectory`.
- Add regression tests verifying directory source preserves destination
content and avoids creating missing parent directories, as well as
destination-is-directory and missing-source behavior.
- `core/services/monoiofs/src/writer.rs`:
- Track closed state via `tx:
Option<mpsc::UnboundedSender<WriterRequest>>` on `MonoiofsWriter` and return
`ErrorKind::Unexpected` on `write()` or `close()` after close.
- Keep the writer worker task alive with `file: Option<File>` until the
sender is dropped, closing `file` only after `sync_all()` and `metadata()`
succeed so a failed `close()` can be retried and a cancelled `close()` cannot
trigger `propagate_worker_panic`.
- Initialize `MonoiofsWriter.pos` from `file.metadata().await?.len()` when
`append == true` and advance it on each write.
- Add regression tests covering use-after-close error handling and append
offset initialization/advancement.
# Are there any user-facing changes?
- `MonoiofsBackend::copy` now returns `ErrorKind::IsADirectory` without
modifying destination files or creating destination parent directories when the
source is a directory without a trailing slash, and returns
`ErrorKind::IsADirectory` when the destination is an existing directory without
a trailing slash.
- `MonoiofsWriter` now returns `ErrorKind::Unexpected` instead of panicking
when used after close, keeps the file open for retry when `close()` fails, and
tracks the true file offset in append mode.
# Breaking changes
# AI Usage Statement
- **Harness:** pi
- **Model:** Gemini 4 Neon
- **Effort:** high
- **Role:** Verified all three issues with failing regression tests,
implemented the fixes and tests in `core/services/monoiofs`, and ran
formatting, clippy, documentation, unit, and monoiofs behavior tests.
Assumption/unknown: append offset initialization (`pos`) was verified on Linux
via unit tests inspecting `MonoiofsWriter.pos` and end-to-end append tests;
macOS/BSD `pwrite` behavior was not executed directly on a BSD/macOS host.
--
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]