public WmTezSession getSession(TezSessionState session, MappingInput input, HiveConf conf,
      final WmContext wmContext) throws Exception {
    WmEvent wmEvent = new WmEvent(WmEvent.EventType.GET);
    // Note: not actually used for pool sessions; verify some things like doAs are not set.
    validateConfig(conf);
    String queryId = HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_QUERY_ID);
    SettableFuture<WmTezSession> future = SettableFuture.create();
    WmTezSession wmSession = checkSessionForReuse(session);
    GetRequest req = new GetRequest(
        input, queryId, future, wmSession, getRequestVersion.incrementAndGet(), wmContext);
    currentLock.lock();
    try {
      current.getRequests.add(req);
      if (req.sessionToReuse != null) {
        // Note: we assume reuse is only possible for the same user and config.
        current.toReuse.put(wmSession, req);
      }
      notifyWmThreadUnderLock();
    } finally {
      currentLock.unlock();
    }
    try {
      WmTezSession sessionState = future.get();
      wmEvent.endEvent(sessionState);
      return sessionState;
    } catch (ExecutionException ex) {
      Throwable realEx = ex.getCause();
      throw realEx instanceof Exception ? (Exception)realEx : ex;
    }
  }
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