GitHub user hvanhovell opened a pull request:
https://github.com/apache/spark/pull/17244
[SPARK-19889][SQL] Make TaskContext callbacks thread safe
## What changes were proposed in this pull request?
It is sometimes useful to use multiple threads in a task to parallelize
tasks. These threads might register some completion/failure listeners to clean
up when the task is completed/interrupted. We currently cannot register such a
callback and be sure that it will get called, because the context might be in
the process of invoking its callbacks, when the the callback gets registered.
This PR improves this by synchronizing on the context itself when callbacks
are invoked or added. This allows you to write the following code, and be
guaranteed that the callback is invoked:
```scala
val ctx: TaskContext = ...
ctx.synchronized {
if (!ctx.isCompleted) {
cts.addTaskCompletionListener { _ =>
// Some clean-up logic.
}
}
}
```
## How was this patch tested?
Existing tests. Adding a test without significant overhead is non-trivial
and make testing flaky.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/hvanhovell/spark SPARK-19889
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/17244.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #17244
----
commit d16ad88d83351d8c514a389cf2b65605ee558b11
Author: Herman van Hovell <[email protected]>
Date: 2017-03-10T14:52:16Z
Make TaskContext callbacks threadsafe.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]