Xuanwo opened a new pull request, #8735:
URL: https://github.com/apache/opendal/pull/8735
# Which issue does this PR close?
Closes #8734.
# Rationale for this change
`Writer::copy_from` documents that interleaved `write`/`copy_from` calls
write in call order. With `.chunk(N)` (exact chunking),
`WriteGenerator::copy_from` could write a natively copied part *before* bytes
already accepted by earlier `write` calls, silently corrupting the destination
object:
```rust
writer.write("XYZ").await?; // 3 bytes buffered
writer.copy_from("source", 0..20).await?; // source = "0123456789abcdefghij"
// expected "XYZ0123456789abcdefghij", produced "789abcdefgXYZ0123456hij"
```
Exact-mode `write_chunk` keeps a full buffer queued until the next write, so
the boundary fill in `copy_from` can leave `chunk_size` bytes unflushed when
the `while remaining >= chunk_size` loop issues `self.w.copy_from` directly on
the underlying writer.
# What changes are included in this PR?
- `core/core/src/types/context/write.rs`: flush `self.buffer` once more
after the boundary fill when it reaches `chunk_size`, before any native
`self.w.copy_from` call. The inexact path is unaffected because `write_chunk`
flushes as soon as the buffer reaches `chunk_size` there.
- New unit tests covering: the reported reproduction, a `copy_from` after a
`write` that fills exactly `chunk_size`, consecutive `copy_from` calls with
misaligned ranges under exact chunking, and inexact-mode interleaving. Both
exact-mode tests fail without the fix.
# Are there any user-facing changes?
Yes: fixes silent out-of-order data corruption for users interleaving
`write` and `copy_from` on writers configured with `.chunk(...)` against
services with native `write_can_copy_from` (e.g. S3 multipart upload part
copy). No API changes.
# Breaking changes
# AI Usage Statement
- Harness: pi coding agent inside T3 Code
- Model: devin/swe-2
- Effort: max reasoning
- Role: AI authored the fix, regression tests, issue report, and this PR
under delegation from the maintainer; the maintainer reviewed the design and
verified reproduction before submission.
--
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]