HBASE-19752 RSGroupBasedLoadBalancer#getMisplacedRegions() should handle the case where rs group cannot be determined
This commit is contained in:
parent
b29a138ecc
commit
6f29a39d76
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.apache.hadoop.hbase.rsgroup;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
|
@ -311,7 +312,8 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer, LoadBalanc
|
|||
return finalList;
|
||||
}
|
||||
|
||||
private Set<HRegionInfo> getMisplacedRegions(
|
||||
@VisibleForTesting
|
||||
public Set<HRegionInfo> getMisplacedRegions(
|
||||
Map<HRegionInfo, ServerName> regions) throws IOException {
|
||||
Set<HRegionInfo> misplacedRegions = new HashSet<HRegionInfo>();
|
||||
for(Map.Entry<HRegionInfo, ServerName> region : regions.entrySet()) {
|
||||
|
@ -319,12 +321,19 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer, LoadBalanc
|
|||
ServerName assignedServer = region.getValue();
|
||||
RSGroupInfo info =
|
||||
infoManager.getRSGroup(infoManager.getRSGroupOfTable(regionInfo.getTable()));
|
||||
if (assignedServer != null &&
|
||||
(info == null || !info.containsServer(assignedServer.getAddress()))) {
|
||||
if (assignedServer == null) {
|
||||
LOG.debug("There is no assigned server for " + region);
|
||||
continue;
|
||||
}
|
||||
RSGroupInfo otherInfo = infoManager.getRSGroupOfServer(assignedServer.getAddress());
|
||||
if (info == null && otherInfo == null) {
|
||||
LOG.warn("Couldn't obtain rs group information for " + region + " on " + assignedServer);
|
||||
continue;
|
||||
}
|
||||
if ((info == null || !info.containsServer(assignedServer.getAddress()))) {
|
||||
LOG.debug("Found misplaced region: " + regionInfo.getRegionNameAsString() +
|
||||
" on server: " + assignedServer +
|
||||
" found in group: " +
|
||||
infoManager.getRSGroupOfServer(assignedServer.getAddress()) +
|
||||
" found in group: " + otherInfo +
|
||||
" outside of group: " + (info == null ? "UNKNOWN" : info.getName()));
|
||||
misplacedRegions.add(regionInfo);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class TestRSGroupBasedLoadBalancer {
|
|||
|
||||
static String[] groups = new String[] { RSGroupInfo.DEFAULT_GROUP, "dg2", "dg3",
|
||||
"dg4" };
|
||||
static TableName table0 = TableName.valueOf("dt0");
|
||||
static TableName[] tables =
|
||||
new TableName[] { TableName.valueOf("dt1"),
|
||||
TableName.valueOf("dt2"),
|
||||
|
@ -222,6 +223,16 @@ public class TestRSGroupBasedLoadBalancer {
|
|||
assertRetainedAssignment(inputForTest, servers, newAssignment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMisplacedRegions() throws Exception {
|
||||
// Test case where region is not considered misplaced if RSGroupInfo cannot be determined
|
||||
Map<HRegionInfo, ServerName> inputForTest = new HashMap<>();
|
||||
HRegionInfo ri = new HRegionInfo(
|
||||
table0, new byte[16], new byte[16], false, regionId++);
|
||||
inputForTest.put(ri, servers.iterator().next());
|
||||
Set<HRegionInfo> misplacedRegions = loadBalancer.getMisplacedRegions(inputForTest);
|
||||
assertFalse(misplacedRegions.contains(ri));
|
||||
}
|
||||
/**
|
||||
* Test BOGUS_SERVER_NAME among groups do not overwrite each other
|
||||
* @throws Exception
|
||||
|
@ -520,6 +531,8 @@ public class TestRSGroupBasedLoadBalancer {
|
|||
tableMap.put(tables[i], groupName);
|
||||
tds.add(htd);
|
||||
}
|
||||
tableMap.put(table0, "");
|
||||
tds.add(new HTableDescriptor(table0));
|
||||
return tds;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue