Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Key by paneindex and reshuffle before loading files. #34324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

claudevdm
Copy link
Collaborator

@claudevdm claudevdm commented Mar 17, 2025

Add Reshuffle before triggering load jobs to ensure determinism.

The Reshuffle implementation in python does not preserve pane index (see #28219)

If we keep fetching pane info in the original DoFn then ALL load jobs will have pane info 0 (see linked bug) and only the very first load job will succeed.

So another option is to fix the Reshuffle implementation (I have tested this too), but that is a more intrusive change that probably needs more discussion.

Note #28219 was for Java that had a similar issue, but Python never had a Reshuffle before actually loading the files so it didn't have any effect

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.

@claudevdm claudevdm requested a review from ahmedabu98 March 17, 2025 16:46
@claudevdm claudevdm marked this pull request as ready for review March 17, 2025 16:46
Copy link
Contributor

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

R: @liferoad for label python.
R: @shunping for label io.

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

self,
element,
load_job_name_prefix,
pane_info=beam.DoFn.PaneInfoParam,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this safe to remove pane_info?

Copy link
Collaborator Author

@claudevdm claudevdm Mar 17, 2025

Choose a reason for hiding this comment

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

We are still using pane info, but just adding it earlier as part of the key that gets processed by TriggerLoadJob

@@ -1104,6 +1099,8 @@ def _load_data(
# Load data using temp tables
trigger_loads_outputs = (
partitions_using_temp_tables
| "KeyByPaneIndexWithTempTables" >> beam.ParDo(KeyByPaneIndex())
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to worry about the update compatibility?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I will make those changes before merging this

@shunping
Copy link
Collaborator

shunping commented Mar 17, 2025

Thanks @claudevdm. I know there is context somewhere, but could you briefly explain why we need this change here?
Looks like we are now getting the pane index in a separate and new DoFn prior to Reshuffle, rather than from the original DoFn.

@claudevdm
Copy link
Collaborator Author

claudevdm commented Mar 17, 2025

Thanks @claudevdm. I know there is context somewhere, but could you briefly explain why we need this change here? Looks like we are now getting the pane index in a separate and new DoFn prior to Reshuffle, rather than from the original DoFn.

The Reshuffle implementation in python does not preserve pane index (see #28219)

If we keep fetching pane info in the original DoFn then ALL load jobs will have pane info 0 (see linked bug) and only the very first load job will succeed.

So another option is to fix the Reshuffle implementation (I have tested this too), but that is a more intrusive change that probably needs more discussion.

Note #28219 was for Java that had a similar issue, but Python never had a Reshuffle before actually loading the files so it didn't have any effect

class KeyByPaneIndex(beam.DoFn):
def process(self, element, pane_info=beam.DoFn.PaneInfoParam):
destination, (partition_key, files) = element
return [(destination, (partition_key, files, pane_info.index))]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very similar to a first attempt to fix the same issue in Java - #28272 add pane info in "WritePartition" so it is survived in ReShuffle. In earlier discussion it was decided to go with fixing ReShuffle itself (and that PR was closed). Shall we go for same decision here?

Copy link
Contributor

@Abacn Abacn Mar 18, 2025

Choose a reason for hiding this comment

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

One of the original concern was upgrade compatibility. However because a ReShuffle is added here, pipeline graph will be changed anyways

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to do this keying by pane in the upstream PartitionFiles DoFn? i.e. instead of creating a new dedicated step.

I think that'll make it easier to revert this quick fix when Reshuffle gets fixed (which should be the longterm solution)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants