-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-53870][PYTHON][SS] Fix partial read bug for large proto messages in TransformWithStateInPySparkStateServer #52539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jiateoh
wants to merge
5
commits into
apache:master
Choose a base branch
from
jiateoh:tws_readFully_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−1
Conversation
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
fe1a90f
to
8806a06
Compare
8806a06
to
5fbe0d4
Compare
5a53558
to
ff81ddd
Compare
…ateServer Use readFully() instead of read() to ensure the entire protobuf message is read from the input stream. The read() method may only read partial results (experimentally 8KB), which can cause failures when processing large state values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This reverts commit 6a0fb22.
This reverts commit 3d8f9ab.
ff81ddd
to
123031a
Compare
@HeartSaVioR can you help take a look? Thank you! |
HeartSaVioR
approved these changes
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Let me keep this PR open for a day and merge once there is no outstanding comment. |
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?
Fix the TransformWithState StateServer's
parseProtoMessage
method to fully read the desired message using the correct readFully DataInputStream API rather thanread
(InputStream/FilterInputStream) which only reads all available data and may not return the full message.readFully
(DataInputStream) will continue fetching until it fills up the provided buffer.In addition to the linked API above, this StackOverflow post also illustrates the difference between the two APIs: https://stackoverflow.com/a/25900095
Why are the changes needed?
For large state values used in the TransformWithState API,
inputStream.read
is not guaranteed to readmessageLen
's bytes of data as per the InputStream API. For large values,read
will return prematurely and the messageBytes will only be partially filled, yielding an incorrect and likely unparseable proto message.This is not a common scenario, as testing also indicated that the actual proto messages had to be somewhat large to consistently trigger this error. The test case I added uses 512KB strings in the state value updates.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Added a new test case using 512KB strings:
The configured data size (512KB) triggers an incomplete read, while also completing in a reasonable time (within 30s on my laptop). I had separately tested a larger input size of 4MB which took 30min which I considered too expensive to include in the test.
Below is sample/testing results from using
read
only (i.e., no fix) and adding a check on message length vs read bytes (test code is included in this commit but reverted later for the PR). The check is no longer required after thereadFully
fix as that is handled within the provided API.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-sonnet-4-5-20250929)