hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [08/17] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Thu, 22 Jun 2017 15:01:28 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1efd3d47/devapidocs/src-html/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.Cluster.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.Cluster.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.Cluster.html
index d0f1508..085701c 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.Cluster.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.Cluster.html
@@ -922,7 +922,7 @@
 <span class="sourceLineNo">914</span>    private Comparator&lt;Integer&gt; numRegionsComparator = new Comparator&lt;Integer&gt;() {<a name="line.914"></a>
 <span class="sourceLineNo">915</span>      @Override<a name="line.915"></a>
 <span class="sourceLineNo">916</span>      public int compare(Integer integer, Integer integer2) {<a name="line.916"></a>
-<span class="sourceLineNo">917</span>        return Integer.valueOf(getNumRegions(integer)).compareTo(getNumRegions(integer2));<a name="line.917"></a>
+<span class="sourceLineNo">917</span>        return Integer.compare(getNumRegions(integer), getNumRegions(integer2));<a name="line.917"></a>
 <span class="sourceLineNo">918</span>      }<a name="line.918"></a>
 <span class="sourceLineNo">919</span>    };<a name="line.919"></a>
 <span class="sourceLineNo">920</span><a name="line.920"></a>
@@ -937,797 +937,789 @@
 <span class="sourceLineNo">929</span>    private Comparator&lt;Integer&gt; localityComparator = new Comparator&lt;Integer&gt;() {<a name="line.929"></a>
 <span class="sourceLineNo">930</span>      @Override<a name="line.930"></a>
 <span class="sourceLineNo">931</span>      public int compare(Integer integer, Integer integer2) {<a name="line.931"></a>
-<span class="sourceLineNo">932</span>        float locality1 = getLocality(integer);<a name="line.932"></a>
-<span class="sourceLineNo">933</span>        float locality2 = getLocality(integer2);<a name="line.933"></a>
-<span class="sourceLineNo">934</span>        if (locality1 &lt; locality2) {<a name="line.934"></a>
-<span class="sourceLineNo">935</span>          return -1;<a name="line.935"></a>
-<span class="sourceLineNo">936</span>        } else if (locality1 &gt; locality2) {<a name="line.936"></a>
-<span class="sourceLineNo">937</span>          return 1;<a name="line.937"></a>
-<span class="sourceLineNo">938</span>        } else {<a name="line.938"></a>
-<span class="sourceLineNo">939</span>          return 0;<a name="line.939"></a>
-<span class="sourceLineNo">940</span>        }<a name="line.940"></a>
-<span class="sourceLineNo">941</span>      }<a name="line.941"></a>
-<span class="sourceLineNo">942</span>    };<a name="line.942"></a>
-<span class="sourceLineNo">943</span><a name="line.943"></a>
-<span class="sourceLineNo">944</span>    int getLowestLocalityRegionServer() {<a name="line.944"></a>
-<span class="sourceLineNo">945</span>      if (regionFinder == null) {<a name="line.945"></a>
-<span class="sourceLineNo">946</span>        return -1;<a name="line.946"></a>
-<span class="sourceLineNo">947</span>      } else {<a name="line.947"></a>
-<span class="sourceLineNo">948</span>        sortServersByLocality();<a name="line.948"></a>
-<span class="sourceLineNo">949</span>        // We want to find server with non zero regions having lowest locality.<a name="line.949"></a>
-<span class="sourceLineNo">950</span>        int i = 0;<a name="line.950"></a>
-<span class="sourceLineNo">951</span>        int lowestLocalityServerIndex = serverIndicesSortedByLocality[i];<a name="line.951"></a>
-<span class="sourceLineNo">952</span>        while (localityPerServer[lowestLocalityServerIndex] == 0<a name="line.952"></a>
-<span class="sourceLineNo">953</span>            &amp;&amp; (regionsPerServer[lowestLocalityServerIndex].length == 0)) {<a name="line.953"></a>
-<span class="sourceLineNo">954</span>          i++;<a name="line.954"></a>
-<span class="sourceLineNo">955</span>          lowestLocalityServerIndex = serverIndicesSortedByLocality[i];<a name="line.955"></a>
-<span class="sourceLineNo">956</span>        }<a name="line.956"></a>
-<span class="sourceLineNo">957</span>        if (LOG.isTraceEnabled()) {<a name="line.957"></a>
-<span class="sourceLineNo">958</span>          LOG.trace("Lowest locality region server with non zero regions is "<a name="line.958"></a>
-<span class="sourceLineNo">959</span>            + servers[lowestLocalityServerIndex].getHostname() + " with locality "<a name="line.959"></a>
-<span class="sourceLineNo">960</span>            + localityPerServer[lowestLocalityServerIndex]);<a name="line.960"></a>
-<span class="sourceLineNo">961</span>        }<a name="line.961"></a>
-<span class="sourceLineNo">962</span>        return lowestLocalityServerIndex;<a name="line.962"></a>
-<span class="sourceLineNo">963</span>      }<a name="line.963"></a>
-<span class="sourceLineNo">964</span>    }<a name="line.964"></a>
-<span class="sourceLineNo">965</span><a name="line.965"></a>
-<span class="sourceLineNo">966</span>    int getLowestLocalityRegionOnServer(int serverIndex) {<a name="line.966"></a>
-<span class="sourceLineNo">967</span>      if (regionFinder != null) {<a name="line.967"></a>
-<span class="sourceLineNo">968</span>        float lowestLocality = 1.0f;<a name="line.968"></a>
-<span class="sourceLineNo">969</span>        int lowestLocalityRegionIndex = -1;<a name="line.969"></a>
-<span class="sourceLineNo">970</span>        if (regionsPerServer[serverIndex].length == 0) {<a name="line.970"></a>
-<span class="sourceLineNo">971</span>          // No regions on that region server<a name="line.971"></a>
-<span class="sourceLineNo">972</span>          return -1;<a name="line.972"></a>
-<span class="sourceLineNo">973</span>        }<a name="line.973"></a>
-<span class="sourceLineNo">974</span>        for (int j = 0; j &lt; regionsPerServer[serverIndex].length; j++) {<a name="line.974"></a>
-<span class="sourceLineNo">975</span>          int regionIndex = regionsPerServer[serverIndex][j];<a name="line.975"></a>
-<span class="sourceLineNo">976</span>          HDFSBlocksDistribution distribution = regionFinder<a name="line.976"></a>
-<span class="sourceLineNo">977</span>              .getBlockDistribution(regions[regionIndex]);<a name="line.977"></a>
-<span class="sourceLineNo">978</span>          float locality = distribution.getBlockLocalityIndex(servers[serverIndex].getHostname());<a name="line.978"></a>
-<span class="sourceLineNo">979</span>          // skip empty region<a name="line.979"></a>
-<span class="sourceLineNo">980</span>          if (distribution.getUniqueBlocksTotalWeight() == 0) {<a name="line.980"></a>
-<span class="sourceLineNo">981</span>            continue;<a name="line.981"></a>
-<span class="sourceLineNo">982</span>          }<a name="line.982"></a>
-<span class="sourceLineNo">983</span>          if (locality &lt; lowestLocality) {<a name="line.983"></a>
-<span class="sourceLineNo">984</span>            lowestLocality = locality;<a name="line.984"></a>
-<span class="sourceLineNo">985</span>            lowestLocalityRegionIndex = j;<a name="line.985"></a>
-<span class="sourceLineNo">986</span>          }<a name="line.986"></a>
-<span class="sourceLineNo">987</span>        }<a name="line.987"></a>
-<span class="sourceLineNo">988</span>        if (lowestLocalityRegionIndex == -1) {<a name="line.988"></a>
-<span class="sourceLineNo">989</span>          return -1;<a name="line.989"></a>
-<span class="sourceLineNo">990</span>        }<a name="line.990"></a>
-<span class="sourceLineNo">991</span>        if (LOG.isTraceEnabled()) {<a name="line.991"></a>
-<span class="sourceLineNo">992</span>          LOG.trace("Lowest locality region is "<a name="line.992"></a>
-<span class="sourceLineNo">993</span>              + regions[regionsPerServer[serverIndex][lowestLocalityRegionIndex]]<a name="line.993"></a>
-<span class="sourceLineNo">994</span>                  .getRegionNameAsString() + " with locality " + lowestLocality<a name="line.994"></a>
-<span class="sourceLineNo">995</span>              + " and its region server contains " + regionsPerServer[serverIndex].length<a name="line.995"></a>
-<span class="sourceLineNo">996</span>              + " regions");<a name="line.996"></a>
-<span class="sourceLineNo">997</span>        }<a name="line.997"></a>
-<span class="sourceLineNo">998</span>        return regionsPerServer[serverIndex][lowestLocalityRegionIndex];<a name="line.998"></a>
-<span class="sourceLineNo">999</span>      } else {<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>        return -1;<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>      }<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>    }<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span><a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>    float getLocalityOfRegion(int region, int server) {<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>      if (regionFinder != null) {<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>        HDFSBlocksDistribution distribution = regionFinder.getBlockDistribution(regions[region]);<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>        return distribution.getBlockLocalityIndex(servers[server].getHostname());<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>      } else {<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>        return 0f;<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>      }<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>    }<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span><a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>    /**<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>     * Returns a least loaded server which has better locality for this region<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>     * than the current server.<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>     */<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>    int getLeastLoadedTopServerForRegion(int region, int currentServer) {<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>      if (regionFinder != null) {<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>        List&lt;ServerName&gt; topLocalServers = regionFinder.getTopBlockLocations(regions[region],<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>          servers[currentServer].getHostname());<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>        int leastLoadedServerIndex = -1;<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>        int load = Integer.MAX_VALUE;<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>        for (ServerName sn : topLocalServers) {<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>          if (!serversToIndex.containsKey(sn.getHostAndPort())) {<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>            continue;<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>          }<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>          int index = serversToIndex.get(sn.getHostAndPort());<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>          if (regionsPerServer[index] == null) {<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>            continue;<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>          }<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>          int tempLoad = regionsPerServer[index].length;<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>          if (tempLoad &lt;= load) {<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>            leastLoadedServerIndex = index;<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>            load = tempLoad;<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>          }<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>        }<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>        if (leastLoadedServerIndex != -1) {<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>          if (LOG.isTraceEnabled()) {<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>            LOG.trace("Pick the least loaded server " +<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>                servers[leastLoadedServerIndex].getHostname() +<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>                " with better locality for region " + regions[region].getShortNameToLog());<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>          }<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>        }<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>        return leastLoadedServerIndex;<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>      } else {<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>        return -1;<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>      }<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>    }<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span><a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    void calculateRegionServerLocalities() {<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>      if (regionFinder == null) {<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>        LOG.warn("Region location finder found null, skipping locality calculations.");<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>        return;<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>      }<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>      for (int i = 0; i &lt; regionsPerServer.length; i++) {<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>        HDFSBlocksDistribution distribution = new HDFSBlocksDistribution();<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>        if (regionsPerServer[i].length &gt; 0) {<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>          for (int j = 0; j &lt; regionsPerServer[i].length; j++) {<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>            int regionIndex = regionsPerServer[i][j];<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>            distribution.add(regionFinder.getBlockDistribution(regions[regionIndex]));<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>          }<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>        } else {<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>          LOG.debug("Server " + servers[i].getHostname() + " had 0 regions.");<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>        }<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>        localityPerServer[i] = distribution.getBlockLocalityIndex(servers[i].getHostname());<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>      }<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>    }<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span><a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>    @VisibleForTesting<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>    protected void setNumRegions(int numRegions) {<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>      this.numRegions = numRegions;<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>    }<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span><a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>    @VisibleForTesting<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>    protected void setNumMovedRegions(int numMovedRegions) {<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>      this.numMovedRegions = numMovedRegions;<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>    }<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span><a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SBSC_USE_STRINGBUFFER_CONCATENATION",<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>        justification="Not important but should be fixed")<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>    @Override<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>    public String toString() {<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>      String desc = "Cluster{" +<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>          "servers=[";<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>          for(ServerName sn:servers) {<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>             desc += sn.getHostAndPort() + ", ";<a name="line.1086"></a>
+<span class="sourceLineNo">932</span>        return Float.compare(getLocality(integer), getLocality(integer2));<a name="line.932"></a>
+<span class="sourceLineNo">933</span>      }<a name="line.933"></a>
+<span class="sourceLineNo">934</span>    };<a name="line.934"></a>
+<span class="sourceLineNo">935</span><a name="line.935"></a>
+<span class="sourceLineNo">936</span>    int getLowestLocalityRegionServer() {<a name="line.936"></a>
+<span class="sourceLineNo">937</span>      if (regionFinder == null) {<a name="line.937"></a>
+<span class="sourceLineNo">938</span>        return -1;<a name="line.938"></a>
+<span class="sourceLineNo">939</span>      } else {<a name="line.939"></a>
+<span class="sourceLineNo">940</span>        sortServersByLocality();<a name="line.940"></a>
+<span class="sourceLineNo">941</span>        // We want to find server with non zero regions having lowest locality.<a name="line.941"></a>
+<span class="sourceLineNo">942</span>        int i = 0;<a name="line.942"></a>
+<span class="sourceLineNo">943</span>        int lowestLocalityServerIndex = serverIndicesSortedByLocality[i];<a name="line.943"></a>
+<span class="sourceLineNo">944</span>        while (localityPerServer[lowestLocalityServerIndex] == 0<a name="line.944"></a>
+<span class="sourceLineNo">945</span>            &amp;&amp; (regionsPerServer[lowestLocalityServerIndex].length == 0)) {<a name="line.945"></a>
+<span class="sourceLineNo">946</span>          i++;<a name="line.946"></a>
+<span class="sourceLineNo">947</span>          lowestLocalityServerIndex = serverIndicesSortedByLocality[i];<a name="line.947"></a>
+<span class="sourceLineNo">948</span>        }<a name="line.948"></a>
+<span class="sourceLineNo">949</span>        if (LOG.isTraceEnabled()) {<a name="line.949"></a>
+<span class="sourceLineNo">950</span>          LOG.trace("Lowest locality region server with non zero regions is "<a name="line.950"></a>
+<span class="sourceLineNo">951</span>            + servers[lowestLocalityServerIndex].getHostname() + " with locality "<a name="line.951"></a>
+<span class="sourceLineNo">952</span>            + localityPerServer[lowestLocalityServerIndex]);<a name="line.952"></a>
+<span class="sourceLineNo">953</span>        }<a name="line.953"></a>
+<span class="sourceLineNo">954</span>        return lowestLocalityServerIndex;<a name="line.954"></a>
+<span class="sourceLineNo">955</span>      }<a name="line.955"></a>
+<span class="sourceLineNo">956</span>    }<a name="line.956"></a>
+<span class="sourceLineNo">957</span><a name="line.957"></a>
+<span class="sourceLineNo">958</span>    int getLowestLocalityRegionOnServer(int serverIndex) {<a name="line.958"></a>
+<span class="sourceLineNo">959</span>      if (regionFinder != null) {<a name="line.959"></a>
+<span class="sourceLineNo">960</span>        float lowestLocality = 1.0f;<a name="line.960"></a>
+<span class="sourceLineNo">961</span>        int lowestLocalityRegionIndex = -1;<a name="line.961"></a>
+<span class="sourceLineNo">962</span>        if (regionsPerServer[serverIndex].length == 0) {<a name="line.962"></a>
+<span class="sourceLineNo">963</span>          // No regions on that region server<a name="line.963"></a>
+<span class="sourceLineNo">964</span>          return -1;<a name="line.964"></a>
+<span class="sourceLineNo">965</span>        }<a name="line.965"></a>
+<span class="sourceLineNo">966</span>        for (int j = 0; j &lt; regionsPerServer[serverIndex].length; j++) {<a name="line.966"></a>
+<span class="sourceLineNo">967</span>          int regionIndex = regionsPerServer[serverIndex][j];<a name="line.967"></a>
+<span class="sourceLineNo">968</span>          HDFSBlocksDistribution distribution = regionFinder<a name="line.968"></a>
+<span class="sourceLineNo">969</span>              .getBlockDistribution(regions[regionIndex]);<a name="line.969"></a>
+<span class="sourceLineNo">970</span>          float locality = distribution.getBlockLocalityIndex(servers[serverIndex].getHostname());<a name="line.970"></a>
+<span class="sourceLineNo">971</span>          // skip empty region<a name="line.971"></a>
+<span class="sourceLineNo">972</span>          if (distribution.getUniqueBlocksTotalWeight() == 0) {<a name="line.972"></a>
+<span class="sourceLineNo">973</span>            continue;<a name="line.973"></a>
+<span class="sourceLineNo">974</span>          }<a name="line.974"></a>
+<span class="sourceLineNo">975</span>          if (locality &lt; lowestLocality) {<a name="line.975"></a>
+<span class="sourceLineNo">976</span>            lowestLocality = locality;<a name="line.976"></a>
+<span class="sourceLineNo">977</span>            lowestLocalityRegionIndex = j;<a name="line.977"></a>
+<span class="sourceLineNo">978</span>          }<a name="line.978"></a>
+<span class="sourceLineNo">979</span>        }<a name="line.979"></a>
+<span class="sourceLineNo">980</span>        if (lowestLocalityRegionIndex == -1) {<a name="line.980"></a>
+<span class="sourceLineNo">981</span>          return -1;<a name="line.981"></a>
+<span class="sourceLineNo">982</span>        }<a name="line.982"></a>
+<span class="sourceLineNo">983</span>        if (LOG.isTraceEnabled()) {<a name="line.983"></a>
+<span class="sourceLineNo">984</span>          LOG.trace("Lowest locality region is "<a name="line.984"></a>
+<span class="sourceLineNo">985</span>              + regions[regionsPerServer[serverIndex][lowestLocalityRegionIndex]]<a name="line.985"></a>
+<span class="sourceLineNo">986</span>                  .getRegionNameAsString() + " with locality " + lowestLocality<a name="line.986"></a>
+<span class="sourceLineNo">987</span>              + " and its region server contains " + regionsPerServer[serverIndex].length<a name="line.987"></a>
+<span class="sourceLineNo">988</span>              + " regions");<a name="line.988"></a>
+<span class="sourceLineNo">989</span>        }<a name="line.989"></a>
+<span class="sourceLineNo">990</span>        return regionsPerServer[serverIndex][lowestLocalityRegionIndex];<a name="line.990"></a>
+<span class="sourceLineNo">991</span>      } else {<a name="line.991"></a>
+<span class="sourceLineNo">992</span>        return -1;<a name="line.992"></a>
+<span class="sourceLineNo">993</span>      }<a name="line.993"></a>
+<span class="sourceLineNo">994</span>    }<a name="line.994"></a>
+<span class="sourceLineNo">995</span><a name="line.995"></a>
+<span class="sourceLineNo">996</span>    float getLocalityOfRegion(int region, int server) {<a name="line.996"></a>
+<span class="sourceLineNo">997</span>      if (regionFinder != null) {<a name="line.997"></a>
+<span class="sourceLineNo">998</span>        HDFSBlocksDistribution distribution = regionFinder.getBlockDistribution(regions[region]);<a name="line.998"></a>
+<span class="sourceLineNo">999</span>        return distribution.getBlockLocalityIndex(servers[server].getHostname());<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>      } else {<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>        return 0f;<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>      }<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>    }<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span><a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>    /**<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>     * Returns a least loaded server which has better locality for this region<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>     * than the current server.<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>     */<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>    int getLeastLoadedTopServerForRegion(int region, int currentServer) {<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>      if (regionFinder != null) {<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>        List&lt;ServerName&gt; topLocalServers = regionFinder.getTopBlockLocations(regions[region],<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>          servers[currentServer].getHostname());<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>        int leastLoadedServerIndex = -1;<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>        int load = Integer.MAX_VALUE;<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>        for (ServerName sn : topLocalServers) {<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>          if (!serversToIndex.containsKey(sn.getHostAndPort())) {<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>            continue;<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>          }<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>          int index = serversToIndex.get(sn.getHostAndPort());<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>          if (regionsPerServer[index] == null) {<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>            continue;<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>          }<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>          int tempLoad = regionsPerServer[index].length;<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>          if (tempLoad &lt;= load) {<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>            leastLoadedServerIndex = index;<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>            load = tempLoad;<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>          }<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>        }<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>        if (leastLoadedServerIndex != -1) {<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>          if (LOG.isTraceEnabled()) {<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>            LOG.trace("Pick the least loaded server " +<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>                servers[leastLoadedServerIndex].getHostname() +<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>                " with better locality for region " + regions[region].getShortNameToLog());<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>          }<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>        }<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>        return leastLoadedServerIndex;<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>      } else {<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>        return -1;<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>      }<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>    }<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span><a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>    void calculateRegionServerLocalities() {<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>      if (regionFinder == null) {<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>        LOG.warn("Region location finder found null, skipping locality calculations.");<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>        return;<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>      }<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>      for (int i = 0; i &lt; regionsPerServer.length; i++) {<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>        HDFSBlocksDistribution distribution = new HDFSBlocksDistribution();<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>        if (regionsPerServer[i].length &gt; 0) {<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>          for (int j = 0; j &lt; regionsPerServer[i].length; j++) {<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>            int regionIndex = regionsPerServer[i][j];<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>            distribution.add(regionFinder.getBlockDistribution(regions[regionIndex]));<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>          }<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>        } else {<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>          LOG.debug("Server " + servers[i].getHostname() + " had 0 regions.");<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>        }<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>        localityPerServer[i] = distribution.getBlockLocalityIndex(servers[i].getHostname());<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>      }<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>    }<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span><a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>    @VisibleForTesting<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>    protected void setNumRegions(int numRegions) {<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>      this.numRegions = numRegions;<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>    }<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span><a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>    @VisibleForTesting<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>    protected void setNumMovedRegions(int numMovedRegions) {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>      this.numMovedRegions = numMovedRegions;<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>    }<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span><a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SBSC_USE_STRINGBUFFER_CONCATENATION",<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>        justification="Not important but should be fixed")<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>    @Override<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>    public String toString() {<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>      String desc = "Cluster{" +<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>          "servers=[";<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>          for(ServerName sn:servers) {<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>             desc += sn.getHostAndPort() + ", ";<a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>          }<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span>          desc +=<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>          ", serverIndicesSortedByRegionCount="+<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>          Arrays.toString(serverIndicesSortedByRegionCount) +<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>          ", regionsPerServer=[";<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span><a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>          for (int[]r:regionsPerServer) {<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>            desc += Arrays.toString(r);<a name="line.1086"></a>
 <span class="sourceLineNo">1087</span>          }<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>          desc +=<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>          ", serverIndicesSortedByRegionCount="+<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>          Arrays.toString(serverIndicesSortedByRegionCount) +<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>          ", regionsPerServer=[";<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span><a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>          for (int[]r:regionsPerServer) {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>            desc += Arrays.toString(r);<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>          }<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>          desc += "]" +<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>          ", numMaxRegionsPerTable=" +<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>          Arrays.toString(numMaxRegionsPerTable) +<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>          ", numRegions=" +<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>          numRegions +<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>          ", numServers=" +<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>          numServers +<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>          ", numTables=" +<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>          numTables +<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>          ", numMovedRegions=" +<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>          numMovedRegions +<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>          '}';<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>      return desc;<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>    }<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>  }<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span><a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>  // slop for regions<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>  protected float slop;<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>  // overallSlop to controll simpleLoadBalancer's cluster level threshold<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>  protected float overallSlop;<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>  protected Configuration config;<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>  protected RackManager rackManager;<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>  private static final Random RANDOM = new Random(System.currentTimeMillis());<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>  private static final Log LOG = LogFactory.getLog(BaseLoadBalancer.class);<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span><a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>  // Regions of these tables are put on the master by default.<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>  private static final String[] DEFAULT_TABLES_ON_MASTER =<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>    new String[] {AccessControlLists.ACL_TABLE_NAME.getNameAsString(),<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>      TableName.NAMESPACE_TABLE_NAME.getNameAsString(),<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>      TableName.META_TABLE_NAME.getNameAsString()};<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span><a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>  public static final String TABLES_ON_MASTER =<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>    "hbase.balancer.tablesOnMaster";<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span><a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>  protected final Set&lt;String&gt; tablesOnMaster = new HashSet&lt;&gt;();<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>  protected MetricsBalancer metricsBalancer = null;<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>  protected ClusterStatus clusterStatus = null;<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>  protected ServerName masterServerName;<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>  protected MasterServices services;<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span><a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>  /**<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>   * By default, regions of some small system tables such as meta,<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>   * namespace, and acl are assigned to the active master. If you don't<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>   * want to assign any region to the active master, you need to<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>   * configure "hbase.balancer.tablesOnMaster" to "none".<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>   */<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>  protected static String[] getTablesOnMaster(Configuration conf) {<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>    String valueString = conf.get(TABLES_ON_MASTER);<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>    if (valueString == null) {<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>      return DEFAULT_TABLES_ON_MASTER;<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>    }<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>    valueString = valueString.trim();<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>    if (valueString.equalsIgnoreCase("none")) {<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>      return null;<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>    }<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>    return StringUtils.getStrings(valueString);<a name="line.1151"></a>
