Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java (revision 1469379) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java (working copy) @@ -60,7 +60,7 @@ ArrayList tables; HRegionInfo[] regions; List[] regionLoads; - int[][] regionLocations; //regionIndex -> list of serverIndex sorted by locality + Integer[][] regionLocations; //regionIndex -> list of serverIndex sorted by locality int[][] regionsPerServer; //serverIndex -> region list int[] regionIndexToServerIndex; //regionIndex -> serverIndex @@ -102,13 +102,18 @@ initialRegionIndexToServerIndex = new int[numRegions]; regionIndexToTableIndex = new int[numRegions]; regionLoads = new List[numRegions]; - regionLocations = new int[numRegions][]; + regionLocations = new Integer[numRegions][]; int tableIndex = 0, serverIndex = 0, regionIndex = 0, regionPerServerIndex = 0; + // populate serversToIndex first for (Entry> entry : clusterState.entrySet()) { servers[serverIndex] = entry.getKey(); regionsPerServer[serverIndex] = new int[entry.getValue().size()]; serversToIndex.put(servers[serverIndex], Integer.valueOf(serverIndex)); + serverIndex++; + } + serverIndex = 0; + for (Entry> entry : clusterState.entrySet()) { regionPerServerIndex = 0; for (HRegionInfo region : entry.getValue()) { byte[] tableName = region.getTableName(); @@ -140,9 +145,10 @@ if (regionFinder != null) { //region location List loc = regionFinder.getTopBlockLocations(region); - regionLocations[regionIndex] = new int[loc.size()]; + regionLocations[regionIndex] = new Integer[loc.size()]; for (int i=0; i < loc.size(); i++) { - regionLocations[regionIndex][i] = serversToIndex.get(loc.get(i)); + regionLocations[regionIndex][i] = + loc.get(i) == null ? null : serversToIndex.get(loc.get(i)); } } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java (revision 1469379) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java (working copy) @@ -495,7 +495,7 @@ for (int i = 0; i < cluster.regionLocations.length; i++) { max += 1; int serverIndex = cluster.regionIndexToServerIndex[i]; - int[] regionLocations = cluster.regionLocations[i]; + Integer[] regionLocations = cluster.regionLocations[i]; // If we can't find where the data is getTopBlock returns null. // so count that as being the best possible. @@ -505,7 +505,7 @@ int index = -1; for (int j = 0; j < regionLocations.length; j++) { - if (regionLocations[j] == serverIndex) { + if (regionLocations[j] != null && regionLocations[j] == serverIndex) { index = j; break; }