From 812b38332557b497560655005c839a92543a80ec Mon Sep 17 00:00:00 2001 From: Kahlil Oppenheimer Date: Tue, 6 Jun 2017 15:53:43 -0400 Subject: [PATCH] HBASE-18164 Fast locality computation in balancer - addendum handles NaN Signed-off-by: tedyu Signed-off-by: Sean Busbey --- .../hbase/master/balancer/StochasticLoadBalancer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 63ec0b50f93..6f0558132a3 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 @@ -1286,8 +1286,9 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { } // We normalize locality to be a score between 0 and 1.0 representing how good it - // is compared to how good it could be - locality /= bestLocality; + // is compared to how good it could be. If bestLocality is 0, assume locality is 100 + // (and the cost is 0) + locality = bestLocality == 0 ? 1.0 : locality / bestLocality; } @Override @@ -1298,7 +1299,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { return; } double localityDelta = getWeightedLocality(region, newEntity) - getWeightedLocality(region, oldEntity); - double normalizedDelta = localityDelta / bestLocality; + double normalizedDelta = bestLocality == 0 ? 0.0 : localityDelta / bestLocality; locality += normalizedDelta; }