From 03e7b78260413ebc508b3415dbe9c14be6a361de Mon Sep 17 00:00:00 2001 From: Xiang LI Date: Wed, 14 Mar 2018 01:08:26 +0800 Subject: [PATCH] HBASE-20186 Improve RSGroupBasedLoadBalancer#balanceCluster() to be more efficient when calculating cluster state for each rsgroup Signed-off-by: tedyu --- .../rsgroup/RSGroupBasedLoadBalancer.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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 392cbab5ce8..3182a61a16c 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 @@ -127,17 +127,23 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer { regionPlans.add(new RegionPlan(regionInfo, serverName, null)); } try { - List rsgi = rsGroupInfoManager.listRSGroups(); - for (RSGroupInfo info: rsgi) { + // Record which region servers have been processed,so as to skip them after processed + HashSet processedServers = new HashSet<>(); + + // For each rsgroup + for (RSGroupInfo rsgroup : rsGroupInfoManager.listRSGroups()) { Map> groupClusterState = new HashMap<>(); Map>> 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 regionsOnServer = correctedState.get(server); + groupClusterState.put(server, regionsOnServer); + + processedServers.add(server); } } + groupClusterLoad.put(HConstants.ENSEMBLE_TABLE_NAME, groupClusterState); this.internalBalancer.setClusterLoad(groupClusterLoad); List groupPlans = this.internalBalancer