diff --git a/hbase-rsgroup/pom.xml b/hbase-rsgroup/pom.xml
index b494a9afde7c..0bef6604783d 100644
--- a/hbase-rsgroup/pom.xml
+++ b/hbase-rsgroup/pom.xml
@@ -98,6 +98,12 @@
org.apache.hbase
hbase-procedure
+
+ org.apache.hbase
+ hbase-procedure
+ test-jar
+ test
+
org.apache.hbase
hbase-protocol
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 9709fb550d9b..6767ac930940 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
@@ -170,23 +170,21 @@ public List balanceCluster(Map> cluster
}
@Override
- public Map> roundRobinAssignment(
- List regions, List servers) throws HBaseIOException {
+ public Map> roundRobinAssignment(List regions,
+ List servers) throws HBaseIOException {
Map> assignments = Maps.newHashMap();
- ListMultimap regionMap = ArrayListMultimap.create();
- ListMultimap serverMap = ArrayListMultimap.create();
+ ListMultimap regionMap = ArrayListMultimap.create();
+ ListMultimap serverMap = ArrayListMultimap.create();
generateGroupMaps(regions, servers, regionMap, serverMap);
- for(String groupKey : regionMap.keySet()) {
+ for (String groupKey : regionMap.keySet()) {
if (regionMap.get(groupKey).size() > 0) {
- Map> result =
- this.internalBalancer.roundRobinAssignment(
- regionMap.get(groupKey),
- serverMap.get(groupKey));
- if(result != null) {
- 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));
+ Map> result = this.internalBalancer
+ .roundRobinAssignment(regionMap.get(groupKey), serverMap.get(groupKey));
+ if (result != null) {
+ 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);
}
@@ -197,24 +195,19 @@ public Map> roundRobinAssignment(
}
@Override
- public Map> retainAssignment(
- Map regions, List servers) throws HBaseIOException {
+ public Map> retainAssignment(Map regions,
+ List servers) throws HBaseIOException {
try {
Map> assignments = new TreeMap<>();
ListMultimap groupToRegion = ArrayListMultimap.create();
- Set misplacedRegions = getMisplacedRegions(regions);
for (RegionInfo region : regions.keySet()) {
- if (!misplacedRegions.contains(region)) {
- String groupName = rsGroupInfoManager.getRSGroupOfTable(region.getTable());
- if (groupName == null) {
- LOG.debug("Group not found for table " + region.getTable() + ", using default");
- groupName = RSGroupInfo.DEFAULT_GROUP;
- }
- groupToRegion.put(groupName, region);
+ String groupName = rsGroupInfoManager.getRSGroupOfTable(region.getTable());
+ if (groupName == null) {
+ LOG.debug("Group not found for table " + region.getTable() + ", using default");
+ groupName = RSGroupInfo.DEFAULT_GROUP;
}
+ groupToRegion.put(groupName, region);
}
- // Now the "groupToRegion" map has only the regions which have correct
- // assignments.
for (String key : groupToRegion.keySet()) {
Map currentAssignmentMap = new TreeMap();
List regionList = groupToRegion.get(key);
@@ -223,34 +216,16 @@ public Map> retainAssignment(
for (RegionInfo region : regionList) {
currentAssignmentMap.put(region, regions.get(region));
}
- if(candidateList.size() > 0) {
- assignments.putAll(this.internalBalancer.retainAssignment(
- currentAssignmentMap, candidateList));
+ if (candidateList.size() > 0) {
+ assignments
+ .putAll(this.internalBalancer.retainAssignment(currentAssignmentMap, candidateList));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("No available servers to assign regions: {}",
- RegionInfo.getShortNameToLog(regionList));
+ RegionInfo.getShortNameToLog(regionList));
}
assignments.computeIfAbsent(LoadBalancer.BOGUS_SERVER_NAME, s -> new ArrayList<>())
- .addAll(regionList);
- }
- }
-
- for (RegionInfo region : misplacedRegions) {
- String groupName = rsGroupInfoManager.getRSGroupOfTable(region.getTable());
- if (groupName == null) {
- LOG.debug("Group not found for table " + region.getTable() + ", using default");
- groupName = RSGroupInfo.DEFAULT_GROUP;
- }
- RSGroupInfo info = rsGroupInfoManager.getRSGroup(groupName);
- List candidateList = filterOfflineServers(info, servers);
- ServerName server = this.internalBalancer.randomAssignment(region,
- candidateList);
- if (server != null) {
- assignments.computeIfAbsent(server, s -> new ArrayList<>()).add(region);
- } else {
- assignments.computeIfAbsent(LoadBalancer.BOGUS_SERVER_NAME, s -> new ArrayList<>())
- .add(region);
+ .addAll(regionList);
}
}
return assignments;
@@ -269,11 +244,9 @@ public ServerName randomAssignment(RegionInfo region,
return this.internalBalancer.randomAssignment(region, filteredServers);
}
- private void generateGroupMaps(
- List regions,
- List servers,
- ListMultimap regionMap,
- ListMultimap serverMap) throws HBaseIOException {
+ private void generateGroupMaps(List regions, List servers,
+ ListMultimap regionMap, ListMultimap serverMap)
+ throws HBaseIOException {
try {
for (RegionInfo region : regions) {
String groupName = rsGroupInfoManager.getRSGroupOfTable(region.getTable());
@@ -307,63 +280,26 @@ private List filterOfflineServers(RSGroupInfo RSGroupInfo,
/**
* Filter servers based on the online servers.
- *
- * @param servers
- * the servers
- * @param onlineServers
- * List of servers which are online.
+ *
+ * servers is actually a TreeSet (see {@link org.apache.hadoop.hbase.rsgroup.RSGroupInfo}), having
+ * its contains()'s time complexity as O(logn), which is good enough.
+ *
+ * TODO: consider using HashSet to pursue O(1) for contains() throughout the calling chain if
+ * needed.
+ * @param servers the servers
+ * @param onlineServers List of servers which are online.
* @return the list
*/
- private List filterServers(Set servers,
- List onlineServers) {
- /**
- * servers is actually a TreeSet (see {@link org.apache.hadoop.hbase.rsgroup.RSGroupInfo}),
- * having its contains()'s time complexity as O(logn), which is good enough.
- * TODO: consider using HashSet to pursue O(1) for contains() throughout the calling chain
- * if needed. */
+ private List filterServers(Set servers, List onlineServers) {
ArrayList finalList = new ArrayList<>();
for (ServerName onlineServer : onlineServers) {
if (servers.contains(onlineServer.getAddress())) {
finalList.add(onlineServer);
}
}
-
return finalList;
}
- @VisibleForTesting
- public Set getMisplacedRegions(
- Map regions) throws IOException {
- Set misplacedRegions = new HashSet<>();
- for(Map.Entry region : regions.entrySet()) {
- RegionInfo regionInfo = region.getKey();
- ServerName assignedServer = region.getValue();
- String groupName = rsGroupInfoManager.getRSGroupOfTable(regionInfo.getTable());
- if (groupName == null) {
- LOG.debug("Group not found for table " + regionInfo.getTable() + ", using default");
- groupName = RSGroupInfo.DEFAULT_GROUP;
- }
- RSGroupInfo info = rsGroupInfoManager.getRSGroup(groupName);
- if (assignedServer == null) {
- LOG.debug("There is no assigned server for {}", region);
- continue;
- }
- 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() +
- " on server: " + assignedServer +
- " found in group: " + otherInfo +
- " outside of group: " + (info == null ? "UNKNOWN" : info.getName()));
- misplacedRegions.add(regionInfo);
- }
- }
- return misplacedRegions;
- }
-
private Pair