From 8392dc0ad2039805262354e3335f528961f82094 Mon Sep 17 00:00:00 2001 From: clarax Date: Mon, 25 Oct 2021 15:44:42 -0700 Subject: [PATCH] HBASE-26327 Replicas cohosted on a rack shouldn't keep triggering balancer (#3789) Signed-off-by: Huaxiang Sun --- .../hbase/master/balancer/StochasticLoadBalancer.java | 6 +----- .../balancer/TestStochasticLoadBalancerRegionReplica.java | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java index 8c8419d230e..de706cbff3c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java @@ -316,11 +316,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { if (Math.abs(regionReplicaHostCostFunction.cost()) > CostFunction.COST_EPSILON) { return true; } - regionReplicaRackCostFunction.init(c); - if (Math.abs(regionReplicaRackCostFunction.cost()) > CostFunction.COST_EPSILON) { - return true; - } - return false; + return (Math.abs(regionReplicaRackCostFunction.cost()) > CostFunction.COST_EPSILON); } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplica.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplica.java index 9634f9a5eb7..686c7cf96c4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplica.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplica.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.master.balancer; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -163,7 +164,7 @@ public class TestStochasticLoadBalancerRegionReplica extends BalancerTestBase { map.put(s2, regionsOnS2); // add another server so that the cluster has some host on another rack map.put(ServerName.valueOf("host2", 1000, 11111), randomRegions(1)); - assertTrue( + assertFalse( loadBalancer.needsBalance(HConstants.ENSEMBLE_TABLE_NAME, new Cluster(map, null, null, new ForTestRackManagerOne()))); }