private boolean addTaskPreemptionCandidate(TreeMap<Integer, TreeSet<TaskInfo>> runningTasks, TaskInfo forTask,
      Set<String> preemptHosts) {
    NavigableMap<Integer, TreeSet<TaskInfo>> orderedMap = runningTasks.descendingMap();
    Iterator<Entry<Integer, TreeSet<TaskInfo>>> iterator = orderedMap.entrySet().iterator();
    while (iterator.hasNext()) {
      Entry<Integer, TreeSet<TaskInfo>> entryAtPriority = iterator.next();
      if (entryAtPriority.getKey() > forTask.priority.getPriority()) {
        Iterator<TaskInfo> taskInfoIterator = entryAtPriority.getValue().iterator();
        while (taskInfoIterator.hasNext()) {
          TaskInfo taskInfo = taskInfoIterator.next();
          if (preemptHosts != null && !preemptHosts.contains(taskInfo.getAssignedNode().getHost())) {
            continue; // Not the right host.
          }
          Map<Integer, Set<Integer>> depInfo = getDependencyInfo(taskInfo.getAttemptId().getDAGID());
          Set<Integer> vertexDepInfo = null;
          if (depInfo != null) {
            vertexDepInfo = depInfo.get(vertexNum(forTask));
          }
          if (depInfo != null && vertexDepInfo == null) {
            LOG.warn("Cannot find info for " + vertexNum(forTask) + " " + depInfo);
          }
          if (vertexDepInfo != null && !vertexDepInfo.contains(vertexNum(taskInfo))) {
            // Only preempt if the task being preempted is "below" us in the dag.
            continue;
          }
          // If preemption Candidate is not already considered
          if (taskInfo.getPreemptedTime() == 0) {
            // Candidate for preemption.
            LOG.debug("Preemption candidate={} for Task={} with potentialHosts={}", taskInfo, forTask, preemptHosts);
            taskInfo.setPreemptedTime(clock.getTime());
            preemptionCandidates.add(taskInfo);
            return true;
          }
        }
      } else {
        // No tasks qualify as preemptable
        LOG.debug("No tasks qualify as preempt candidates for priority {}. Current priority={}",
            forTask.priority.getPriority(), entryAtPriority.getKey());
        break;
      }
    }
    return false;
  }
Go through the running tasks Tree in descending priority and find a candidate to preempt. The candidate should be:
1. lower priority than forTask
2. below forTask in the DAG
3. not considered already for preemption
A successful candidate is added to the preemptionCandidates queue for preemption by the scheduling loop.
@param runningTasks Tree of running tasks
@param forTask Task to find preemption candidate for
@param preemptHosts Hosts preference
@return true when preemption candidate is found
llap-tez/src/java/org/apache/hadoop/hive/llap/tezplugins/LlapTaskSchedulerService.java