diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java index 92b99b49c3f..2059f915244 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java @@ -1092,7 +1092,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 { @@ -1119,10 +1118,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 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 bc1b5f51e97..e0f1dfb04e6 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 @@ -356,6 +356,7 @@ public class TestHCM { final AtomicReference failed = new AtomicReference(null); Thread t = new Thread("testConnectionCloseThread") { + @Override public void run() { int done = 0; try { @@ -1263,5 +1264,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(); + } }