@Override
  public synchronized void start() {
    super.start();
    // If we're supporting dynamic service discovery, we'll add the service uri for this
    // HiveServer2 instance to Zookeeper as a znode.
    HiveConf hiveConf = getHiveConf();
    if (!serviceDiscovery || !activePassiveHA) {
      allowClientSessions();
    }
    if (serviceDiscovery) {
      try {
        if (activePassiveHA) {
          hs2HARegistry.registerLeaderLatchListener(leaderLatchListener, leaderActionsExecutorService);
          hs2HARegistry.start();
          LOG.info("HS2 HA registry started");
        } else {
          boolean publishConfigs =
                  hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_PUBLISH_CONFIGS);
          String instanceURI = getServerInstanceURI();
          String znodeData;
          if (publishConfigs) {
            // HiveServer2 configs that this instance will publish to ZooKeeper,
            // so that the clients can read these and configure themselves properly.
            addConfsToPublish(hiveConf, confsToPublish, getServerInstanceURI());
            znodeData = Joiner.on(';').withKeyValueSeparator("=").join(confsToPublish);
          } else {
            znodeData = instanceURI;
          }

          // Add a Znode to the specified ZooKeeper with name: serverUri=host:port;
          // version=versionInfo; sequence=sequenceNumber
          zooKeeperHelper = hiveConf.getZKConfig();
          String znodePathPrefix = "serverUri=" + instanceURI + ";" +
                  "version=" + HiveVersionInfo.getVersion() + ";" + "sequence=";
          zooKeeperHelper.addServerInstanceToZooKeeper(znodePathPrefix, znodeData,
                  zooKeeperAclProvider, new DeRegisterWatcher(zooKeeperHelper));
        }
      } catch (Exception e) {
        LOG.error("Error adding this HiveServer2 instance to ZooKeeper: ", e);
        throw new ServiceException(e);
      }
    }

    try {
      startPrivilegeSynchronizer(hiveConf);
    } catch (Exception e) {
      LOG.error("Error starting priviledge synchronizer: ", e);
      throw new ServiceException(e);
    }

    if (webServer != null) {
      try {
        webServer.start();
        LOG.info("Web UI has started on port " + webServer.getPort());
      } catch (Exception e) {
        LOG.error("Error starting Web UI: ", e);
        throw new ServiceException(e);
      }
    }

    if (hiveConf.getVar(ConfVars.HIVE_EXECUTION_ENGINE).equals("tez")) {
      if (!activePassiveHA) {
        LOG.info("HS2 interactive HA not enabled. Starting tez sessions..");
        try {
          startOrReconnectTezSessions();
        } catch (Exception e) {
          LOG.error("Error starting  Tez sessions: ", e);
          throw new ServiceException(e);
        }
      } else {
        LOG.info("HS2 interactive HA enabled. Tez sessions will be started/reconnected by the leader.");
      }
    }
  }
@return true if the server instance was deregistered from ZooKeeper, else false. The function might
be called even when the instance is not registered with the ZooKeeper (See
SessionManage.closeSessionInternal()). In that case, return false since the deregistration has
not really happened.
service/src/java/org/apache/hive/service/server/HiveServer2.java