From dc2bb6a908569a3d34b8b20df10c7921528a0817 Mon Sep 17 00:00:00 2001 From: clarax Date: Sun, 26 Sep 2021 00:10:44 -0700 Subject: [PATCH] HBASE-26297 Balancer run is improperly triggered by accuracy error of double comparison (#3698) Signed-off-by: Duo Zhang --- .../hbase/master/balancer/StochasticLoadBalancer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 da51175ccc6..216b665f2c6 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 @@ -313,11 +313,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { @Override protected synchronized boolean areSomeRegionReplicasColocated(Cluster c) { regionReplicaHostCostFunction.init(c); - if (regionReplicaHostCostFunction.cost() > 0) { + if (Math.abs(regionReplicaHostCostFunction.cost()) > CostFunction.COST_EPSILON) { return true; } regionReplicaRackCostFunction.init(c); - if (regionReplicaRackCostFunction.cost() > 0) { + if (Math.abs(regionReplicaRackCostFunction.cost()) > CostFunction.COST_EPSILON) { return true; } return false; @@ -811,6 +811,9 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { * Base class of StochasticLoadBalancer's Cost Functions. */ public abstract static class CostFunction { + + public static final double COST_EPSILON = 0.0001; + private float multiplier = 0; protected Cluster cluster;