HBASE-20186 Improve RSGroupBasedLoadBalancer#balanceCluster() to be more efficient when calculating cluster state for each rsgroup

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Xiang LI 2018-03-14 01:08:26 +08:00 committed by Andrew Purtell
parent 3f1c86786c
commit 03e7b78260
1 changed files with 13 additions and 7 deletions

View File

@ -127,17 +127,23 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer {
regionPlans.add(new RegionPlan(regionInfo, serverName, null));
}
try {
List<RSGroupInfo> rsgi = rsGroupInfoManager.listRSGroups();
for (RSGroupInfo info: rsgi) {
// Record which region servers have been processedso as to skip them after processed
HashSet<ServerName> processedServers = new HashSet<>();
// For each rsgroup
for (RSGroupInfo rsgroup : rsGroupInfoManager.listRSGroups()) {
Map<ServerName, List<RegionInfo>> groupClusterState = new HashMap<>();
Map<TableName, Map<ServerName, List<RegionInfo>>> groupClusterLoad = new HashMap<>();
for (Address sName : info.getServers()) {
for(ServerName curr: clusterState.keySet()) {
if(curr.getAddress().equals(sName)) {
groupClusterState.put(curr, correctedState.get(curr));
}
for (ServerName server : clusterState.keySet()) { // for each region server
if (!processedServers.contains(server) // server is not processed yet
&& rsgroup.containsServer(server.getAddress())) { // server belongs to this rsgroup
List<RegionInfo> regionsOnServer = correctedState.get(server);
groupClusterState.put(server, regionsOnServer);
processedServers.add(server);
}
}
groupClusterLoad.put(HConstants.ENSEMBLE_TABLE_NAME, groupClusterState);
this.internalBalancer.setClusterLoad(groupClusterLoad);
List<RegionPlan> groupPlans = this.internalBalancer