private KillQueryResult process() {
      if (!isUserDone && hasKillFailed) {
        // The user has not returned and the kill has failed.
        // We are going to brute force kill the AM; whatever user does is now irrelevant.
        session.setIsIrrelevantForWm(reason);
        return KillQueryResult.RESTART_REQUIRED;
      }
      if (!isUserDone || !isKillDone) return KillQueryResult.IN_PROGRESS; // Someone is not done.
      // Both user and the kill have returned.
      if (hasUserFailed && hasKillFailed) {
        // If the kill failed and the user also thinks the session is invalid, restart it.
        session.setIsIrrelevantForWm(reason);
        return KillQueryResult.RESTART_REQUIRED;
      }
      // Otherwise, we can reuse the session. Either the kill has failed but the user managed to
      // return early (in fact, can it fail because the query has completed earlier?), or the user
      // has failed because the query was killed from under it.
      return KillQueryResult.OK;
    }
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