HBASE-20697 Can't cache All region locations of the specify table by calling table.getRegionLocator().getAllRegionLocations()
Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
parent
d7561cee50
commit
1e0650955a
|
@ -56,9 +56,6 @@ public class RegionLocations {
|
|||
int index = 0;
|
||||
for (HRegionLocation loc : locations) {
|
||||
if (loc != null) {
|
||||
if (loc.getServerName() != null) {
|
||||
numNonNullElements++;
|
||||
}
|
||||
if (loc.getRegionInfo().getReplicaId() >= maxReplicaId) {
|
||||
maxReplicaId = loc.getRegionInfo().getReplicaId();
|
||||
maxReplicaIdIndex = index;
|
||||
|
@ -66,8 +63,6 @@ public class RegionLocations {
|
|||
}
|
||||
index++;
|
||||
}
|
||||
this.numNonNullElements = numNonNullElements;
|
||||
|
||||
// account for the null elements in the array after maxReplicaIdIndex
|
||||
maxReplicaId = maxReplicaId + (locations.length - (maxReplicaIdIndex + 1) );
|
||||
|
||||
|
@ -81,6 +76,12 @@ public class RegionLocations {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (HRegionLocation loc : this.locations) {
|
||||
if (loc != null && loc.getServerName() != null){
|
||||
numNonNullElements++;
|
||||
}
|
||||
}
|
||||
this.numNonNullElements = numNonNullElements;
|
||||
}
|
||||
|
||||
public RegionLocations(Collection<HRegionLocation> locations) {
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.apache.hadoop.hbase.HRegionInfo;
|
|||
import org.apache.hadoop.hbase.HRegionLocation;
|
||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
||||
import org.apache.hadoop.hbase.RegionLocations;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
@ -85,15 +84,12 @@ public class HRegionLocator implements RegionLocator {
|
|||
@Override
|
||||
public List<HRegionLocation> getAllRegionLocations() throws IOException {
|
||||
TableName tableName = getName();
|
||||
List<Pair<RegionInfo, ServerName>> locations =
|
||||
MetaTableAccessor.getTableRegionsAndLocations(this.connection, tableName);
|
||||
ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size());
|
||||
for (Pair<RegionInfo, ServerName> entry : locations) {
|
||||
regions.add(new HRegionLocation(entry.getFirst(), entry.getSecond()));
|
||||
|
||||
}
|
||||
if (regions.size() > 0) {
|
||||
connection.cacheLocation(tableName, new RegionLocations(regions));
|
||||
ArrayList<HRegionLocation> regions = new ArrayList<>();
|
||||
for (RegionLocations locations : listRegionLocations()) {
|
||||
for (HRegionLocation location : locations.getRegionLocations()) {
|
||||
regions.add(location);
|
||||
}
|
||||
connection.cacheLocation(tableName, locations);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
|
|
@ -6417,6 +6417,13 @@ public class TestFromClientSide {
|
|||
int number = ((ConnectionImplementation)admin.getConnection())
|
||||
.getNumberOfCachedRegionLocations(htd.getTableName());
|
||||
assertEquals(results.size(), number);
|
||||
ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection());
|
||||
assertNotNull("Can't get cached location for row aaa",
|
||||
conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa")));
|
||||
for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){
|
||||
assertNotNull("Can't get cached location for row "+
|
||||
Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue