HBASE-7060 Region load balancing by table does not handle the case where a table's region count is lower than the number of the RS in the cluster (Ted Yu and Tianying)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1403851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2012-10-30 20:08:22 +00:00
parent 02fa99f9f0
commit 9fda46c126
1 changed files with 12 additions and 3 deletions

View File

@ -269,13 +269,22 @@ public class DefaultLoadBalancer extends BaseLoadBalancer {
fetchFromTail = false;
Map<ServerName, Integer> underloadedServers = new HashMap<ServerName, Integer>();
float average = (float)numRegions / numServers; // for logging
int maxToTake = numRegions - (int)average;
for (Map.Entry<ServerAndLoad, List<HRegionInfo>> server:
serversByLoad.entrySet()) {
if (maxToTake == 0) break; // no more to take
int regionCount = server.getKey().getLoad();
if (regionCount >= min) {
break;
if (regionCount >= min && regionCount > 0) {
continue; // look for other servers which haven't reached min
}
underloadedServers.put(server.getKey().getServerName(), min - regionCount);
int regionsToPut = min - regionCount;
if (regionsToPut == 0)
{
regionsToPut = 1;
maxToTake--;
}
underloadedServers.put(server.getKey().getServerName(), regionsToPut);
}
// number of servers that get new regions
int serversUnderloaded = underloadedServers.size();