HBASE-11332 Fix for metas location cache from HBASE-10785

This commit is contained in:
Enis Soztutar 2014-06-25 00:58:40 -07:00
parent 8e40fa0c41
commit 14a09e79bd
2 changed files with 30 additions and 4 deletions

View File

@ -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) {

View File

@ -356,6 +356,7 @@ public class TestHCM {
final AtomicReference<Throwable> failed = new AtomicReference<Throwable>(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();
}
}