Index: src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (revision 1004890) +++ src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (working copy) @@ -40,8 +40,12 @@ import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.proto.WatcherEvent; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -90,11 +94,11 @@ @Test public void testClientSessionExpired() throws IOException, InterruptedException { - new HTable(conf, HConstants.META_TABLE_NAME); - - String quorumServers = ZKConfig.getZKQuorumServersString(conf); + Configuration c = new Configuration(this.conf); + new HTable(c, HConstants.META_TABLE_NAME); + String quorumServers = ZKConfig.getZKQuorumServersString(c); int sessionTimeout = 5 * 1000; // 5 seconds - HConnection connection = HConnectionManager.getConnection(conf); + HConnection connection = HConnectionManager.getConnection(c); ZooKeeperWatcher connectionZK = connection.getZooKeeperWatcher(); long sessionID = connectionZK.getZooKeeper().getSessionId(); byte[] password = connectionZK.getZooKeeper().getSessionPasswd(); @@ -106,7 +110,8 @@ Thread.sleep(sessionTimeout * 3L); System.err.println("ZooKeeper should have timed out"); - connection.relocateRegion(HConstants.ROOT_TABLE_NAME, HConstants.EMPTY_BYTE_ARRAY); + Assert.assertTrue(connection.getZooKeeperWatcher().getZooKeeper(). + getState().equals(States.CLOSED)); } @Test Index: src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (revision 1004890) +++ src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (working copy) @@ -249,10 +249,13 @@ case Disconnected: LOG.info(prefix("Received Disconnected from ZooKeeper, ignoring")); break; + case Expired: - String msg = prefix("Received Expired from ZooKeeper, aborting server"); - LOG.error(msg); - if (abortable != null) abortable.abort(msg, null); + String msg = prefix(this.identifier + " received expired from " + + "ZooKeeper, aborting"); + // TODO: One thought is to add call to ZooKeeperListener so say, + // ZooKeperNodeTracker can zero out its data values. + if (this.abortable != null) this.abortable.abort(msg, null); break; } } Index: src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1004890) +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -515,7 +515,8 @@ private HRegionLocation locateRegion(final byte [] tableName, final byte [] row, boolean useCache) - throws IOException{ + throws IOException { + if (this.closed) throw new IOException("closed"); if (tableName == null || tableName.length == 0) { throw new IllegalArgumentException( "table name cannot be null or zero length"); @@ -525,7 +526,8 @@ try { HServerAddress hsa = this.rootRegionTracker.waitRootRegionLocation(this.rpcTimeout); - LOG.debug("Lookedup root region location " + hsa); + LOG.debug("Lookedup root region location, connection=" + this + + "; hsa=" + hsa); if (hsa == null) return null; return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa); } catch (InterruptedException e) { @@ -1030,6 +1032,7 @@ this.zooKeeper.close(); this.zooKeeper = null; } + this.closed = true; } private Callable createCallable( @@ -1289,6 +1292,7 @@ public void abort(final String msg, Throwable t) { if (t != null) LOG.fatal(msg, t); else LOG.fatal(msg); + this.closed = true; } } }