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 0f8d67f..ebcabf8 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -2016,6 +2016,8 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "hive.zookeeper.quorum in their connection string."), HIVE_SERVER2_ZOOKEEPER_NAMESPACE("hive.server2.zookeeper.namespace", "hiveserver2", "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 the server configs in ZooKeeper."), // HiveServer2 global init file location HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION("hive.server2.global.init.file.location", "${env:HIVE_CONF_DIR}", diff --git a/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java b/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java index 1ca77a1..3ee5967 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java +++ b/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java @@ -48,17 +48,16 @@ public void process(org.apache.zookeeper.WatchedEvent event) { static void configureConnParams(JdbcConnectionParams connParams) throws ZooKeeperHiveClientException { String zooKeeperEnsemble = connParams.getZooKeeperEnsemble(); - String zooKeeperNamespace = - connParams.getSessionVars().get(JdbcConnectionParams.ZOOKEEPER_NAMESPACE); + String zooKeeperNamespace = connParams.getSessionVars().get( + JdbcConnectionParams.ZOOKEEPER_NAMESPACE); if ((zooKeeperNamespace == null) || (zooKeeperNamespace.isEmpty())) { zooKeeperNamespace = JdbcConnectionParams.ZOOKEEPER_DEFAULT_NAMESPACE; } List serverHosts; Random randomizer = new Random(); String serverNode; - CuratorFramework zooKeeperClient = - CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) - .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); + CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder() + .connectString(zooKeeperEnsemble).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); try { zooKeeperClient.start(); serverHosts = zooKeeperClient.getChildren().forPath("/" + zooKeeperNamespace); @@ -71,14 +70,27 @@ static void configureConnParams(JdbcConnectionParams connParams) // Now pick a server node randomly serverNode = serverHosts.get(randomizer.nextInt(serverHosts.size())); connParams.setCurrentHostZnodePath(serverNode); - // Read config string from the znode for this server node - String serverConfStr = - new String( - zooKeeperClient.getData().forPath("/" + zooKeeperNamespace + "/" + serverNode), - Charset.forName("UTF-8")); - applyConfs(serverConfStr, connParams); + // Read data from the znode for this server node + // This data could be either config string (new releases) or server end + // point (old releases) + String dataStr = new String(zooKeeperClient.getData().forPath( + "/" + zooKeeperNamespace + "/" + serverNode), Charset.forName("UTF-8")); + Matcher matcher = kvPattern.matcher(dataStr); + // If dataStr is not null and dataStr is not a KV pattern, + // it must be the server uri added by an older version HS2 + if ((dataStr != null) && (!matcher.find())) { + String[] split = dataStr.split(":"); + if (split.length != 2) { + throw new ZooKeeperHiveClientException("Unable to read HiveServer2 uri from ZooKeeper"); + } + connParams.setHost(split[0]); + connParams.setPort(Integer.parseInt(split[1])); + } + else { + applyConfs(dataStr, connParams); + } } catch (Exception e) { - throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e); + throw new ZooKeeperHiveClientException("Unable to read HiveServer2 data from ZooKeeper", e); } finally { // Close the client connection with ZooKeeper if (zooKeeperClient != null) { 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 ab834b9..e29c6ac 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -254,25 +254,18 @@ private void addServerInstanceToZooKeeper(HiveConf hiveConf) throws Exception { String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE); String instanceURI = getServerInstanceURI(); setUpZooKeeperAuth(hiveConf); - // HiveServer2 configs that this instance will publish to ZooKeeper, - // so that the clients can read these and configure themselves properly. - Map confsToPublish = new HashMap(); - addConfsToPublish(hiveConf, confsToPublish); - int sessionTimeout = - (int) hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, - TimeUnit.MILLISECONDS); - int baseSleepTime = - (int) hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, - TimeUnit.MILLISECONDS); + int sessionTimeout = (int) hiveConf.getTimeVar( + HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS); + int baseSleepTime = (int) hiveConf.getTimeVar( + HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS); int maxRetries = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES); // Create a CuratorFramework instance to be used as the ZooKeeper client // Use the zooKeeperAclProvider to create appropriate ACLs - zooKeeperClient = - CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) - .sessionTimeoutMs(sessionTimeout).aclProvider(zooKeeperAclProvider) - .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)).build(); + zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) + .sessionTimeoutMs(sessionTimeout).aclProvider(zooKeeperAclProvider) + .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)).build(); zooKeeperClient.start(); - // Create the parent znodes recursively; ignore if the parent already exists. + // Create parent znodes recursively; ignore if parent already exists. try { zooKeeperClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .forPath(ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace); @@ -283,20 +276,27 @@ private void addServerInstanceToZooKeeper(HiveConf hiveConf) throws Exception { throw e; } } - // Create a znode under the rootNamespace parent for this instance of the server - // Znode name: serverUri=host:port;version=versionInfo;sequence=sequenceNumber + // Create a znode under the rootNamespace parent for this instance of the + // server. Znode name: + // serverUri=host:port;version=versionInfo;sequence=sequenceNumber try { - String pathPrefix = - ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace - + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "serverUri=" + instanceURI + ";" - + "version=" + HiveVersionInfo.getVersion() + ";" + "sequence="; + String pathPrefix = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace + + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "serverUri=" + instanceURI + ";" + + "version=" + HiveVersionInfo.getVersion() + ";" + "sequence="; String znodeData = ""; - // Publish configs for this instance as the data on the node - znodeData = Joiner.on(';').withKeyValueSeparator("=").join(confsToPublish); + if (hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_PUBLISH_CONFIGS)) { + // HiveServer2 configs that this instance will publish to ZooKeeper, + // so that the clients can read these and configure themselves properly. + Map confsToPublish = new HashMap(); + addConfsToPublish(hiveConf, confsToPublish); + // Publish configs for this instance as the data on the node + znodeData = Joiner.on(';').withKeyValueSeparator("=").join(confsToPublish); + } else { + znodeData = instanceURI; + } byte[] znodeDataUTF8 = znodeData.getBytes(Charset.forName("UTF-8")); - znode = - new PersistentEphemeralNode(zooKeeperClient, - PersistentEphemeralNode.Mode.EPHEMERAL_SEQUENTIAL, pathPrefix, znodeDataUTF8); + znode = new PersistentEphemeralNode(zooKeeperClient, + PersistentEphemeralNode.Mode.EPHEMERAL_SEQUENTIAL, pathPrefix, znodeDataUTF8); znode.start(); // We'll wait for 120s for node creation long znodeCreationTimeout = 120;