private RemoveSessionResult checkAndRemoveSessionFromItsPool(WmTezSession session,
      Set<String> poolsToRedistribute, Boolean isSessionOk, boolean updateMetrics) {
    // It is possible for some request to be queued after a main thread has decided to kill this
    // session; on the next iteration, we'd be processing that request with an irrelevant session.
    if (session.isIrrelevantForWm()) {
      return RemoveSessionResult.IGNORE;
    }
    if (killQueryInProgress.containsKey(session)) {
      if (isSessionOk != null) {
        killQueryInProgress.get(session).handleUserCallback(!isSessionOk);
      }
      return RemoveSessionResult.IGNORE;
    }
    // If we did not kill this session we expect everything to be present.
    String poolName = session.getPoolName();
    if (poolName != null) {
      poolsToRedistribute.add(poolName);
      PoolState pool = pools.get(poolName);
      session.clearWm();
      if (pool != null && pool.sessions.remove(session)) {
        if (updateMetrics && pool.metrics != null) {
          pool.metrics.removeRunningQueries(1);
        }
        return RemoveSessionResult.OK;
      }
    }
    LOG.error("Session was not in the pool (internal error) " + poolName + ": " + session);
    return RemoveSessionResult.NOT_FOUND;
  }
Checks if the session is still relevant for WM and if yes, removes it from its thread.
@param isSessionOk Whether the user thinks the session being returned in some way is ok;
                   true means it is (return, reuse); false mean it isn't (reopen, destroy);
                   null means this is not a user call.
@return true if the session was removed; false if the session was already processed by WM
        thread (so we are dealing with an outdated request); null if the session should be
        in WM but wasn't found in the requisite pool (internal error?).
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/WorkloadManager.java