public void addSources(List<TaskSource> sources) {
    checkNotNull(sources, "sources is null");
    checkState(
        !Thread.holdsLock(this),
        "Can not add sources while holding a lock on the %s",
        getClass().getSimpleName());

    try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
      // update our record of sources and schedule drivers for new partitioned splits
      Map<PlanNodeId, TaskSource> updatedUnpartitionedSources = updateSources(sources);

      // tell existing drivers about the new splits; it is safe to update drivers
      // multiple times and out of order because sources contain full record of
      // the unpartitioned splits
      for (TaskSource source : updatedUnpartitionedSources.values()) {
        // tell all the existing drivers this source is finished
        for (WeakReference<Driver> driverReference : drivers) {
          Driver driver = driverReference.get();
          // the driver can be GCed due to a failure or a limit
          if (driver != null) {
            driver.updateSource(source);
          } else {
            // remove the weak reference from the list to avoid a memory leak
            // NOTE: this is a concurrent safe operation on a CopyOnWriteArrayList
            drivers.remove(driverReference);
          }
        }
      }

      // we may have transitioned to no more splits, so check for completion
      checkTaskCompletion();
    }
  }
 @Override
 public void stateChanged(BufferState taskState) {
   if (taskState == BufferState.FINISHED) {
     SqlTaskExecution sqlTaskExecution = sqlTaskExecutionReference.get();
     if (sqlTaskExecution != null) {
       sqlTaskExecution.checkTaskCompletion();
     }
   }
 }
  @Override
  public TaskInfo getTaskInfo(boolean full) {
    try (SetThreadName setThreadName = new SetThreadName("Task-%s", taskId)) {
      checkTaskCompletion();

      TaskState state = taskStateMachine.getState();
      List<ExecutionFailureInfo> failures = ImmutableList.of();
      if (state == TaskState.FAILED) {
        failures = toFailures(taskStateMachine.getFailureCauses());
      }

      return new TaskInfo(
          taskStateMachine.getTaskId(),
          nextTaskInfoVersion.getAndIncrement(),
          state,
          location,
          lastHeartbeat.get(),
          sharedBuffer.getInfo(),
          getNoMoreSplits(),
          taskContext.getTaskStats(),
          failures);
    }
  }