HBASE-1868 Spew about rebalancing but none done....

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@820173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-09-30 04:40:53 +00:00
parent c2db3972ec
commit 9719bcba95
1 changed files with 67 additions and 50 deletions

View File

@ -196,8 +196,8 @@ class RegionManager implements HConstants {
// figure out what regions need to be assigned and aren't currently being // figure out what regions need to be assigned and aren't currently being
// worked on elsewhere. // worked on elsewhere.
Set<RegionState> regionsToAssign = regionsAwaitingAssignment(info.getServerAddress(), Set<RegionState> regionsToAssign =
isSingleServer); regionsAwaitingAssignment(info.getServerAddress(), isSingleServer);
if (regionsToAssign.size() == 0) { if (regionsToAssign.size() == 0) {
// There are no regions waiting to be assigned. // There are no regions waiting to be assigned.
if (!inSafeMode()) { if (!inSafeMode()) {
@ -224,22 +224,32 @@ class RegionManager implements HConstants {
* Note that no synchronization is needed while we iterate over * Note that no synchronization is needed while we iterate over
* regionsInTransition because this method is only called by assignRegions * regionsInTransition because this method is only called by assignRegions
* whose caller owns the monitor for RegionManager * whose caller owns the monitor for RegionManager
*
* TODO: This code is unintelligible. REWRITE. Add TESTS! St.Ack 09/30/2009
* @param thisServersLoad
* @param regionsToAssign
* @param info
* @param returnMsgs
*/ */
private void assignRegionsToMultipleServers(final HServerLoad thisServersLoad, private void assignRegionsToMultipleServers(final HServerLoad thisServersLoad,
final Set<RegionState> regionsToAssign, final HServerInfo info, final Set<RegionState> regionsToAssign, final HServerInfo info,
final ArrayList<HMsg> returnMsgs) { final ArrayList<HMsg> returnMsgs) {
boolean isMetaAssign = false; boolean isMetaAssign = false;
for (RegionState s : regionsToAssign) { for (RegionState s : regionsToAssign) {
if (s.getRegionInfo().isMetaRegion()) if (s.getRegionInfo().isMetaRegion())
isMetaAssign = true; isMetaAssign = true;
} }
int nRegionsToAssign = regionsToAssign.size(); int nRegionsToAssign = regionsToAssign.size();
// Now many regions to assign this server.
int nregions = regionsPerServer(nRegionsToAssign, thisServersLoad); int nregions = regionsPerServer(nRegionsToAssign, thisServersLoad);
LOG.debug("Assigning for " + info + ": total nregions to assign=" + LOG.debug("Assigning for " + info + ": total nregions to assign=" +
nRegionsToAssign + ", nregions to reach balance=" + nregions + nRegionsToAssign + ", nregions to reach balance=" + nregions +
", isMetaAssign=" + isMetaAssign); ", isMetaAssign=" + isMetaAssign);
if (nRegionsToAssign <= nregions) {
// I do not know whats supposed to happen in this case. Assign one.
LOG.debug("Assigning one region only (playing it safe..)");
assignRegions(regionsToAssign, 1, info, returnMsgs);
} else {
nRegionsToAssign -= nregions; nRegionsToAssign -= nregions;
if (nRegionsToAssign > 0 || isMetaAssign) { if (nRegionsToAssign > 0 || isMetaAssign) {
// We still have more regions to assign. See how many we can assign // We still have more regions to assign. See how many we can assign
@ -247,16 +257,13 @@ class RegionManager implements HConstants {
// most heavily loaded server. // most heavily loaded server.
HServerLoad heavierLoad = new HServerLoad(); HServerLoad heavierLoad = new HServerLoad();
int nservers = computeNextHeaviestLoad(thisServersLoad, heavierLoad); int nservers = computeNextHeaviestLoad(thisServersLoad, heavierLoad);
nregions = 0; nregions = 0;
// Advance past any less-loaded servers // Advance past any less-loaded servers
for (HServerLoad load = new HServerLoad(thisServersLoad); for (HServerLoad load = new HServerLoad(thisServersLoad);
load.compareTo(heavierLoad) <= 0 && nregions < nRegionsToAssign; load.compareTo(heavierLoad) <= 0 && nregions < nRegionsToAssign;
load.setNumberOfRegions(load.getNumberOfRegions() + 1), nregions++) { load.setNumberOfRegions(load.getNumberOfRegions() + 1), nregions++) {
// continue; // continue;
} }
LOG.debug("Doing for " + info + " nregions: " + nregions + LOG.debug("Doing for " + info + " nregions: " + nregions +
" and nRegionsToAssign: " + nRegionsToAssign); " and nRegionsToAssign: " + nRegionsToAssign);
if (nregions < nRegionsToAssign) { if (nregions < nRegionsToAssign) {
@ -265,31 +272,43 @@ class RegionManager implements HConstants {
if (nservers > 0) { if (nservers > 0) {
// There are other servers that can share the load. // There are other servers that can share the load.
// Split regions that need assignment across the servers. // Split regions that need assignment across the servers.
nregions = (int) Math.ceil((1.0 * nRegionsToAssign) nregions = (int) Math.ceil((1.0 * nRegionsToAssign)/(1.0 * nservers));
/ (1.0 * nservers));
} else { } else {
// No other servers with same load. // No other servers with same load.
// Split regions over all available servers // Split regions over all available servers
nregions = (int) Math.ceil((1.0 * nRegionsToAssign) nregions = (int) Math.ceil((1.0 * nRegionsToAssign)/
/ (1.0 * master.serverManager.numServers())); (1.0 * master.serverManager.numServers()));
} }
} else { } else {
// Assign all regions to this server // Assign all regions to this server
nregions = nRegionsToAssign; nregions = nRegionsToAssign;
} }
assignRegions(regionsToAssign, nregions, info, returnMsgs);
if (nregions > this.maxAssignInOneGo) { }
nregions = this.maxAssignInOneGo; }
} }
/*
* Assign <code>nregions</code> regions.
* @param regionsToAssign
* @param nregions
* @param info
* @param returnMsgs
*/
private void assignRegions(final Set<RegionState> regionsToAssign,
final int nregions, final HServerInfo info,
final ArrayList<HMsg> returnMsgs) {
int count = nregions;
if (count > this.maxAssignInOneGo) {
count = this.maxAssignInOneGo;
}
for (RegionState s: regionsToAssign) { for (RegionState s: regionsToAssign) {
doRegionAssignment(s, info, returnMsgs); doRegionAssignment(s, info, returnMsgs);
if (--nregions <= 0) { if (--count <= 0) {
break; break;
} }
} }
} }
}
/* /*
* Assign all to the only server. An unlikely case but still possible. * Assign all to the only server. An unlikely case but still possible.
@ -332,7 +351,6 @@ class RegionManager implements HConstants {
*/ */
private int regionsPerServer(final int numUnassignedRegions, private int regionsPerServer(final int numUnassignedRegions,
final HServerLoad thisServersLoad) { final HServerLoad thisServersLoad) {
SortedMap<HServerLoad, Set<String>> lightServers = SortedMap<HServerLoad, Set<String>> lightServers =
new TreeMap<HServerLoad, Set<String>>(); new TreeMap<HServerLoad, Set<String>>();
@ -346,14 +364,13 @@ class RegionManager implements HConstants {
// until they reach load equal with ours. Then, see how many regions are left // until they reach load equal with ours. Then, see how many regions are left
// unassigned. That is how many regions we should assign to this server. // unassigned. That is how many regions we should assign to this server.
int nRegions = 0; int nRegions = 0;
for (Map.Entry<HServerLoad, Set<String>> e : lightServers.entrySet()) { for (Map.Entry<HServerLoad, Set<String>> e: lightServers.entrySet()) {
HServerLoad lightLoad = new HServerLoad(e.getKey()); HServerLoad lightLoad = new HServerLoad(e.getKey());
do { do {
lightLoad.setNumberOfRegions(lightLoad.getNumberOfRegions() + 1); lightLoad.setNumberOfRegions(lightLoad.getNumberOfRegions() + 1);
nRegions += 1; nRegions += 1;
} while (lightLoad.compareTo(thisServersLoad) <= 0 } while (lightLoad.compareTo(thisServersLoad) <= 0
&& nRegions < numUnassignedRegions); && nRegions < numUnassignedRegions);
nRegions *= e.getValue().size(); nRegions *= e.getValue().size();
if (nRegions >= numUnassignedRegions) { if (nRegions >= numUnassignedRegions) {
break; break;