From b5365c49aa5d5b12676b6291f9189b17a7e49560 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Fri, 4 Mar 2011 15:51:07 +0000 Subject: [PATCH] HBASE-3586 Improve the selection of regions to balance git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1078020 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hadoop/hbase/master/LoadBalancer.java | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5c0e2fd7e38..a6444249661 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -88,6 +88,8 @@ Release 0.91.0 - Unreleased HBASE-3564 DemoClient.pl - a demo client in Perl HBASE-3560 the hbase-default entry of "hbase.defaults.for.version" causes tests not to run via not-maven + HBASE-3586 Improve the selection of regions to balance (Ted Yu via Andrew + Purtell) TASK HBASE-3559 Move report of split to master OFF the heartbeat channel diff --git a/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java b/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java index 3d102c1971c..901be8bb459 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java +++ b/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java @@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.master; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -59,6 +60,17 @@ public class LoadBalancer { private static final Log LOG = LogFactory.getLog(LoadBalancer.class); private static final Random rand = new Random(); + static class RegionPlanComparator implements Comparator { + @Override + public int compare(RegionPlan l, RegionPlan r) { + long diff = r.getRegionInfo().getRegionId() - l.getRegionInfo().getRegionId(); + if (diff < 0) return -1; + if (diff > 0) return 1; + return 0; + } + } + static RegionPlanComparator rpComparator = new RegionPlanComparator(); + /** * Generate a global load balancing plan according to the specified map of * server information to the most loaded regions of each server. @@ -77,6 +89,8 @@ public class LoadBalancer { *
  • Iterate down the most loaded servers, shedding regions from each so * each server hosts exactly MAX regions. Stop once you reach a * server that already has <= MAX regions. + *

    + * Order the regions to move from most recent to least. * *

  • Iterate down the least loaded servers, assigning regions so each server * has exactly MIN regions. Stop once you reach a server that @@ -184,7 +198,8 @@ public class LoadBalancer { List regions = server.getValue(); int numToOffload = Math.min(regionCount - max, regions.size()); int numTaken = 0; - for (HRegionInfo hri: regions) { + for (int i = regions.size() - 1; i >= 0; i--) { + HRegionInfo hri = regions.get(i); // Don't rebalance meta regions. if (hri.isMetaRegion()) continue; regionsToMove.add(new RegionPlan(hri, serverInfo, null)); @@ -194,6 +209,8 @@ public class LoadBalancer { serverBalanceInfo.put(serverInfo, new BalanceInfo(numToOffload, (-1)*numTaken)); } + // put young regions at the beginning of regionsToMove + Collections.sort(regionsToMove, rpComparator); // Walk down least loaded, filling each to the min int serversUnderloaded = 0; // number of servers that get new regions