-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Reduce setDefaultPipelineOptions call on creating TestPipelineOptions #32723
Conversation
482a93c
to
17ed411
Compare
tested added log to "setDefaultPipelineOptionsOnce" as well as inside "setDefaultPipelineOptions". Found
This suggests there was excessive call to "setDefaultPipelineOptions" which becomes source of Exception when there is lots of jars in classLoader (added by Spark) |
PostCommit Java PVR Spark Batch passed in first run |
514c8cb
to
a9d504f
Compare
a9d504f
to
0bdb00a
Compare
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
assign set of reviewers |
Assigning reviewers. If you would like to opt out of this review, comment R: @m-trieu for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
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.
LGTM, thanks
Fix #30512
Problem statement
Random tests in this test suite failing due to tmp file get deleted half way, likely a racing condition.
Investigation
This is a longstanding and tricky issue, see earlier investigation in
#30512 (comment)
as the validate runner test set adds//enables more tests, the test becomes increasingly flaky.
setDefaultPipelineOptions
In TestPipeline scenario, it is found that setDefaultPipelineOptions is called at least twice
When TestPipelineOptions object is created:
beam/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
Line 518 in 4cf99ea
Right before pipeline runs :
beam/sdks/java/core/src/main/java/org/apache/beam/sdk/PipelineRunner.java
Line 47 in 4cf99ea
Note that if "options.revision" does not change, the second call should usually be skipped. However there are multiple place modifying pipeline options before submit (amending some options). Checked that in the first call, revision=2; in the second call, revision=4. Therefore both run resulted in rebuild the map.
If run by "runWithAddidionalArgument", there is a third call:
beam/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
Line 376 in 4cf99ea
The first run is even triggered when the test is filtered by a wildcard, where junit still runs
@Rule TestPipelineOptions options = TestPipelineOption.create()
Assumptions of what happened
Assumption 1
Spark runner first put jars in a temp directory (
/temp/.../userFiles/...
), load jars into class loader (#30512 (comment)), and after pipeline run delete these files (likely in a async way, there is "shutdown hook called..." appeared in log)At the same time in tests, setDefaultPipelineOptions are called, invoking ServiceLoader, looking for registered services in the classloader. For PortableSparkRunner tests. It causes racing condition when class loader still has jars entry from previous test that has been deleted.
Assumption 2
Executing the tests locally (on macOS) there are other intermittent test failure, but now FileNotFoundException has a hint (Too many files open). It could also be that ServiceLoader is opening lots of files if running frequently.
Nevertheless, both observation agrees with excessive call to
setDefaultPipelineOptions
in test pipeline submission time.Solution
This PR reduces call to
setDefaultPipelineOptions
in two places in TestPipeline.java. This reducessetDefaultPipelineOptions
call by at least half.Risk
There is potential risk of FileSystem stored PipelineOptions is out of sync between TestPipelineOptions.create and testPipeline.run(). I would argue this is of less concern because
TestPipeline / TestPipelineOptions are meant by tests, this change does not affect dev and prod settings.
Under current setting out-of-sync can already happen. Consider the following code
Under the current implementation of using a Static map for PipelineOption initalized FileSystem, whenever there are multiple pipelines, it can always be out-of-sync.
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
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, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.