diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java index d3f4078..2f57ed8 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java @@ -1117,7 +1117,6 @@ class ConnectionManager { throw new IllegalArgumentException( "table name cannot be null or zero length"); } - if (tableName.equals(TableName.META_TABLE_NAME)) { return locateMeta(tableName, useCache, replicaId); } else { @@ -1145,10 +1144,13 @@ class ConnectionManager { synchronized (metaRegionLock) { // Check the cache again for a hit in case some other thread made the // same query while we were waiting on the lock. - locations = getCachedLocation(tableName, metaCacheKey); - if (locations != null) { - return locations; + if (useCache) { + locations = getCachedLocation(tableName, metaCacheKey); + if (locations != null) { + return locations; + } } + // Look up from zookeeper locations = this.registry.getMetaRegionLocation(); if (locations != null) { diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index 7526ecc..b40ca17 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -270,6 +270,7 @@ public class TestHCM { final AtomicReference failed = new AtomicReference(null); Thread t = new Thread("testConnectionCloseThread") { + @Override public void run() { int done = 0; try { @@ -1164,5 +1165,28 @@ public class TestHCM { } pool.shutdownNow(); } + + @Test(timeout = 60000) + public void testConnectionRideOverClusterRestart() throws IOException, InterruptedException { + Configuration config = new Configuration(TEST_UTIL.getConfiguration()); + + TableName tableName = TableName.valueOf("testConnectionRideOverClusterRestart"); + TEST_UTIL.createTable(tableName.getName(), new byte[][] {FAM_NAM}, config).close(); + + HConnection connection = HConnectionManager.createConnection(config); + HTableInterface table = connection.getTable(tableName); + + // this will cache the meta location and table's region location + table.get(new Get(Bytes.toBytes("foo"))); + + // restart HBase + TEST_UTIL.shutdownMiniHBaseCluster(); + TEST_UTIL.restartHBaseCluster(2); + // this should be able to discover new locations for meta and table's region + table.get(new Get(Bytes.toBytes("foo"))); + TEST_UTIL.deleteTable(tableName); + table.close(); + connection.close(); + } }