public void killQuery(String queryIdOrTag, String doAs, boolean doAsAdmin) throws IOException {
    List<String> serverHosts = getAllServerUrls();
    if (serverHosts.size() < 2) {
      return;
    }
    KillQueryZookeeperBarrier barrier = new KillQueryZookeeperBarrier(zooKeeperClient, "/" + zkNameSpace);
    boolean result;
    try {
      barrier.setBarrier(queryIdOrTag, hiveServer2.getServerInstanceURI(), doAs, doAsAdmin);
      LOG.info("Created kill query barrier in path: {} for queryId: {}", barrier.getBarrierPath(), queryIdOrTag);
      result = barrier.waitOnBarrier(serverHosts.size() - 1, MAX_WAIT_ON_CONFIRMATION_SECONDS,
          MAX_WAIT_ON_KILL_SECONDS, TimeUnit.SECONDS);

    } catch (Exception e) {
      LOG.error("Unable to create Barrier on Zookeeper for KillQuery", e);
      throw new IOException(e);
    }
    if (!result) {
      throw new IOException("Unable to kill query on remote servers");
    }
  }
Post a kill query request on Zookeeper for the other HS2 instances. If the service discovery is not enabled or
there is no other server registered, does nothing. Otherwise post the kill query request on Zookeeper
and waits for the other instances to confirm the kill or deny it.

@param queryIdOrTag queryId or tag to kill
@param doAs         user requesting the kill
@param doAsAdmin    admin user requesting the kill (with KILLQUERY privilege)
@throws IOException If the kill query failed
service/src/java/org/apache/hive/service/server/KillQueryZookeeperManager.java