Skip to content

Fix TextSource incorrect handling in channels that return short reads.#23376

Merged
lukecwik merged 2 commits intoapache:masterfrom
lukecwik:23375
Sep 27, 2022
Merged

Fix TextSource incorrect handling in channels that return short reads.#23376
lukecwik merged 2 commits intoapache:masterfrom
lukecwik:23375

Conversation

@lukecwik
Copy link
Copy Markdown
Member

The issue is that readDefaultLine and readCustomLine was incorrectly calculating the appendLength when the buffer returned was 0 length. This was solved by ensuring that the internal read loop always read at least one byte allowing for the code to ensure that we were making progress. For readDefaultLine we kept track of whether we need to skip an LF in the next buffer if the current buffer ended with a CR and for readCustomLine we had to remember how much of the delimiter we have read so far in this buffer.

The bug was introduced in 30a48f0

There was no noticeable change in the TextSourceBenchmark performance results.

Fixes #23375


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI.

The issue is that readDefaultLine and readCustomLine was incorrectly calculating the appendLength when the buffer returned was 0 length.
This was solved by ensuring that the internal read loop always read at least one byte allowing for the code to ensure that we were making progress. For readDefaultLine we kept track of whether we need to skip an LF in the next buffer if the current buffer ended with a CR and for readCustomLine we had to remember how much of the delimiter we have read so far in this buffer.

The bug was introduced in apache@30a48f0

There was no noticeable change in the TextSourceBenchmark performance results.

Fixes apache#23375
Comment on lines +391 to +392
reader.startReading(
new ReadableByteChannel() {
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.

nit: could be nice to document this for readability (could happen later though, I know you want to get this in)

Suggested change
reader.startReading(
new ReadableByteChannel() {
reader.startReading(
// Placeholder channel that only yields 0- and 1-length buffers.
// Data is read one byte at a time from line parameter
new ReadableByteChannel() {

@TheNeuralBit
Copy link
Copy Markdown
Member

It looks like the bug was caught with an internal Google test, please make sure that this patch fixes it before merging. Thanks!

@github-actions github-actions Bot added the java label Sep 26, 2022
@github-actions
Copy link
Copy Markdown
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @robertwb for label java.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@lukecwik
Copy link
Copy Markdown
Member Author

It looks like the bug was caught with an internal Google test, please make sure that this patch fixes it before merging. Thanks!

Will do.

@lukecwik
Copy link
Copy Markdown
Member Author

@lukecwik
Copy link
Copy Markdown
Member Author

Internal testing within Google also passed.

@lukecwik lukecwik merged commit 7dd1c6b into apache:master Sep 27, 2022
johnjcasey added a commit to johnjcasey/beam that referenced this pull request Nov 21, 2023
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.

[Bug]: TextSource fails to handle parsing channels that return very short reads (< # delimiter characters)

2 participants