diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index cd425aa..e3c1619 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -3012,6 +3012,8 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "The parent node in ZooKeeper used by HiveServer2 when supporting dynamic service discovery."), HIVE_SERVER2_ZOOKEEPER_PUBLISH_CONFIGS("hive.server2.zookeeper.publish.configs", true, "Whether we should publish HiveServer2's configs to ZooKeeper."), + HIVE_SERVER2_LEADER_ZOOKEEPER_NAMESPACE("hive.server2.leader.zookeeper.namespace", "hiveserver2-leader", + "Zookeeper znode for HiveServer2 leader selection."), // HiveServer2 global init file location HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION("hive.server2.global.init.file.location", "${env:HIVE_CONF_DIR}", @@ -4312,7 +4314,6 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "hive.server2.authentication.ldap.userMembershipKey," + "hive.server2.authentication.ldap.groupClassKey," + "hive.server2.authentication.ldap.customLDAPQuery," + - "hive.privilege.synchronizer," + "hive.privilege.synchronizer.interval," + "hive.spark.client.connect.timeout," + "hive.spark.client.server.connect.timeout," + diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java index 6184fdc..15cf6a7 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -147,6 +147,7 @@ private PersistentEphemeralNode znode; private CuratorFramework zooKeeperClient; private CuratorFramework zKClientForPrivSync = null; + private LeaderLatch privilegeSynchonizerLatch = null; private boolean deregisteredWithZooKeeper = false; // Set to true only when deregistration happens private HttpServer webServer; // Web UI private TezSessionPoolManager tezSessionPoolManager; @@ -945,6 +946,14 @@ public synchronized void stop() { if (zKClientForPrivSync != null) { zKClientForPrivSync.close(); } + + if (privilegeSynchonizerLatch != null) { + try { + privilegeSynchonizerLatch.close(); + } catch (IOException e) { + LOG.error("Error close privilegeSynchonizerLatch"); + } + } } private void shutdownExecutor(final ExecutorService leaderActionsExecutorService) { @@ -1000,10 +1009,21 @@ public void startPrivilegeSynchonizer(HiveConf hiveConf) throws Exception { if (policyContainer.size() > 0) { zKClientForPrivSync = startZookeeperClient(hiveConf); - String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE); + String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_LEADER_ZOOKEEPER_NAMESPACE); + // Create the parent znodes recursively; ignore if the parent already exists. + try { + zKClientForPrivSync.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) + .forPath(ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace); + LOG.info("Created the root name space: " + rootNamespace + " on ZooKeeper for HiveServer2"); + } catch (KeeperException e) { + if (e.code() != KeeperException.Code.NODEEXISTS) { + LOG.error("Unable to create HiveServer2 namespace: " + rootNamespace + " on ZooKeeper", e); + throw e; + } + } String path = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace - + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "leader"; - LeaderLatch privilegeSynchonizerLatch = new LeaderLatch(zKClientForPrivSync, path); + + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "privilege_synchonizer"; + privilegeSynchonizerLatch = new LeaderLatch(zKClientForPrivSync, path); privilegeSynchonizerLatch.start(); Thread privilegeSynchonizerThread = new Thread( new PrivilegeSynchonizer(privilegeSynchonizerLatch, policyContainer, hiveConf), "PrivilegeSynchonizer");