diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java index 049e7230473..5c08fb77cd7 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java @@ -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 getMisplacedRegions( + @VisibleForTesting + public Set getMisplacedRegions( Map regions) throws IOException { Set misplacedRegions = new HashSet(); for(Map.Entry 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); } diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java index 2360ce80919..e511d1434c6 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java @@ -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 inputForTest = new HashMap<>(); + HRegionInfo ri = new HRegionInfo( + table0, new byte[16], new byte[16], false, regionId++); + inputForTest.put(ri, servers.iterator().next()); + Set 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; }