public boolean extractSessionAndCancelIfDone(
        List<WmTezSession> results, List<Path> toDelete) {
      lock.lock();
      try {
        if (state != SessionInitState.DONE) return false;
        this.state = SessionInitState.CANCELED;
        if (pathToDelete != null) {
          toDelete.add(pathToDelete);
        }
        if (this.session != null) {
          results.add(this.session);
        } // Otherwise we have failed; the callback has taken care of the failure.
        this.session = null;
        return true;
      } finally {
        lock.unlock();
      }
    }
Extracts the session and cancel the operation, both only if done.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/WorkloadManager.java