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 48bcb64fb45..d7f94989d4a 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 @@ -173,7 +173,13 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer, LoadBalanc regionMap.get(groupKey), serverMap.get(groupKey)); if(result != null) { - assignments.putAll(result); + if(result.containsKey(LoadBalancer.BOGUS_SERVER_NAME) && + assignments.containsKey(LoadBalancer.BOGUS_SERVER_NAME)){ + assignments.get(LoadBalancer.BOGUS_SERVER_NAME).addAll( + result.get(LoadBalancer.BOGUS_SERVER_NAME)); + } else { + assignments.putAll(result); + } } } } 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 3b96de6da68..dea0a948125 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 @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.rsgroup.RSGroupInfo; import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager; import org.apache.hadoop.hbase.master.AssignmentManager; import org.apache.hadoop.hbase.master.HMaster; +import org.apache.hadoop.hbase.master.LoadBalancer; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.master.RegionPlan; import org.apache.hadoop.hbase.net.Address; @@ -55,6 +56,8 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -246,6 +249,37 @@ public class TestRSGroupBasedLoadBalancer { assertRetainedAssignment(inputForTest, servers, newAssignment); } + /** + * Test BOGUS_SERVER_NAME among groups do not overwrite each other + * @throws Exception + */ + @Test + public void testRoundRobinAssignment() throws Exception { + List onlineServers = new ArrayList(servers.size()); + onlineServers.addAll(servers); + List regions = randomRegions(25); + int bogusRegion = 0; + for(HRegionInfo region : regions){ + String group = tableMap.get(region.getTable()); + if("dg3".equals(group) || "dg4".equals(group)){ + bogusRegion++; + } + } + Set
offlineServers = new HashSet
(); + offlineServers.addAll(groupMap.get("dg3").getServers()); + offlineServers.addAll(groupMap.get("dg4").getServers()); + for(Iterator it = onlineServers.iterator(); it.hasNext();){ + ServerName server = it.next(); + Address address = server.getAddress(); + if(offlineServers.contains(address)){ + it.remove(); + } + } + Map> assignments = loadBalancer + .roundRobinAssignment(regions, onlineServers); + assertEquals(bogusRegion, assignments.get(LoadBalancer.BOGUS_SERVER_NAME).size()); + } + /** * Asserts a valid retained assignment plan. *