Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17244#discussion_r106577342
  
    --- Diff: core/src/main/scala/org/apache/spark/TaskContextImpl.scala ---
    @@ -52,62 +63,79 @@ private[spark] class TaskContextImpl(
       @volatile private var interrupted: Boolean = false
     
       // Whether the task has completed.
    -  @volatile private var completed: Boolean = false
    +  private var completed: Boolean = false
     
       // Whether the task has failed.
    -  @volatile private var failed: Boolean = false
    +  private var failed: Boolean = false
    +
    +  // Throwable that caused the task to fail
    +  private var failure: Throwable = _
     
       // If there was a fetch failure in the task, we store it here, to make 
sure user-code doesn't
       // hide the exception.  See SPARK-19276
       @volatile private var _fetchFailedException: 
Option[FetchFailedException] = None
     
    -  override def addTaskCompletionListener(listener: 
TaskCompletionListener): this.type = {
    -    onCompleteCallbacks += listener
    +  @GuardedBy("this")
    +  override def addTaskCompletionListener(listener: TaskCompletionListener)
    +      : this.type = synchronized {
    +    if (completed) {
    +      listener.onTaskCompletion(this)
    --- End diff --
    
    `invokeListeners` takes a list of listeners, so we are able to only call 
this listener.
    
    I think it's better to make these listeners consistent, i.e. throw 
`TaskCompletionListenerException` when failure happens during calling listener.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to