HBASE-19752 RSGroupBasedLoadBalancer#getMisplacedRegions() should handle the case where rs group cannot be determined
This commit is contained in:
parent
a5601c8eac
commit
f0ba7922f3
|
@ -301,7 +301,8 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer {
|
||||||
return finalList;
|
return finalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<RegionInfo> getMisplacedRegions(
|
@VisibleForTesting
|
||||||
|
public Set<RegionInfo> getMisplacedRegions(
|
||||||
Map<RegionInfo, ServerName> regions) throws IOException {
|
Map<RegionInfo, ServerName> regions) throws IOException {
|
||||||
Set<RegionInfo> misplacedRegions = new HashSet<>();
|
Set<RegionInfo> misplacedRegions = new HashSet<>();
|
||||||
for(Map.Entry<RegionInfo, ServerName> region : regions.entrySet()) {
|
for(Map.Entry<RegionInfo, ServerName> region : regions.entrySet()) {
|
||||||
|
@ -309,10 +310,16 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer {
|
||||||
ServerName assignedServer = region.getValue();
|
ServerName assignedServer = region.getValue();
|
||||||
RSGroupInfo info = rsGroupInfoManager.getRSGroup(rsGroupInfoManager.
|
RSGroupInfo info = rsGroupInfoManager.getRSGroup(rsGroupInfoManager.
|
||||||
getRSGroupOfTable(regionInfo.getTable()));
|
getRSGroupOfTable(regionInfo.getTable()));
|
||||||
if (assignedServer != null &&
|
if (assignedServer == null) {
|
||||||
(info == null || !info.containsServer(assignedServer.getAddress()))) {
|
LOG.debug("There is no assigned server for {}", region);
|
||||||
RSGroupInfo otherInfo = null;
|
continue;
|
||||||
otherInfo = rsGroupInfoManager.getRSGroupOfServer(assignedServer.getAddress());
|
}
|
||||||
|
RSGroupInfo otherInfo = rsGroupInfoManager.getRSGroupOfServer(assignedServer.getAddress());
|
||||||
|
if (info == null && otherInfo == null) {
|
||||||
|
LOG.warn("Couldn't obtain rs group information for {} on {}", region, assignedServer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((info == null || !info.containsServer(assignedServer.getAddress()))) {
|
||||||
LOG.debug("Found misplaced region: " + regionInfo.getRegionNameAsString() +
|
LOG.debug("Found misplaced region: " + regionInfo.getRegionNameAsString() +
|
||||||
" on server: " + assignedServer +
|
" on server: " + assignedServer +
|
||||||
" found in group: " + otherInfo +
|
" found in group: " + otherInfo +
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class TestRSGroupBasedLoadBalancer {
|
||||||
private static SecureRandom rand;
|
private static SecureRandom rand;
|
||||||
|
|
||||||
static String[] groups = new String[] { RSGroupInfo.DEFAULT_GROUP, "dg2", "dg3", "dg4" };
|
static String[] groups = new String[] { RSGroupInfo.DEFAULT_GROUP, "dg2", "dg3", "dg4" };
|
||||||
|
static TableName table0 = TableName.valueOf("dt0");
|
||||||
static TableName[] tables =
|
static TableName[] tables =
|
||||||
new TableName[] { TableName.valueOf("dt1"),
|
new TableName[] { TableName.valueOf("dt1"),
|
||||||
TableName.valueOf("dt2"),
|
TableName.valueOf("dt2"),
|
||||||
|
@ -214,6 +215,20 @@ public class TestRSGroupBasedLoadBalancer {
|
||||||
assertClusterAsBalanced(loadMap);
|
assertClusterAsBalanced(loadMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMisplacedRegions() throws Exception {
|
||||||
|
// Test case where region is not considered misplaced if RSGroupInfo cannot be determined
|
||||||
|
Map<RegionInfo, ServerName> inputForTest = new HashMap<>();
|
||||||
|
RegionInfo ri = RegionInfoBuilder.newBuilder(table0)
|
||||||
|
.setStartKey(new byte[16])
|
||||||
|
.setEndKey(new byte[16])
|
||||||
|
.setSplit(false)
|
||||||
|
.setRegionId(regionId++)
|
||||||
|
.build();
|
||||||
|
inputForTest.put(ri, servers.iterator().next());
|
||||||
|
Set<RegionInfo> misplacedRegions = loadBalancer.getMisplacedRegions(inputForTest);
|
||||||
|
assertFalse(misplacedRegions.contains(ri));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Test the cluster startup bulk assignment which attempts to retain assignment info.
|
* Test the cluster startup bulk assignment which attempts to retain assignment info.
|
||||||
*/
|
*/
|
||||||
|
@ -533,6 +548,8 @@ public class TestRSGroupBasedLoadBalancer {
|
||||||
tableMap.put(tables[i], groupName);
|
tableMap.put(tables[i], groupName);
|
||||||
tds.add(htd);
|
tds.add(htd);
|
||||||
}
|
}
|
||||||
|
tableMap.put(table0, "");
|
||||||
|
tds.add(new HTableDescriptor(table0));
|
||||||
return tds;
|
return tds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue