diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 763b79f..6455c07 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -604,9 +604,8 @@ public class HConnectionManager { this.clusterId = this.registry.getClusterId(); if (clusterId == null) { clusterId = HConstants.CLUSTER_ID_DEFAULT; + LOG.debug("clusterid came back null, using default " + clusterId); } - - LOG.info("ClusterId is " + clusterId); } @Override diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java index dde0740..5f6f45c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java @@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.zookeeper.MetaRegionTracker; +import org.apache.hadoop.hbase.zookeeper.ZKClusterId; import org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly; import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.zookeeper.KeeperException; @@ -69,10 +70,28 @@ class ZooKeeperRegistry implements Registry { } } + private String clusterId = null; + @Override public String getClusterId() { - // TODO Auto-generated method stub - return null; + if (this.clusterId != null) return this.clusterId; + // No synchronized here, worse case we will retrieve it twice, that's + // not an issue. + ZooKeeperKeepAliveConnection zkw = null; + try { + zkw = hci.getKeepAliveZooKeeperWatcher(); + this.clusterId = ZKClusterId.readClusterIdZNode(zkw); + if (this.clusterId == null) { + LOG.info("ClusterId read in ZooKeeper is null"); + } + } catch (KeeperException e) { + LOG.warn("Can't retrieve clusterId from Zookeeper", e); + } catch (IOException e) { + LOG.warn("Can't retrieve clusterId from Zookeeper", e); + } finally { + if (zkw != null) zkw.close(); + } + return this.clusterId; } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index 554e45f..229015b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -809,7 +809,11 @@ public class TestHCM { @Test public void testDeleteForZKConnLeak() throws Exception { TEST_UTIL.createTable(TABLE_NAME4, FAM_NAM); - final Configuration config = TEST_UTIL.getConfiguration(); + final Configuration config = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); + config.setInt("zookeeper.recovery.retry", 1); + config.setInt("zookeeper.recovery.retry.intervalmill", 1000); + config.setInt("hbase.rpc.timeout", 2000); + config.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3); ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 10, 5, TimeUnit.SECONDS, @@ -822,7 +826,10 @@ public class TestHCM { while (!Thread.interrupted()) { try { HConnection conn = HConnectionManager.getConnection(config); + LOG.info("Connection " + conn); HConnectionManager.deleteStaleConnection(conn); + LOG.info("Connection closed " + conn); + Threads.sleep(100); } catch (Exception e) { } } @@ -830,13 +837,16 @@ public class TestHCM { }); // use connection multiple times - for (int i = 0; i < 50; i++) { + for (int i = 0; i < 30; i++) { HConnection c1 = null; try { c1 = HConnectionManager.getConnection(config); + LOG.info("HTable connection " + i + " " + c1); HTable table = new HTable(TABLE_NAME4, c1, pool); table.close(); + LOG.info("HTable connection " + i + " closed " + c1); } catch (Exception e) { + LOG.info("This can happen", e); } finally { if (c1 != null) { if (c1.isClosed()) {