-
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
Invoke teardown when DoFn throws in portable runners #32522
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Java_PVR_Flink_Batch.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test" | ||
"modification": 1 | ||
} |
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Java_PVR_Flink_Streaming.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"modification": 0 | ||
"modification": 1 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"modification": 0 | ||
"modification": 1 | ||
} |
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Java_PVR_Spark3_Streaming.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"modification": 0 | ||
"modification": 1 | ||
} |
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Java_PVR_Spark_Batch.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"modification": 0 | ||
"modification": 1 | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,7 +596,11 @@ public BeamFnApi.InstructionResponse.Builder processBundle(BeamFnApi.Instruction | |
request.getProcessBundle().getProcessBundleDescriptorId(), bundleProcessor); | ||
return BeamFnApi.InstructionResponse.newBuilder().setProcessBundle(response); | ||
} catch (Exception e) { | ||
// Make sure we clean-up from the active set of bundle processors. | ||
// Make sure we clean up from the active set of bundle processors. | ||
LOG.debug( | ||
"Discard bundleProcessor for {} after exception: {}", | ||
request.getProcessBundle().getProcessBundleDescriptorId(), | ||
e.getMessage()); | ||
bundleProcessorCache.discard(bundleProcessor); | ||
throw e; | ||
} | ||
|
@@ -1168,13 +1172,26 @@ void discard() { | |
if (this.bundleCache != null) { | ||
this.bundleCache.clear(); | ||
} | ||
// setupFunctions are invoked in createBundleProcessor. Invoke teardownFunction here as the | ||
// BundleProcessor is already removed from cache and won't be re-used. | ||
for (ThrowingRunnable teardownFunction : Lists.reverse(this.getTearDownFunctions())) { | ||
try { | ||
teardownFunction.run(); | ||
} catch (Throwable e) { | ||
LOG.warn( | ||
"Exceptions are thrown from DoFn.teardown method when trying to discard " | ||
+ "ProcessBundleHandler", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusted to warning and wording of it. Originally it was an Error, which may cause confuse on the cause of the error in case of a failed pipeline (the cause is upstream error in processElement, etc. not tearDown throws) |
||
e); | ||
} | ||
} | ||
getMetricsEnvironmentStateForBundle().discard(); | ||
for (BeamFnDataOutboundAggregator aggregator : getOutboundAggregators().values()) { | ||
aggregator.discard(); | ||
} | ||
} | ||
} | ||
|
||
// this is called in cachedBundleProcessors removal listener | ||
void shutdown() { | ||
for (ThrowingRunnable tearDownFunction : getTearDownFunctions()) { | ||
LOG.debug("Tearing down function {}", tearDownFunction); | ||
|
Oops, something went wrong.
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.
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.
if we throw the exception above during one of the start functions we may not have called all of them. That could be confusing since then finish could be called without corresponding start. If we knew which start/teardown functions corresponeded (ie change to a single list with both matched up) we coudl remember the index we made it to on start functions to call teardown only on the right ones.
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.
The naming here was confusing.
startFunction
are forstartBundle
.tearDown
corresponds tosetup
in terms of DoFns, wheresetup
was called as early as:that was when BundleProcessor gets created. Therefore in bundleProcessor.discard call DoFn's
@Setup
have been called before.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.
If the question is about throw the exception in
setupFunction
, then tearDown is invoked earlier, atbeam/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvokers.java
Line 56 in c3be9f0
and createBundleProcessor won't complete and discard() method won't invoked
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.
the DoFnInvoker link where teardown is called if exception during startup is for a single DoFn.
If we have fused DoFnA->DoFnB we start in reverse order. If A throws exception in setup, tearDown is invoked on DoFnA. Do we call teardown on B which had startup invoked? If not we probably need some try catch in createBundleProcessor to invoke the added teardown functions.
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.
Tested that teardown on B isn't called, indeed. However this is same for legacy runner, except for legacy runner setup is called in sequence order (not reverse), which means if B throws in setup, tearDown in A won't be called.
Prefer to note this as a separate issue for now.