private void resetAndQueueKill(Map<WmTezSession, KillQueryContext> toKillQuery,
    KillQueryContext killQueryContext, Map<WmTezSession, GetRequest> toReuse) {

    WmTezSession toKill = killQueryContext.session;
    String poolName = toKill.getPoolName();

    boolean validPoolName = StringUtils.isNotBlank(poolName);

    if (validPoolName) {
      killQueryContext.setPoolName(poolName);
    }
    toKillQuery.put(toKill, killQueryContext);

    // The way this works is, a session in WM pool will move back to tez AM pool on a kill and will get
    // reassigned back to WM pool on GetRequest based on user pool mapping. Only if we remove the session from active
    // sessions list of its WM pool will the queue'd GetRequest be processed
    if (validPoolName) {
      PoolState poolState = pools.get(poolName);
      if (poolState != null) {
        poolState.getSessions().remove(toKill);
        Iterator<SessionInitContext> iter = poolState.getInitializingSessions().iterator();
        while (iter.hasNext()) {
          if (iter.next().session == toKill) {
            iter.remove();
            break;
          }
        }
      }
    }

    toKill.clearWm();
    GetRequest req = toReuse.remove(toKill);
    if (req != null) {
      req.sessionToReuse = null;
    }
  }
When we kill a query without killing a session, we need two things to come back before reuse.
First of all, kill query itself should come back, and second the user should handle it
and let go of the session (or, the query could finish and it could give the session back
even before we try to kill the query). We also need to handle cases where the user doesn't
like the session even before we kill it, or the kill fails and the user is happily computing
away. This class is to collect and make sense of the state around all this.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/WorkloadManager.java