Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/11340#discussion_r54193748
--- Diff: core/src/main/scala/org/apache/spark/TaskContextImpl.scala ---
@@ -55,14 +58,30 @@ private[spark] class TaskContextImpl(
this
}
- override def addTaskCompletionListener(f: TaskContext => Unit):
this.type = {
- onCompleteCallbacks += new TaskCompletionListener {
- override def onTaskCompletion(context: TaskContext): Unit =
f(context)
- }
+ override def addTaskFailureListener(listener: TaskFailureListener):
this.type = {
+ onFailureCallbacks += listener
this
}
- /** Marks the task as completed and triggers the listeners. */
+ /** Marks the task as completed and triggers the failure listeners. */
+ private[spark] def markTaskFailed(error: Throwable): Unit = {
+ val errorMsgs = new ArrayBuffer[String](2)
+ // Process complete callbacks in the reverse order of registration
+ onFailureCallbacks.reverse.foreach { listener =>
+ try {
+ listener.onTaskFailure(this, error)
+ } catch {
+ case e: Throwable =>
+ errorMsgs += e.getMessage
+ logError("Error in TaskFailureListener", e)
+ }
+ }
+ if (errorMsgs.nonEmpty) {
+ throw new TaskCompletionListenerException(errorMsgs)
--- End diff --
Also make sure that we don't mask the original exception.
---
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]