Skip to content

[CELEBORN-2253] Fix IndexOutOfBoundsException reading shuffle data from HDFS#3683

Closed
1fanwang wants to merge 1 commit into
apache:mainfrom
1fanwang:CELEBORN-2253-fix-hdfs-flush-trailing-bytes
Closed

[CELEBORN-2253] Fix IndexOutOfBoundsException reading shuffle data from HDFS#3683
1fanwang wants to merge 1 commit into
apache:mainfrom
1fanwang:CELEBORN-2253-fix-hdfs-flush-trailing-bytes

Conversation

@1fanwang
Copy link
Copy Markdown
Contributor

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.

…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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HdfsFlushTask to call FSDataOutputStream.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.

@SteNicholas
Copy link
Copy Markdown
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants