[CELEBORN-2253] Fix IndexOutOfBoundsException reading shuffle data from HDFS#3683
Closed
1fanwang wants to merge 1 commit into
Closed
[CELEBORN-2253] Fix IndexOutOfBoundsException reading shuffle data from HDFS#36831fanwang wants to merge 1 commit into
1fanwang wants to merge 1 commit into
Conversation
…om HDFS ### What changes were proposed in this pull request? `HdfsFlushTask.writeAndRecordMetrics` calls `hdfsStream.write(bytes)`, which writes the full `bytes.length`. When the provider passes a reusable `copyBytes` buffer (whose length is `>= size`), this leaks trailing bytes from previous flushes into the current partition file. Pass the actual readable size to write only `size` bytes. ### Why are the changes needed? The S3 and OSS flush paths had the same bug and were fixed in apache#3600 for CELEBORN-2263; the HDFS path was missed. Without the fix, shuffle data flushed to HDFS can be corrupted when `copyBytes` is reused across flushes, and readers later fail with `IndexOutOfBoundsException` in `CelebornInputStream.fillBuffer`. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New unit test in `FlushTaskSuite` mirrors the S3/OSS coverage added in apache#3600. It drives `HdfsFlushTask.flush` with `copyBytes` of three sizes (equal, larger, smaller than the buffer payload), captures the `FSDataOutputStream.write` arguments via Mockito's `ArgumentCaptor`, and asserts the offset/length pair matches the buffer content. The test fails on master with `ArgumentsAreDifferent` at `FlushTask.scala:128` and passes with the fix.
There was a problem hiding this comment.
Pull request overview
Fixes potential shuffle data corruption in the HDFS flush path by ensuring only the valid portion of a reused buffer is written to HDFS, aligning behavior with the previously-fixed S3/OSS flush implementations.
Changes:
- Update
HdfsFlushTaskto callFSDataOutputStream.write(bytes, 0, size)instead of writing the full array length. - Add a unit test covering HDFS flush behavior when the provider’s reusable buffer is equal to, larger than, or smaller than the payload size.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| worker/src/main/scala/org/apache/celeborn/service/deploy/worker/storage/FlushTask.scala | Fixes HDFS write to respect readableBytes length and prevent trailing garbage bytes from being persisted. |
| worker/src/test/scala/org/apache/celeborn/service/deploy/worker/storage/FlushTaskSuite.scala | Adds regression coverage to validate HDFS flush uses the correct offset/length when writing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
RexXiong
approved these changes
May 12, 2026
SteNicholas
approved these changes
May 12, 2026
Member
|
Thanks. Merged to main(v0.7.0). |
akpatnam25
pushed a commit
to akpatnam25/incubator-celeborn
that referenced
this pull request
May 15, 2026
…om HDFS ### What changes were proposed in this pull request? `HdfsFlushTask.writeAndRecordMetrics` calls `hdfsStream.write(bytes)`, which writes the full `bytes.length`. When the provider passes a reusable `copyBytes` buffer (whose length is `>= size`), this leaks trailing bytes from previous flushes into the current partition file. Pass the actual readable size to write only `size` bytes. ### Why are the changes needed? The S3 and OSS flush paths had the same bug and were fixed in apache#3600 for CELEBORN-2263; the HDFS path was missed. Without the fix, shuffle data flushed to HDFS can be corrupted when `copyBytes` is reused across flushes, and readers later fail with `IndexOutOfBoundsException` in `CelebornInputStream.fillBuffer`, for example: ``` IndexOutOfBoundsException: readerIndex(4154253) + length(808530018) exceeds writerIndex(12457470) ``` ### Does this PR resolve a correctness bug? Yes. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New unit test in `FlushTaskSuite` mirrors the S3/OSS coverage added in apache#3600. It drives `HdfsFlushTask.flush` with `copyBytes` arrays of three sizes (equal, larger, smaller than the buffer payload), captures the `FSDataOutputStream.write` arguments via Mockito's `ArgumentCaptor`, and asserts the offset/length pair matches the buffer content. The test fails on master with `ArgumentsAreDifferent` at `FlushTask.scala:128` and passes with the fix. Closes apache#3683 from 1fanwang/CELEBORN-2253-fix-hdfs-flush-trailing-bytes. Authored-by: 1fanwang <1fannnw@gmail.com> Signed-off-by: SteNicholas <programgeek@163.com>
SteNicholas
pushed a commit
that referenced
this pull request
May 21, 2026
…ta from HDFS Backport CELEBORN-2253 (#3683) to branch-0.6, code and tests are tuned to adapt branch-0.6 due to miss CELEBORN-2211 (#3548) Assisted-by: OpenCode:mimo-v2.5-pro --- Original PR description. ### What changes were proposed in this pull request? `HdfsFlushTask.writeAndRecordMetrics` calls `hdfsStream.write(bytes)`, which writes the full `bytes.length`. When the provider passes a reusable `copyBytes` buffer (whose length is `>= size`), this leaks trailing bytes from previous flushes into the current partition file. Pass the actual readable size to write only `size` bytes. ### Why are the changes needed? The S3 and OSS flush paths had the same bug and were fixed in #3600 for CELEBORN-2263; the HDFS path was missed. Without the fix, shuffle data flushed to HDFS can be corrupted when `copyBytes` is reused across flushes, and readers later fail with `IndexOutOfBoundsException` in `CelebornInputStream.fillBuffer`, for example: ``` IndexOutOfBoundsException: readerIndex(4154253) + length(808530018) exceeds writerIndex(12457470) ``` ### Does this PR resolve a correctness bug? Yes. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New unit test in `FlushTaskSuite` mirrors the S3/OSS coverage added in #3600. It drives `HdfsFlushTask.flush` with `copyBytes` arrays of three sizes (equal, larger, smaller than the buffer payload), captures the `FSDataOutputStream.write` arguments via Mockito's `ArgumentCaptor`, and asserts the offset/length pair matches the buffer content. The test fails on master with `ArgumentsAreDifferent` at `FlushTask.scala:128` and passes with the fix. Closes #3697 from pan3793/CELEBORN-2253-0.6. Authored-by: Cheng Pan <chengpan@apache.org> Signed-off-by: SteNicholas <programgeek@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
HdfsFlushTask.writeAndRecordMetricscallshdfsStream.write(bytes), which writes the fullbytes.length. When the provider passes a reusablecopyBytesbuffer (whose length is>= size), this leaks trailing bytes from previous flushes into the current partition file. Pass the actual readable size to write onlysizebytes.Why are the changes needed?
The S3 and OSS flush paths had the same bug and were fixed in #3600 for CELEBORN-2263; the HDFS path was missed. Without the fix, shuffle data flushed to HDFS can be corrupted when
copyBytesis reused across flushes, and readers later fail withIndexOutOfBoundsExceptioninCelebornInputStream.fillBuffer, for example:Does this PR resolve a correctness bug?
Yes.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New unit test in
FlushTaskSuitemirrors the S3/OSS coverage added in #3600. It drivesHdfsFlushTask.flushwithcopyBytesarrays of three sizes (equal, larger, smaller than the buffer payload), captures theFSDataOutputStream.writearguments via Mockito'sArgumentCaptor, and asserts the offset/length pair matches the buffer content. The test fails on master withArgumentsAreDifferentatFlushTask.scala:128and passes with the fix.