Skip to content

fix: fill FileIO chunks after short positive reads - #3815

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/file-source-handle-short-reads
Nov 29, 2026
Merged

He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/file-source-handle-short-reads

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Motivation

A positional file-channel read can return fewer bytes than requested without reaching EOF. Treating a short positive read as EOF can truncate the source.

Modification

Keep filling the existing buffer while reads make progress. Emit full chunks and a final partial chunk when needed, while retaining the existing read-ahead limit and zero-read termination policy. Exercise a channel that returns two bytes per read from a nonzero offset and document the chunk-size contract.

Result

FileIO.fromPath reads through short positive reads without changing its public API or the close-before-result ordering. The branch now contains only the short-read change atop Apache main, after #3808 merged.

Tests

  • Native FileSourceSpec and FileSourceCloseFailureSpec passed 20/20 on Scala 2.13.18 and 20/20 on Scala 3.3.9 (JDK 17).
  • The exact pre-fix FileSource failed the new regression using the same Scala 2.13 test classes.
  • Scoped Scalafmt, license headers and git diff --check passed.

References

Refs #3808.

@He-Pin
He-Pin force-pushed the fix/file-source-handle-short-reads branch from 114746e to 38f4839 Compare November 26, 2026 13:01
Motivation:
A positional file-channel read can return fewer bytes than requested
without reaching EOF. Treating that as EOF could truncate the source.

Modification:
Keep filling the existing buffer after positive progress. Emit a full
chunk, or the remaining bytes on a terminal read, without changing the
read-ahead limit or materialized result and close ordering.

Result:
Short positive reads yield full chunks until the final chunk. The
existing zero-read termination policy is unchanged.

Tests:
- Native FileSourceSpec and FileSourceCloseFailureSpec: 20/20 each on
  Scala 2.13.18 and 3.3.9, JDK 17.
- The exact pre-fix FileSource blob failed the new case, as expected,
  with the same Scala 2.13 test classes.
- Scoped Scalafmt, license header checks and git diff --check passed.

References:
Refs apache#3808 and apache#3815.
@He-Pin
He-Pin force-pushed the fix/file-source-handle-short-reads branch from 38f4839 to ce2ac37 Compare November 27, 2026 09:50
@He-Pin
He-Pin marked this pull request as ready for review November 27, 2026 19:47
@He-Pin
He-Pin requested a review from pjfanning November 27, 2026 19:47

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@He-Pin
He-Pin merged commit af3aa01 into apache:main Nov 29, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants