HBASE-15674 HRegionLocator#getAllRegionLocations should put the results in cache
This commit is contained in:
parent
58f175f0ea
commit
03f3c392a3
|
@ -86,6 +86,9 @@ public interface ClusterConnection extends HConnection {
|
|||
@Override
|
||||
void clearRegionCache();
|
||||
|
||||
|
||||
void cacheLocation(final TableName tableName, final RegionLocations location);
|
||||
|
||||
/**
|
||||
* Allows flushing the region cache of all locations that pertain to
|
||||
* <code>tableName</code>
|
||||
|
|
|
@ -927,7 +927,8 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
|
|||
* @param tableName The table name.
|
||||
* @param location the new location
|
||||
*/
|
||||
private void cacheLocation(final TableName tableName, final RegionLocations location) {
|
||||
@Override
|
||||
public void cacheLocation(final TableName tableName, final RegionLocations location) {
|
||||
metaCache.cacheLocation(tableName, location);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,11 +83,16 @@ public class HRegionLocator implements RegionLocator {
|
|||
|
||||
@Override
|
||||
public List<HRegionLocation> getAllRegionLocations() throws IOException {
|
||||
TableName tableName = getName();
|
||||
List<Pair<HRegionInfo, ServerName>> locations =
|
||||
MetaTableAccessor.getTableRegionsAndLocations(this.connection, getName());
|
||||
MetaTableAccessor.getTableRegionsAndLocations(this.connection, tableName);
|
||||
ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size());
|
||||
for (Pair<HRegionInfo, ServerName> entry : locations) {
|
||||
regions.add(new HRegionLocation(entry.getFirst(), entry.getSecond()));
|
||||
|
||||
}
|
||||
if (regions.size() > 0) {
|
||||
connection.cacheLocation(tableName, new RegionLocations(regions));
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
|
|
@ -6141,4 +6141,20 @@ public class TestFromClientSide {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionCache() throws IOException {
|
||||
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testRegionCache"));
|
||||
HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
|
||||
htd.addFamily(fam);
|
||||
byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE;
|
||||
Admin admin = TEST_UTIL.getHBaseAdmin();
|
||||
admin.createTable(htd, KEYS);
|
||||
HRegionLocator locator =
|
||||
(HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName());
|
||||
List<HRegionLocation> results = locator.getAllRegionLocations();
|
||||
int number = ((ConnectionImplementation)admin.getConnection())
|
||||
.getNumberOfCachedRegionLocations(htd.getTableName());
|
||||
assertEquals(results.size(), number);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue