public synchronized boolean waitOnBarrier(int confirmationCount, long maxWaitOnConfirmation, long maxWaitOnKill,
        TimeUnit unit) throws Exception {
      long startMs = System.currentTimeMillis();
      long startKill = -1;
      long maxWaitMs = TimeUnit.MILLISECONDS.convert(maxWaitOnConfirmation, unit);
      long maxWaitOnKillMs = TimeUnit.MILLISECONDS.convert(maxWaitOnKill, unit);

      boolean progress = false;
      boolean result = false;
      while (true) {
        List<String> children = client.getChildren().usingWatcher(watcher).forPath(barrierPath);
        boolean concluded = false;
        for (String child : children) {
          if (child.startsWith("DONE")) {
            result = true;
            concluded = true;
            break;
          }
          if (child.startsWith("FAILED")) {
            concluded = true;
            break;
          }
          if (child.startsWith("PROGRESS")) {
            progress = true;
          }
        }
        if (concluded) {
          break;
        }
        if (progress) {
          // Wait for the kill query to finish
          if (startKill < 0) {
            startKill = System.currentTimeMillis();
          }
          long elapsed = System.currentTimeMillis() - startKill;
          long thisWaitMs = maxWaitOnKillMs - elapsed;
          if (thisWaitMs <= 0) {
            break;
          }
          wait(thisWaitMs);
        } else {
          if (children.size() == confirmationCount) {
            result = false;
            break;
          }
          // Wait for confirmation
          long elapsed = System.currentTimeMillis() - startMs;
          long thisWaitMs = maxWaitMs - elapsed;
          if (thisWaitMs <= 0) {
            break;
          }
          wait(thisWaitMs);
        }

      }
      client.delete().deletingChildrenIfNeeded().forPath(barrierPath);
      return result;
    }
Wait for every server either confirm killing the query or confirm not knowing the query.

@param confirmationCount     number of confirmation to wait for
@param maxWaitOnConfirmation confirmation waiting timeout for NO answers
@param maxWaitOnKill         timeout for waiting on the actual kill query operation
@param unit                  time unit for timeouts
@return true if the kill was confirmed, false on timeout or if everybody voted for NO
@throws Exception If confirmation failed
service/src/java/org/apache/hive/service/server/KillQueryZookeeperManager.java