+<span class="sourceLineNo">1088</span>          desc += "]" +<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>          ", numMaxRegionsPerTable=" +<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>          Arrays.toString(numMaxRegionsPerTable) +<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>          ", numRegions=" +<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>          numRegions +<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>          ", numServers=" +<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span>          numServers +<a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>          ", numTables=" +<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>          numTables +<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>          ", numMovedRegions=" +<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>          numMovedRegions +<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>          '}';<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>      return desc;<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>    }<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>  }<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span><a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>  // slop for regions<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span>  protected float slop;<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>  // overallSlop to controll simpleLoadBalancer's cluster level threshold<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>  protected float overallSlop;<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>  protected Configuration config;<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>  protected RackManager rackManager;<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>  private static final Random RANDOM = new Random(System.currentTimeMillis());<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>  private static final Log LOG = LogFactory.getLog(BaseLoadBalancer.class);<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span><a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>  // Regions of these tables are put on the master by default.<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>  private static final String[] DEFAULT_TABLES_ON_MASTER =<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>    new String[] {AccessControlLists.ACL_TABLE_NAME.getNameAsString(),<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>      TableName.NAMESPACE_TABLE_NAME.getNameAsString(),<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>      TableName.META_TABLE_NAME.getNameAsString()};<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span><a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>  public static final String TABLES_ON_MASTER =<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>    "hbase.balancer.tablesOnMaster";<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span><a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>  protected final Set&lt;String&gt; tablesOnMaster = new HashSet&lt;&gt;();<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>  protected MetricsBalancer metricsBalancer = null;<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>  protected ClusterStatus clusterStatus = null;<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>  protected ServerName masterServerName;<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>  protected MasterServices services;<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span><a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>  /**<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>   * By default, regions of some small system tables such as meta,<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>   * namespace, and acl are assigned to the active master. If you don't<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>   * want to assign any region to the active master, you need to<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>   * configure "hbase.balancer.tablesOnMaster" to "none".<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>   */<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>  protected static String[] getTablesOnMaster(Configuration conf) {<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>    String valueString = conf.get(TABLES_ON_MASTER);<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>    if (valueString == null) {<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>      return DEFAULT_TABLES_ON_MASTER;<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>    }<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>    valueString = valueString.trim();<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>    if (valueString.equalsIgnoreCase("none")) {<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>      return null;<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span>    }<a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>    return StringUtils.getStrings(valueString);<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>  }<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span><a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>  /**<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>   * Check if configured to put any tables on the active master<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>   */<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>  public static boolean tablesOnMaster(Configuration conf) {<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>    return tables != null &amp;&amp; tables.length &gt; 0;<a name="line.1151"></a>
 <span class="sourceLineNo">1152</span>  }<a name="line.1152"></a>
 <span class="sourceLineNo">1153</span><a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>  /**<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>   * Check if configured to put any tables on the active master<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>   */<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>  public static boolean tablesOnMaster(Configuration conf) {<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>    return tables != null &amp;&amp; tables.length &gt; 0;<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>  }<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span><a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>  public static boolean userTablesOnMaster(Configuration conf) {<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>    if (tables == null || tables.length == 0) {<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      return false;<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>    }<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>    for (String tn:tables) {<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>      if (!tn.startsWith("hbase:")) {<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>        return true;<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>      }<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>    }<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>    return false;<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>  }<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span><a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>  @Override<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>  public void setConf(Configuration conf) {<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>    setSlop(conf);<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>    if (slop &lt; 0) slop = 0;<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>    else if (slop &gt; 1) slop = 1;<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span><a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>    if (overallSlop &lt; 0) overallSlop = 0;<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>    else if (overallSlop &gt; 1) overallSlop = 1;<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span><a name="line.1183"></a>
-<span class="sourceLineNo">1184</span>    this.config = conf;<a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>    if (tables != null &amp;&amp; tables.length &gt; 0) {<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>      Collections.addAll(tablesOnMaster, tables);<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>    }<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>    this.rackManager = new RackManager(getConf());<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>    regionFinder.setConf(conf);<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>  }<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span><a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>  protected void setSlop(Configuration conf) {<a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>    this.slop = conf.getFloat("hbase.regions.slop", (float) 0.2);<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>    this.overallSlop = conf.getFloat("hbase.regions.overallSlop", slop);<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>  }<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span><a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>  /**<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>   * Check if a region belongs to some small system table.<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>   * If so, the primary replica may be expected to be put on the master regionserver.<a name="line.1200"></a>
+<span class="sourceLineNo">1154</span>  public static boolean userTablesOnMaster(Configuration conf) {<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span>    if (tables == null || tables.length == 0) {<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>      return false;<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span>    }<a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>    for (String tn:tables) {<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>      if (!tn.startsWith("hbase:")) {<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>        return true;<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>      }<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>    }<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>    return false;<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>  }<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span><a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>  @Override<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>  public void setConf(Configuration conf) {<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>    setSlop(conf);<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>    if (slop &lt; 0) slop = 0;<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>    else if (slop &gt; 1) slop = 1;<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span><a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>    if (overallSlop &lt; 0) overallSlop = 0;<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>    else if (overallSlop &gt; 1) overallSlop = 1;<a name="line.1174"></a>
+<span class="sourceLineNo">1175</span><a name="line.1175"></a>
+<span class="sourceLineNo">1176</span>    this.config = conf;<a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>    String[] tables = getTablesOnMaster(conf);<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>    if (tables != null &amp;&amp; tables.length &gt; 0) {<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>      Collections.addAll(tablesOnMaster, tables);<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>    }<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>    this.rackManager = new RackManager(getConf());<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>    regionFinder.setConf(conf);<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>  }<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span><a name="line.1184"></a>
+<span class="sourceLineNo">1185</span>  protected void setSlop(Configuration conf) {<a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>    this.slop = conf.getFloat("hbase.regions.slop", (float) 0.2);<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span>    this.overallSlop = conf.getFloat("hbase.regions.overallSlop", slop);<a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>  }<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span><a name="line.1189"></a>
+<span class="sourceLineNo">1190</span>  /**<a name="line.1190"></a>
+<span class="sourceLineNo">1191</span>   * Check if a region belongs to some small system table.<a name="line.1191"></a>
+<span class="sourceLineNo">1192</span>   * If so, the primary replica may be expected to be put on the master regionserver.<a name="line.1192"></a>
+<span class="sourceLineNo">1193</span>   */<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span>  public boolean shouldBeOnMaster(HRegionInfo region) {<a name="line.1194"></a>
+<span class="sourceLineNo">1195</span>    return tablesOnMaster.contains(region.getTable().getNameAsString())<a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>        &amp;&amp; region.getReplicaId() == HRegionInfo.DEFAULT_REPLICA_ID;<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>  }<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span><a name="line.1198"></a>
+<span class="sourceLineNo">1199</span>  /**<a name="line.1199"></a>
+<span class="sourceLineNo">1200</span>   * Balance the regions that should be on master regionserver.<a name="line.1200"></a>
 <span class="sourceLineNo">1201</span>   */<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>  public boolean shouldBeOnMaster(HRegionInfo region) {<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>    return tablesOnMaster.contains(region.getTable().getNameAsString())<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>        &amp;&amp; region.getReplicaId() == HRegionInfo.DEFAULT_REPLICA_ID;<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>  }<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span><a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>  /**<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>   * Balance the regions that should be on master regionserver.<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>   */<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>  protected List&lt;RegionPlan&gt; balanceMasterRegions(<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>      Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; clusterMap) {<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>    if (masterServerName == null<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>        || clusterMap == null || clusterMap.size() &lt;= 1) return null;<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>    List&lt;RegionPlan&gt; plans = null;<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>    List&lt;HRegionInfo&gt; regions = clusterMap.get(masterServerName);<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>    if (regions != null) {<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>      Iterator&lt;ServerName&gt; keyIt = null;<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>      for (HRegionInfo region: regions) {<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>        if (shouldBeOnMaster(region)) continue;<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span><a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>        // Find a non-master regionserver to host the region<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>        if (keyIt == null || !keyIt.hasNext()) {<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>          keyIt = clusterMap.keySet().iterator();<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>        }<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>        ServerName dest = keyIt.next();<a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>        if (masterServerName.equals(dest)) {<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>          if (!keyIt.hasNext()) {<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>            keyIt = clusterMap.keySet().iterator();<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>          }<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>          dest = keyIt.next();<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span>        }<a name="line.1231"></a>
-<span class="sourceLineNo">1232</span><a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>        // Move this region away from the master regionserver<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>        RegionPlan plan = new RegionPlan(region, masterServerName, dest);<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>        if (plans == null) {<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span>          plans = new ArrayList&lt;&gt;();<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>        }<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>        plans.add(plan);<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>      }<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>    }<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>    for (Map.Entry&lt;ServerName, List&lt;HRegionInfo&gt;&gt; server: clusterMap.entrySet()) {<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>      if (masterServerName.equals(server.getKey())) continue;<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>      for (HRegionInfo region: server.getValue()) {<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>        if (!shouldBeOnMaster(region)) continue;<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span><a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>        // Move this region to the master regionserver<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>        RegionPlan plan = new RegionPlan(region, server.getKey(), masterServerName);<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>        if (plans == null) {<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>          plans = new ArrayList&lt;&gt;();<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span>        }<a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>        plans.add(plan);<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>      }<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>    }<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>    return plans;<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span>  }<a name="line.1255"></a>
-<span class="sourceLineNo">1256</span><a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>  /**<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>   * Assign the regions that should be on master regionserver.<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>   */<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>  protected Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; assignMasterRegions(<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>      Collection&lt;HRegionInfo&gt; regions, List&lt;ServerName&gt; servers) {<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>    if (servers == null || regions == null || regions.isEmpty()) {<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>      return null;<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>    }<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>    Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; assignments = new TreeMap&lt;&gt;();<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>    if (masterServerName != null &amp;&amp; servers.contains(masterServerName)) {<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>      assignments.put(masterServerName, new ArrayList&lt;&gt;());<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>      for (HRegionInfo region: regions) {<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>        if (shouldBeOnMaster(region)) {<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>          assignments.get(masterServerName).add(region);<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>        }<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>      }<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>    }<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>    return assignments;<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>  }<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span><a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>  @Override<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>  public Configuration getConf() {<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>    return this.config;<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>  }<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span><a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>  @Override<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>  public synchronized void setClusterStatus(ClusterStatus st) {<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>    this.clusterStatus = st;<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>    regionFinder.setClusterStatus(st);<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>  }<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span><a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>  @Override<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>  public void setClusterLoad(Map&lt;TableName, Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt;&gt; clusterLoad){<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span><a name="line.1290"></a>
-<span class="sourceLineNo">1291</span>  }<a name="line.1291"></a>
-<span class="sourceLineNo">1292</span><a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>  @Override<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span>  public void setMasterServices(MasterServices masterServices) {<a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>    masterServerName = masterServices.getServerName();<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>    this.services = masterServices;<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>    this.regionFinder.setServices(masterServices);<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>  }<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span><a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>  public void setRackManager(RackManager rackManager) {<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>    this.rackManager = rackManager;<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>  }<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span><a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>  protected boolean needsBalance(Cluster c) {<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>    ClusterLoadState cs = new ClusterLoadState(c.clusterState);<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>    if (cs.getNumServers() &lt; MIN_SERVER_BALANCE) {<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>      if (LOG.isDebugEnabled()) {<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>        LOG.debug("Not running balancer because only " + cs.getNumServers()<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>            + " active regionserver(s)");<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>      }<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>      return false;<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>    }<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>    if(areSomeRegionReplicasColocated(c)) return true;<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>    // Check if we even need to do any load balancing<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>    // HBASE-3681 check sloppiness first<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>    float average = cs.getLoadAverage(); // for logging<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>    int floor = (int) Math.floor(average * (1 - slop));<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>    int ceiling = (int) Math.ceil(average * (1 + slop));<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>    if (!(cs.getMaxLoad() &gt; ceiling || cs.getMinLoad() &lt; floor)) {<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>      NavigableMap&lt;ServerAndLoad, List&lt;HRegionInfo&gt;&gt; serversByLoad = cs.getServersByLoad();<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>      if (LOG.isTraceEnabled()) {<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>        // If nothing to balance, then don't say anything unless trace-level logging.<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>        LOG.trace("Skipping load balancing because balanced cluster; " +<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>          "servers=" + cs.getNumServers() +<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>          " regions=" + cs.getNumRegions() + " average=" + average +<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>          " mostloaded=" + serversByLoad.lastKey().getLoad() +<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>          " leastloaded=" + serversByLoad.firstKey().getLoad());<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>      }<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>      return false;<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>    }<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>    return true;<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>  }<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span><a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>  /**<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>   * Subclasses should implement this to return true if the cluster has nodes that hosts<a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>   * multiple replicas for the same region, or, if there are multiple racks and the same<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>   * rack hosts replicas of the same region<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>   * @param c Cluster information<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>   * @return whether region replicas are currently co-located<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>   */<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>  protected boolean areSomeRegionReplicasColocated(Cluster c) {<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>    return false;<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>  }<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span><a name="line.1344"></a>
-<span class="sourceLineNo">1345</span>  /**<a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>   * Generates a bulk assignment plan to be used on cluster startup using a<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>   * simple round-robin assignment.<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>   * &lt;p&gt;<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span>   * Takes a list of all the regions and all the servers in the cluster and<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>   * returns a map of each server to the regions that it should be assigned.<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>   * &lt;p&gt;<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>   * Currently implemented as a round-robin assignment. Same invariant as load<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>   * balancing, all servers holding floor(avg) or ceiling(avg).<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>   *<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>   * TODO: Use block locations from HDFS to place regions with their blocks<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>   *<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>   * @param regions all regions<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>   * @param servers all servers<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>   * @return map of server to the regions it should take, or null if no<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>   *         assignment is possible (ie. no regions or no servers)<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>   */<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>  @Override<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>  public Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; roundRobinAssignment(List&lt;HRegionInfo&gt; regions,<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>      List&lt;ServerName&gt; servers) throws HBaseIOException {<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>    metricsBalancer.incrMiscInvocations();<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; assignments = assignMasterRegions(regions, servers);<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>    if (assignments != null &amp;&amp; !assignments.isEmpty()) {<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>      servers = new ArrayList&lt;&gt;(servers);<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>      // Guarantee not to put other regions on master<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      servers.remove(masterServerName);<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>      List&lt;HRegionInfo&gt; masterRegions = assignments.get(masterServerName);<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>      if (!masterRegions.isEmpty()) {<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>        regions = new ArrayList&lt;&gt;(regions);<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>        for (HRegionInfo region: masterRegions) {<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>          regions.remove(region);<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>        }<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      }<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>    }<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>    if (regions == null || regions.isEmpty()) {<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>      return assignments;<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>    }<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span><a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>    int numServers = servers == null ? 0 : servers.size();<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>    if (numServers == 0) {<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>      LOG.warn("Wanted to do round robin assignment but no servers to assign to");<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>      return null;<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>    }<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span><a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>    // TODO: instead of retainAssignment() and roundRobinAssignment(), we should just run the<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    // normal LB.balancerCluster() with unassignedRegions. We only need to have a candidate<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>    // generator for AssignRegionAction. The LB will ensure the regions are mostly local<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    // and balanced. This should also run fast with fewer number of iterations.<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span><a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>    if (numServers == 1) { // Only one server, nothing fancy we can do here<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>      ServerName server = servers.get(0);<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>      assignments.put(server, new ArrayList&lt;&gt;(regions));<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>      return assignments;<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>    }<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span><a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>    Cluster cluster = createCluster(servers, regions, false);<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>    List&lt;HRegionInfo&gt; unassignedRegions = new ArrayList&lt;&gt;();<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span><a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>    roundRobinAssignment(cluster, regions, unassignedRegions,<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>      servers, assignments);<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span><a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    List&lt;HRegionInfo&gt; lastFewRegions = new ArrayList&lt;&gt;();<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    // assign the remaining by going through the list and try to assign to servers one-by-one<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>    int serverIdx = RANDOM.nextInt(numServers);<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>    for (HRegionInfo region : unassignedRegions) {<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>      boolean assigned = false;<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>      for (int j = 0; j &lt; numServers; j++) { // try all servers one by one<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>        ServerName serverName = servers.get((j + serverIdx) % numServers);<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>        if (!cluster.wouldLowerAvailability(region, serverName)) {<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>          List&lt;HRegionInfo&gt; serverRegions = assignments.get(serverName);<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>          if (serverRegions == null) {<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>            serverRegions = new ArrayList&lt;&gt;();<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>            assignments.put(serverName, serverRegions);<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>          }<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>          serverRegions.add(region);<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>          cluster.doAssignRegion(region, serverName);<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>          serverIdx = (j + serverIdx + 1) % numServers; //remain from next server<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>          assigned = true;<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>          break;<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>        }<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>      }<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>      if (!assigned) {<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>        lastFewRegions.add(region);<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>      }<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>    }<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>    // just sprinkle the rest of the regions on random regionservers. The balanceCluster will<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>    // make it optimal later. we can end up with this if numReplicas &gt; numServers.<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>    for (HRegionInfo region : lastFewRegions) {<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>      int i = RANDOM.nextInt(numServers);<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>      ServerName server = servers.get(i);<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>      List&lt;HRegionInfo&gt; serverRegions = assignments.get(server);<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>      if (serverRegions == null) {<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>        serverRegions = new ArrayList&lt;&gt;();<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>        assignments.put(server, serverRegions);<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>      }<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>      serverRegions.add(region);<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>      cluster.doAssignRegion(region, server);<a name="line.1441"></a>
+<span class="sourceLineNo">1202</span>  protected List&lt;RegionPlan&gt; balanceMasterRegions(<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>      Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; clusterMap) {<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>    if (masterServerName == null<a name="line.1204"></a>
+<span class="sourceLineNo">1205</span>        || clusterMap == null || clusterMap.size() &lt;= 1) return null;<a name="line.1205"></a>
+<span class="sourceLineNo">1206</span>    List&lt;RegionPlan&gt; plans = null;<a name="line.1206"></a>
+<span class="sourceLineNo">1207</span>    List&lt;HRegionInfo&gt; regions = clusterMap.get(masterServerName);<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>    if (regions != null) {<a name="line.1208"></a>
+<span class="sourceLineNo">1209</span>      Iterator&lt;ServerName&gt; keyIt = null;<a name="line.1209"></a>
+<span class="sourceLineNo">1210</span>      for (HRegionInfo region: regions) {<a name="line.1210"></a>
+<span class="sourceLineNo">1211</span>        if (shouldBeOnMaster(region)) continue;<a name="line.1211"></a>
+<span class="sourceLineNo">1212</span><a name="line.1212"></a>
+<span class="sourceLineNo">1213</span>        // Find a non-master regionserver to host the region<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>        if (keyIt == null || !keyIt.hasNext()) {<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>          keyIt = clusterMap.keySet().iterator();<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span>        }<a name="line.1216"></a>
+<span class="sourceLineNo">1217</span>        ServerName dest = keyIt.next();<a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>        if (masterServerName.equals(dest)) {<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>          if (!keyIt.hasNext()) {<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>            keyIt = clusterMap.keySet().iterator();<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>          }<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>          dest = keyIt.next();<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>        }<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span><a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>        // Move this region away from the master regionserver<a name="line.1225"></a>
+<span class="sourceLineNo">1226</span>        RegionPlan plan = new RegionPlan(region, masterServerName, dest);<a name="line.1226"></a>
+<span class="sourceLineNo">1227</span>        if (plans == null) {<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>          plans = new ArrayList&lt;&gt;();<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span>        }<a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>        plans.add(plan);<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>      }<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span>    }<a name="line.1232"></a>
+<span class="sourceLineNo">1233</span>    for (Map.Entry&lt;ServerName, List&lt;HRegionInfo&gt;&gt; server: clusterMap.entrySet()) {<a name="line.1233"></a>
+<span class="sourceLineNo">1234</span>      if (masterServerName.equals(server.getKey())) continue;<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>      for (HRegionInfo region: server.getValue()) {<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>        if (!shouldBeOnMaster(region)) continue;<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span><a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>        // Move this region to the master regionserver<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>        RegionPlan plan = new RegionPlan(region, server.getKey(), masterServerName);<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>        if (plans == null) {<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>          plans = new ArrayList&lt;&gt;();<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>        }<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>        plans.add(plan);<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>      }<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>    }<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>    return plans;<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>  }<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span><a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>  /**<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>   * Assign the regions that should be on master regionserver.<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span>   */<a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>  protected Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; assignMasterRegions(<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span>      Collection&lt;HRegionInfo&gt; regions, List&lt;ServerName&gt; servers) {<a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>    if (servers == null || regions == null || regions.isEmpty()) {<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span>      return null;<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>    }<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>    Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt; assignments = new TreeMap&lt;&gt;();<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>    if (masterServerName != null &amp;&amp; servers.contains(masterServerName)) {<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>      assignments.put(masterServerName, new ArrayList&lt;&gt;());<a name="line.1259"></a>
+<span class="sourceLineNo">1260</span>      for (HRegionInfo region: regions) {<a name="line.1260"></a>
+<span class="sourceLineNo">1261</span>        if (shouldBeOnMaster(region)) {<a name="line.1261"></a>
+<span class="sourceLineNo">1262</span>          assignments.get(masterServerName).add(region);<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>        }<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>      }<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>    }<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span>    return assignments;<a name="line.1266"></a>
+<span class="sourceLineNo">1267</span>  }<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span><a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>  @Override<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>  public Configuration getConf() {<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>    return this.config;<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>  }<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span><a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>  @Override<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>  public synchronized void setClusterStatus(ClusterStatus st) {<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>    this.clusterStatus = st;<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>    regionFinder.setClusterStatus(st);<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>  }<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span><a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>  @Override<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span>  public void setClusterLoad(Map&lt;TableName, Map&lt;ServerName, List&lt;HRegionInfo&gt;&gt;&gt; clusterLoad){<a name="line.1281"></a>
+<span class="sourceLineNo">1282</span><a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>  }<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span><a name="line.1284"></a>
+<span class="sourceLineNo">1285</span>  @Override<a name="line.1285"></a>
+<span class="sourceLineNo">1286</span>  public void setMasterServices(MasterServices masterServices) {<a name="line.1286"></a>
+<span class="sourceLineNo">1287</span>    masterServerName = masterServices.getServerName();<a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>    this.services = masterServices;<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>    this.regionFinder.setServices(masterServices);<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>  }<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span><a name="line.1291"></a>
+<span class="sourceLineNo">1292</span>  public void setRackManager(RackManager rackManager) {<a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>    this.rackManager = rackManager;<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>  }<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span><a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>  protected boolean needsBalance(Cluster c) {<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>    ClusterLoadState cs = new ClusterLoadState(c.clusterState);<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>    if (cs.getNumServers() &lt; MIN_SERVER_BALANCE) {<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>      if (LOG.isDebugEnabled()) {<a name="line.1299"></a>
+<span class="sourceLineNo">1300</span>        LOG.debug("Not running balancer because only " + cs.getNumServers()<a name="line.1300"></a>
+<span class="sourceLineNo">1301</span>            + " active regionserver(s)");<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>      }<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>      return false;<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>    }<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>    if(areSomeRegionReplicasColocated(c)) return true;<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>    // Check if we even need to do any load balancing<a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>    // HBASE-3681 check sloppiness first<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>    float average = cs.getLoadAverage(); // for logging<a name="line.1308"></a>
+<span class="sourceLineNo">1309</spa

<TRUNCATED>

Mime
View raw message