Author: vgumashta
Date: Sun Oct 26 23:53:00 2014
New Revision: 1634408

URL: http://svn.apache.org/r1634408
Log:
HIVE-8596: HiveServer2 dynamic service discovery: ZK throws too many 
connections error (Vaibhav Gumashta reviewed by Thejas Nair)

Modified:
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java

Modified: 
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java?rev=1634408&r1=1634407&r2=1634408&view=diff
==============================================================================
--- 
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java 
(original)
+++ 
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java 
Sun Oct 26 23:53:00 2014
@@ -59,9 +59,10 @@ public class ZooKeeperHiveClientHelper {
     List<String> serverHosts;
     Random randomizer = new Random();
     String serverNode;
+    ZooKeeper zooKeeperClient = null;
     // Pick a random HiveServer2 host from the ZooKeeper namspace
     try {
-      ZooKeeper zooKeeperClient =
+      zooKeeperClient =
           new ZooKeeper(zooKeeperEnsemble, 
JdbcConnectionParams.ZOOKEEPER_SESSION_TIMEOUT,
               new ZooKeeperHiveClientHelper.DummyWatcher());
       // All the HiveServer2 host nodes that are in ZooKeeper currently
@@ -83,7 +84,15 @@ public class ZooKeeperHiveClientHelper {
       return serverUri;
     } catch (Exception e) {
       throw new ZooKeeperHiveClientException("Unable to read HiveServer2 uri 
from ZooKeeper", e);
+    } finally {
+      // Try to close the client connection with ZooKeeper
+      if (zooKeeperClient != null) {
+        try {
+          zooKeeperClient.close();
+        } catch (Exception e) {
+          // No-op
+        }
+      }
     }
   }
-
 }


Reply via email to