code: private synchronized TaskInProgress findTaskFromList(
        Collection<TaskInProgress> tips, TaskTrackerStatus ttStatus,
        int numUniqueHosts,
        boolean removeFailedTip) {
      Iterator<TaskInProgress> iter = tips.iterator();
      while (iter.hasNext()) {
        TaskInProgress tip = iter.next();
  
        // Select a tip if
        //   1. runnable   : still needs to be run and is not completed
        //   2. ~running   : no other node is running it
        //   3. earlier attempt failed : has not failed on this host
        //                               and has failed on all the other hosts
        // A TIP is removed from the list if
        // (1) this tip is scheduled
        // (2) if the passed list is a level 0 (host) cache
        // (3) when the TIP is non-schedulable (running, killed, complete)
        if (tip.isRunnable() && !tip.isRunning()) {
          // check if the tip has failed on this host
          if (!tip.hasFailedOnMachine(ttStatus.getHost()) ||
               tip.getNumberOfFailedMachines() >= numUniqueHosts) {
            // check if the tip has failed on all the nodes
            iter.remove();
            return tip;
          } else if (removeFailedTip) {
            // the case where we want to remove a failed tip from the host cache
            // point#3 in the TIP removal logic above
            iter.remove();
          }
        } else {
          // see point#3 in the comment above for TIP removal logic
          iter.remove();
        }
      }
      return null;
    }
docs: Find a non-running task in the passed list of TIPs
  @param tips a collection of TIPs
  @param ttStatus the status of tracker that has requested a task to run
  @param numUniqueHosts number of unique hosts that run trask trackers
  @param removeFailedTip whether to remove the failed tips