HBASE-18164 Fast locality computation in balancer - addendum handles NaN

Signed-off-by: tedyu <yuzhihong@gmail.com>
Signed-off-by: Sean Busbey <busbey@apache.org>
This commit is contained in:
Kahlil Oppenheimer 2017-06-06 15:53:43 -04:00 committed by Sean Busbey
parent 141482512a
commit 8da6f069c3
1 changed files with 4 additions and 3 deletions

View File

@ -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 // We normalize locality to be a score between 0 and 1.0 representing how good it
// is compared to how good it could be // is compared to how good it could be. If bestLocality is 0, assume locality is 100
locality /= bestLocality; // (and the cost is 0)
locality = bestLocality == 0 ? 1.0 : locality / bestLocality;
} }
@Override @Override
@ -1298,7 +1299,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
return; return;
} }
double localityDelta = getWeightedLocality(region, newEntity) - getWeightedLocality(region, oldEntity); double localityDelta = getWeightedLocality(region, newEntity) - getWeightedLocality(region, oldEntity);
double normalizedDelta = localityDelta / bestLocality; double normalizedDelta = bestLocality == 0 ? 0.0 : localityDelta / bestLocality;
locality += normalizedDelta; locality += normalizedDelta;
} }