Index: src/main/java/org/apache/hadoop/hbase/master/HMaster.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1100413) +++ src/main/java/org/apache/hadoop/hbase/master/HMaster.java (working copy) @@ -711,12 +711,22 @@ return balancerCutoffTime; } + /** + * @return Maximum number of regions in each run of balancer, -1 means there is no limit + */ + private int getBalancerRegionCountLimit() { + int balancerRegionCountLimit = + getConfiguration().getInt("hbase.balancer.max.regions.periteration", -1); + return balancerRegionCountLimit; + } + @Override public boolean balance() { // If balance not true, don't run balancer. if (!this.balanceSwitch) return false; // Do this call outside of synchronized block. int maximumBalanceTime = getBalancerCutoffTime(); + int maximumRegionCount = getBalancerRegionCountLimit(); long cutoffTime = System.currentTimeMillis() + maximumBalanceTime; boolean balancerRan; synchronized (this.balancer) { @@ -767,6 +777,10 @@ this.assignmentManager.balance(plan); totalRegPlanExecTime += System.currentTimeMillis()-balStartTime; rpCount++; + if (maximumRegionCount > 0 && rpCount >= maximumRegionCount) { + LOG.debug("Balancer has moved " + rpCount + " regions, reaching limit for this iteration"); + break; + } if (rpCount < plans.size() && // if performing next balance exceeds cutoff time, exit the loop (System.currentTimeMillis() + (totalRegPlanExecTime / rpCount)) > cutoffTime) {