Xuanwo opened a new pull request, #8865:
URL: https://github.com/apache/opendal/pull/8865
# Which issue does this PR close?
Part of #8854. The `BufferSink` part is left out because open PR #8846
modifies
that file; it can follow once that PR merges.
# Rationale for this change
`Copier`, `FuturesDeleteSink`, and `CompleteWriter` each kept their lifecycle
payload in fields next to a tag enum:
- `Copier` had `copier: Option<oio::Copier>`, `fut:
Option<BoxedStaticFuture<Step>>`,
and `state: State`, with comments and `.take()` / `.expect()` explaining
which
combinations are possible.
- `FuturesDeleteSink` encoded "closed" as `State::Idle(None)`, so the same
`Option` meant both "no deleter in hand" and "this sink is done".
- `CompleteWriter` had `inner: Option<W>` next to `state: CompleteState` and
used
`debug_assert_ne!` to defend an invariant that the type did not express.
A reader had to hold several fields in mind to know what a state means.
Carrying
the payload in the variant makes the invariant compiler-checked and readable
in
one enum definition.
# What changes are included in this PR?
`Copier` (`core/core/src/types/copy.rs`):
- `State` now owns its payload: `Idle(oio::Copier)`,
`InFlight(BoxedStaticFuture<Step>)`,
`Closed(metadata)`, `Aborted`, `Failed(oio::Copier)`.
- `start_step` moves the state out to hand the inner copier to the step, and
`step` / `poll_next` read the in-flight future out of the state, so a
canceled
poll still resumes the same step instead of dropping its progress.
- `abort` takes the copier from `Idle` or `Failed`; it keeps the copier when
the
abort fails so a retry can clean up the same server-side copy.
`FuturesDeleteSink` (`core/core/src/types/delete/futures_delete_sink.rs`):
- `State::Idle(Option<Deleter>)` becomes `State::Idle(Deleter)` plus an
explicit
`State::Closed`. A successful close moves to `Closed`, a failed close
returns
the deleter to `Idle` so the close can be retried, exactly as before.
- `take_idle_deleter` performs the hand-off from `Idle` to a delete or close
request; `poll_close` reads as flush-the-delete, start-the-close,
poll-the-close instead of a match inside a loop.
`CompleteWriter` (`core/core/src/layers/complete.rs`):
- `State` now owns the writer: `Open(oio::Writer)`, `Written(oio::Writer)`,
`Closed`, `Failed(oio::Writer)`. `inner: Option<W>`, `CompleteState`, and
the
`debug_assert_ne!` checks are gone.
- `W` is removed. `CompleteWriter` is internal to the private `complete`
module;
the only instantiation in the workspace was `CompleteWriter<oio::Writer>`,
and
the remaining references are unit tests in the same file.
- The close-metadata contract (check the reported length, require a final
length
for append, promote unknown metadata with the written size) is now one
method,
`check_close`, so `close` stays readable end to end.
- A failure stays recorded until the writer is closed or aborted, preserving
the
previous sticky-error behavior; a successful close or abort after a
failure now
ends in `Closed` rather than a separate error tag. Both reject every later
operation with the same error and neither warns on drop.
Tests:
- `Copier` tests assert the state reached after close, after a failed close,
and
during a canceled poll, and cover aborting after a failed close.
- `CompleteWriter` tests cover a closed writer rejecting further writes,
closes,
and aborts; a failed close that keeps the writer for a retry; and a failure
that stays recorded after a later successful write.
`CompleteLayer::layer()`, `CompleteService::stat`, and `buffer_sink.rs` are
untouched.
Validation, all run locally from `core/`:
- `cargo fmt --all -- --check`
- `cargo clippy -p opendal-core --all-targets -- -D warnings`
- `cargo test -p opendal-core --lib` (431 passed)
- `cargo test -p opendal-core --doc` (143 passed, 10 ignored)
# Are there any user-facing changes?
No. All three types are internal to `opendal-core`, and no public signature,
capability, or error message changes.
# Breaking changes
# AI Usage Statement
- Harness: pi / T3 Code
- Model: DeepSeek
- Effort: High
- Role: Analyzed the three state machines, moved the payloads into the state
enums, wrote the transition tests, and ran the local formatting, lint,
unit-test, and doc-test checks. Assumption that affects review: a writer that
failed and was then closed or aborted is now recorded as `Closed`; I checked
that every later operation returns the same error and that the only previous
reader of the sticky error tag was the debug-only drop warning.
--
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]