HBASE-10726 Fix java.lang.ArrayIndexOutOfBoundsException in StochasticLoadBalancer (Enis Soztutar)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1576795 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2014-03-12 16:02:36 +00:00
parent d54525ca90
commit f4ee8a05ea
2 changed files with 13 additions and 7 deletions

View File

@ -543,15 +543,14 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
return pickOtherRandomServer(cluster, thisServer);
}
int idx = 0;
while (idx < regionLocations.length && regionLocations[idx] == thisServer) {
idx++;
for (int loc : regionLocations) {
if (loc >= 0 && loc != thisServer) { // find the first suitable server
return loc;
}
}
return idx < regionLocations.length
? regionLocations[idx]
: pickOtherRandomServer(cluster, thisServer);
// no location found
return pickOtherRandomServer(cluster, thisServer);
}
void setServices(MasterServices services) {

View File

@ -295,6 +295,8 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
Lists.newArrayList(servers.get(0), servers.get(1)));
when(locationFinder.getTopBlockLocations(regions.get(42))).thenReturn(
Lists.newArrayList(servers.get(4), servers.get(9), servers.get(5)));
when(locationFinder.getTopBlockLocations(regions.get(43))).thenReturn(
Lists.newArrayList(ServerName.valueOf("foo", 0, 0))); // this server does not exists in clusterStatus
BaseLoadBalancer.Cluster cluster = new Cluster(clusterState, null, locationFinder);
@ -302,6 +304,7 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
int r1 = ArrayUtils.indexOf(cluster.regions, regions.get(1));
int r10 = ArrayUtils.indexOf(cluster.regions, regions.get(10));
int r42 = ArrayUtils.indexOf(cluster.regions, regions.get(42));
int r43 = ArrayUtils.indexOf(cluster.regions, regions.get(43));
int s0 = cluster.serversToIndex.get(servers.get(0).getHostAndPort());
int s1 = cluster.serversToIndex.get(servers.get(1).getHostAndPort());
@ -326,6 +329,10 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
assertEquals(s4, cluster.regionLocations[r42][0]);
assertEquals(s9, cluster.regionLocations[r42][1]);
assertEquals(s5, cluster.regionLocations[r42][2]);
// region 43 locations
assertEquals(1, cluster.regionLocations[r43].length);
assertEquals(-1, cluster.regionLocations[r43][0]);
}
}