@@ -240,6 +240,7 @@ public void testUpdateBalancerLoadInfo(){
240240    BalancerClusterState  clusterState  = mockCluster (cluster );
241241    Map <TableName , Map <ServerName , List <RegionInfo >>> LoadOfAllTable  =
242242      (Map ) mockClusterServersWithTables (servers );
243+     boolean  oldIsByTable  = conf .getBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , false );
243244    try  {
244245      boolean [] perTableBalancerConfigs  = { true , false  };
245246      for  (boolean  isByTable  : perTableBalancerConfigs ) {
@@ -262,14 +263,15 @@ public void testUpdateBalancerLoadInfo(){
262263        assertEquals (curOverallCost , curOverallCostInMetrics , 0.001 );
263264      }
264265    }finally  {
265-       conf .unset (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE );
266+       conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE ,  oldIsByTable );
266267      loadBalancer .onConfigurationChange (conf );
267268    }
268269  }
269270
270271  @ Test 
271272  public  void  testUpdateStochasticCosts () {
272273    float  minCost  = conf .getFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 0.05f );
274+     boolean  oldIsByTable  = conf .getBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , false );
273275    try  {
274276      int [] cluster  = new  int [] { 10 , 0  };
275277      Map <ServerName , List <RegionInfo >> servers  = mockClusterServers (cluster );
@@ -291,14 +293,15 @@ public void testUpdateStochasticCosts() {
291293    } finally  {
292294      //reset config 
293295      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , minCost );
294-       conf .unset (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE );
296+       conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE ,  oldIsByTable );
295297      loadBalancer .onConfigurationChange (conf );
296298    }
297299  }
298300
299301  @ Test 
300302  public  void  testUpdateStochasticCostsIfBalanceNotRan () {
301303    float  minCost  = conf .getFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 0.05f );
304+     boolean  oldIsByTable  = conf .getBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , false );
302305    try  {
303306      int [] cluster  = new  int [] { 10 , 10  };
304307      Map <ServerName , List <RegionInfo >> servers  = mockClusterServers (cluster );
@@ -320,17 +323,22 @@ public void testUpdateStochasticCostsIfBalanceNotRan() {
320323    } finally  {
321324      //reset config 
322325      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , minCost );
323-       conf .unset (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE );
326+       conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE ,  oldIsByTable );
324327      loadBalancer .onConfigurationChange (conf );
325328    }
326329  }
327330
328331  @ Test 
329332  public  void  testNeedBalance () {
333+     boolean  oldIsByTable  = conf .getBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , false );
330334    float  minCost  = conf .getFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 0.05f );
331335    float  slop  = conf .getFloat (HConstants .LOAD_BALANCER_SLOP_KEY , 0.2f );
336+     boolean  runMaxSteps  = conf .getBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
337+     long  maxSteps  = conf .getLong ("hbase.master.balancer.stochastic.maxSteps" , 1000000 );
332338    conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 1.0f );
333339    conf .setFloat (HConstants .LOAD_BALANCER_SLOP_KEY , -1f );
340+     conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
341+     conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , 5000L );
334342    try  {
335343      // Test with/without per table balancer. 
336344      boolean [] perTableBalancerConfigs  = {true , false };
@@ -343,23 +351,29 @@ public void testNeedBalance() {
343351      }
344352    } finally  {
345353      // reset config 
346-       conf .unset (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE );
354+       conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE ,  oldIsByTable );
347355      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , minCost );
348356      conf .setFloat (HConstants .LOAD_BALANCER_SLOP_KEY , slop );
357+       conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , runMaxSteps );
358+       conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , maxSteps );
349359      loadBalancer .onConfigurationChange (conf );
350360    }
351361  }
352362
353363  @ Test 
354364  public  void  testBalanceOfSloppyServers () {
355365    float  minCost  = conf .getFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 0.025f );
366+     boolean  runMaxSteps  = conf .getBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
367+     long  maxSteps  = conf .getLong ("hbase.master.balancer.stochastic.maxSteps" , 1000000 );
356368    try  {
357369      // We are testing slop checks, so don't "accidentally" balance due to a minCost calculation. 
358370      // During development, imbalance of a 100 server cluster, with one node having 10 regions 
359371      // and the rest having 5, is 0.0048. With minCostNeedBalance default of 0.025, test should 
360372      // validate slop checks without this override. We override just to ensure we will always 
361373      // validate slop check here, and for small clusters as well. 
362374      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 1.0f );
375+       conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
376+       conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , 5000L );
363377      loadBalancer .onConfigurationChange (conf );
364378      for  (int [] mockCluster  : clusterStateMocksWithNoSlop ) {
365379        assertTrue (hasEmptyBalancerPlans (mockCluster ));
@@ -370,6 +384,8 @@ public void testBalanceOfSloppyServers() {
370384    } finally  {
371385      // reset config 
372386      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , minCost );
387+       conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , runMaxSteps );
388+       conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , maxSteps );
373389      loadBalancer .onConfigurationChange (conf );
374390    }
375391  }
@@ -383,14 +399,21 @@ public void testSloppyTablesLoadBalanceByTable() {
383399        , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 },
384400    };
385401    float  minCost  = conf .getFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 0.025f );
402+     boolean  runMaxSteps  = conf .getBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
403+     long  maxSteps  = conf .getLong ("hbase.master.balancer.stochastic.maxSteps" , 1000000 );
404+     boolean  oldIsByTable  = conf .getBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , false );
386405    try  {
387406      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , 1.0f );
407+       conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , false );
408+       conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , 5000L );
388409      conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , true );
389410      loadBalancer .onConfigurationChange (conf );
390411      assertFalse (hasEmptyBalancerPlans (regionsPerServerPerTable ));
391412    } finally  {
392413      conf .setFloat ("hbase.master.balancer.stochastic.minCostNeedBalance" , minCost );
393-       conf .unset (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE );
414+       conf .setBoolean ("hbase.master.balancer.stochastic.runMaxSteps" , runMaxSteps );
415+       conf .setLong ("hbase.master.balancer.stochastic.maxSteps" , maxSteps );
416+       conf .setBoolean (HConstants .HBASE_MASTER_LOADBALANCE_BYTABLE , oldIsByTable );
394417      loadBalancer .onConfigurationChange (conf );
395418    }
396419  }
0 commit comments