Skip to content
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

[Spark Dataset runner] Fix collection encoder bug leading to corrupt data #25297

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

mosche
Copy link
Member

@mosche mosche commented Feb 3, 2023

A bug in the collection encoder of the Spark dataset runner (aka Spark structured streaming runner) may result in corrupted data after a groupByKey if the dataset is converted to an RDD and persisted.

The collection encoder just wraps the underlying serialized UnsafeArrayData for primitive types to present a Collection as a result of deserialization. However, Spark may reuse the underlying unsafe object and with that corrupt values.

This PR ensures the data is always copied when exposed. Usage in other cases such as Map deserialization is fine as values are eventually copied when constructing the map.

I wasn't able to reproduce this in a Unit test. VR tests in #25187 will verify the behavior.

Fixes #25296


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

  • 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.

…rrupted data due to naive usage of unsafe storage (fixes apache#25296).
@mosche
Copy link
Member Author

mosche commented Feb 3, 2023

R: @aromanenko-dev (small fix to unblock #25187)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@aromanenko-dev
Copy link
Contributor

Run Spark StructuredStreaming ValidatesRunner

Copy link
Contributor

@aromanenko-dev aromanenko-dev left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@mosche mosche merged commit d50924d into apache:master Feb 3, 2023
@mosche mosche deleted the 25296_spark_collection_encoder branch February 3, 2023 09:37
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]: Usage of collection encoder in Spark Dataset runner may lead to corrupt data
2 participants