private void killUnfinishedAttempt(TaskAttempt attempt, String logMsg) {
   if (commitAttempt != null && commitAttempt.equals(attempt)) {
     LOG.info("Removing commit attempt: " + commitAttempt);
     commitAttempt = null;
   }
   if (attempt != null && !attempt.isFinished()) {
     eventHandler.handle(new TaskAttemptEventKillRequest(attempt.getID(), logMsg));
   }
 }
    @Override
    public void transition(TaskImpl task, TaskEvent event) {
      TezTaskAttemptID successTaId = ((TaskEventTAUpdate) event).getTaskAttemptID();

      if (task.commitAttempt != null && !task.commitAttempt.equals(successTaId)) {
        // The succeeded attempt is not the one that was selected to commit
        // This is impossible and has to be a bug
        throw new TezUncheckedException(
            "TA: "
                + successTaId
                + " succeeded but TA: "
                + task.commitAttempt
                + " was expected to commit and succeed");
      }

      task.handleTaskAttemptCompletion(successTaId, TaskAttemptStateInternal.SUCCEEDED);
      task.finishedAttempts++;
      --task.numberUncompletedAttempts;
      task.successfulAttempt = successTaId;
      task.eventHandler.handle(new VertexEventTaskCompleted(task.taskId, TaskState.SUCCEEDED));
      LOG.info("Task succeeded with attempt " + task.successfulAttempt);
      if (task.historyTaskStartGenerated) {
        task.logJobHistoryTaskFinishedEvent();
      }

      // issue kill to all other attempts
      for (TaskAttempt attempt : task.attempts.values()) {
        if (attempt.getID() != task.successfulAttempt
            &&
            // This is okay because it can only talk us out of sending a
            //  TA_KILL message to an attempt that doesn't need one for
            //  other reasons.
            !attempt.isFinished()) {
          LOG.info("Issuing kill to other attempt " + attempt.getID());
          task.eventHandler.handle(
              new TaskAttemptEventKillRequest(attempt.getID(), "Alternate attempt succeeded"));
        }
      }
      // send notification to DAG scheduler
      task.eventHandler.handle(
          new DAGEventSchedulerUpdate(
              DAGEventSchedulerUpdate.UpdateType.TA_SUCCEEDED,
              task.attempts.get(task.successfulAttempt)));
      task.finished(TaskStateInternal.SUCCEEDED);
    }