From 1f10ef553efbcbe0979f77fe2d5b68c030078247 Mon Sep 17 00:00:00 2001 From: Thiruvel Thirumoolan Date: Wed, 9 May 2018 11:47:48 -0700 Subject: [PATCH] HBASE-20545 Improve performance of BaseLoadBalancer.retainAssignment Signed-off-by: tedyu --- .../master/balancer/BaseLoadBalancer.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java index 44dfe415447..90f4e586299 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java @@ -1413,6 +1413,9 @@ public abstract class BaseLoadBalancer implements LoadBalancer { // after the cluster restart. Set oldHostsNoLongerPresent = Sets.newTreeSet(); + // If the old servers aren't present, lets assign those regions later. + List randomAssignRegions = Lists.newArrayList(); + int numRandomAssignments = 0; int numRetainedAssigments = 0; @@ -1426,37 +1429,51 @@ public abstract class BaseLoadBalancer implements LoadBalancer { localServers = serversByHostname.get(oldServerName.getHostname()); } if (localServers.isEmpty()) { - // No servers on the new cluster match up with this hostname, - // assign randomly. - ServerName randomServer = randomAssignment(cluster, region, servers); - assignments.get(randomServer).add(region); - numRandomAssignments++; - if (oldServerName != null) oldHostsNoLongerPresent.add(oldServerName.getHostname()); + // No servers on the new cluster match up with this hostname, assign randomly, later. + randomAssignRegions.add(region); + if (oldServerName != null) { + oldHostsNoLongerPresent.add(oldServerName.getHostname()); + } } else if (localServers.size() == 1) { // the usual case - one new server on same host ServerName target = localServers.get(0); assignments.get(target).add(region); - cluster.doAssignRegion(region, target); numRetainedAssigments++; } else { // multiple new servers in the cluster on this same host if (localServers.contains(oldServerName)) { assignments.get(oldServerName).add(region); - cluster.doAssignRegion(region, oldServerName); + numRetainedAssigments++; } else { ServerName target = null; - for (ServerName tmp: localServers) { + for (ServerName tmp : localServers) { if (tmp.getPort() == oldServerName.getPort()) { target = tmp; + assignments.get(tmp).add(region); + numRetainedAssigments++; break; } } if (target == null) { - target = randomAssignment(cluster, region, localServers); + randomAssignRegions.add(region); } - assignments.get(target).add(region); } - numRetainedAssigments++; + } + } + + // If servers from prior assignment aren't present, then lets do randomAssignment on regions. + if (randomAssignRegions.size() > 0) { + for (Map.Entry> entry : assignments.entrySet()) { + ServerName sn = entry.getKey(); + for (RegionInfo region : entry.getValue()) { + cluster.doAssignRegion(region, sn); + } + } + for (RegionInfo region : randomAssignRegions) { + ServerName target = randomAssignment(cluster, region, servers); + assignments.get(target).add(region); + cluster.doAssignRegion(region, target); + numRandomAssignments++; } }