From 0b081303b949508caace40218c1a16d8ba59885d Mon Sep 17 00:00:00 2001 From: tedyu Date: Sat, 22 Aug 2015 14:50:57 -0700 Subject: [PATCH] HBASE-14291 NPE On StochasticLoadBalancer Balance Involving RS With No Regions --- .../hadoop/hbase/master/balancer/BaseLoadBalancer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java index 8a7f7dcc6d2..7199ffee382 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java @@ -858,7 +858,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer { int leastLoadedServerIndex = -1; int load = Integer.MAX_VALUE; for (ServerName sn : topLocalServers) { - int index = serversToIndex.get(sn); + if (!serversToIndex.containsKey(sn.getHostAndPort())) { + continue; + } + int index = serversToIndex.get(sn.getHostAndPort()); + if (regionsPerServer[index] == null) { + continue; + } int tempLoad = regionsPerServer[index].length; if (tempLoad <= load) { leastLoadedServerIndex = index;