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

Fix RowCoderGenerator to use the encodingPositions when encoding and decoding the bit set representing null fields. #32389

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

scwhittle
Copy link
Contributor

@scwhittle scwhittle commented Sep 3, 2024

Add tests that fail without the change covering encoding and decoding

Also add tests that cover the static position overrides which was not tested previously.

Some other cleanup to help debug other possible encoding positions issues in the future:

  • ensure that only a single RowCoder is created for a given UUID by using synchronization when generating coders
  • add some logging if encoding position overrides arrive after a RowCoder has already been generated for the UUID

fixes #32388


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 or the workflows README to see a list of phrases to trigger workflows.

@scwhittle
Copy link
Contributor Author

R: @reuvenlax

@github-actions github-actions bot added the java label Sep 3, 2024
Copy link
Contributor

github-actions bot commented Sep 3, 2024

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@scwhittle
Copy link
Contributor Author

Also added internal dataflow tests verifying that this fixes update with reordered schemas with null fields.

@scwhittle
Copy link
Contributor Author

@Abacn @reuvenlax friendly ping

Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

thanks, left a few questions


@VisibleForTesting
static void clearRowCoderCache() {
synchronized (setOverridesLock) {
Copy link
Contributor

Choose a reason for hiding this comment

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

GENERATED_CODERS is already a synchronized map. Usually does not need to be wrapped with synchronized block. Here I see "setOverridesLock" is used in other places, probably this is the reason. If this is the case, consider adding a comment to note this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Coders can be read without the synchronized block but are written with the extra synchronization because concurrenthashmap updateifnotpresent is not reentrant (unlike synchronized) and the get/insert pattern is possibly racy.

That said I since the read coders are cached, I think I will just change to regular maps under synchronization and ditch the concurrenthashmap.

@@ -425,7 +538,7 @@ static Row decodeDelegate(
// in which case we drop the extra fields.
if (encodingPos < coders.length) {
int rowIndex = encodingPosToIndex[encodingPos];
if (nullFields.get(rowIndex)) {
if (nullFields.get(encodingPos)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

was this a bug? rowIndex and encodingPos looks different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this along with other nullfields fix above is the purpose of this PR to fix #32388 .
The stack trace and synchronization changes were added as the initial belief was that encoded corruption was due to late overrides arriving. Since that could still be an issue, I think we should keep those changes but I can separate them to a separate PR if you'd prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that unless there are encoding overrides rowIndex and encodingPos are equal. But the improved unit tests catch the issue, previous tests with encoding overrides didn't have null fields and thus missed it.

…decoding the bit set representing null fields.
Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

thank you!

@scwhittle scwhittle merged commit e76b51f into apache:master Sep 11, 2024
28 checks passed
@scwhittle scwhittle deleted the schema_reproduce_issue branch September 11, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Java generated RowCoder doesn't use encodingPositions when encoding/decoding the null set
2 participants