HBASE-20545 Improve performance of BaseLoadBalancer.retainAssignment
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
32dd633b98
commit
a67909d3d6
|
@ -1413,6 +1413,9 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
|||
// after the cluster restart.
|
||||
Set<String> oldHostsNoLongerPresent = Sets.newTreeSet();
|
||||
|
||||
// If the old servers aren't present, lets assign those regions later.
|
||||
List<RegionInfo> 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<ServerName, List<RegionInfo>> 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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue