hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1576971 - in /hbase/branches/hbase-10070: ./ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
Date Wed, 12 Mar 2014 22:42:36 GMT
Author: enis
Date: Wed Mar 12 22:42:36 2014
New Revision: 1576971

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

Modified:
    hbase/branches/hbase-10070/   (props changed)
    hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
    hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java

Propchange: hbase/branches/hbase-10070/
------------------------------------------------------------------------------
  Merged /hbase/trunk:r1576795

Modified: hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java?rev=1576971&r1=1576970&r2=1576971&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
(original)
+++ hbase/branches/hbase-10070/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
Wed Mar 12 22:42:36 2014
@@ -561,15 +561,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/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java?rev=1576971&r1=1576970&r2=1576971&view=diff
==============================================================================
--- hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
(original)
+++ hbase/branches/hbase-10070/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
Wed Mar 12 22:42:36 2014
@@ -448,6 +448,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, null);
 
@@ -455,6 +457,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());
@@ -479,6 +482,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