hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r1576799 - in /hbase/branches/0.98/hbase-server/src: main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
Date Wed, 12 Mar 2014 16:06:17 GMT
Author: apurtell
Date: Wed Mar 12 16:06:17 2014
New Revision: 1576799

URL: http://svn.apache.org/r1576799
Log:
HBASE-10726 Fix java.lang.ArrayIndexOutOfBoundsException in StochasticLoadBalancer (Enis Soztutar)

Modified:
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
    hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java?rev=1576799&r1=1576798&r2=1576799&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
(original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
Wed Mar 12 16:06:17 2014
@@ -543,15 +543,14 @@ public class StochasticLoadBalancer exte
         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) {

Modified: hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java?rev=1576799&r1=1576798&r2=1576799&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
(original)
+++ hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
Wed Mar 12 16:06:17 2014
@@ -295,6 +295,8 @@ public class TestBaseLoadBalancer extend
       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 extend
     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 extend
     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]);
   }
 
 }



Mime
View raw message