accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1397048 - /accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
Date Thu, 11 Oct 2012 13:42:59 GMT
Author: ecn
Date: Thu Oct 11 13:42:58 2012
New Revision: 1397048

URL: http://svn.apache.org/viewvc?rev=1397048&view=rev
Log:
ACCUMULO-770 randomize the list of potential locations when assigning tablets

Modified:
    accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java

Modified: accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java?rev=1397048&r1=1397047&r2=1397048&view=diff
==============================================================================
--- accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
(original)
+++ accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
Thu Oct 11 13:42:58 2012
@@ -22,9 +22,9 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.SortedMap;
-import java.util.Map.Entry;
 
 import org.apache.accumulo.core.data.KeyExtent;
 import org.apache.accumulo.core.master.thrift.TableInfo;
@@ -50,6 +50,12 @@ public class DefaultLoadBalancer extends
     tableToBalance = table;
   }
   
+  List<TServerInstance> randomize(Set<TServerInstance> locations) {
+    List<TServerInstance> result = new ArrayList<TServerInstance>(locations);
+    Collections.shuffle(result);
+    return result;
+  }
+  
   public TServerInstance getAssignment(SortedMap<TServerInstance,TabletServerStatus>
locations, KeyExtent extent, TServerInstance last) {
     if (locations.size() == 0)
       return null;
@@ -68,11 +74,11 @@ public class DefaultLoadBalancer extends
     // The strategy here is to walk through the locations and hand them back, one at a time
     // Grab an iterator off of the set of options; use a new iterator if it hands back something
not in the current list.
     if (assignments == null || !assignments.hasNext())
-      assignments = locations.keySet().iterator();
+      assignments = randomize(locations.keySet()).iterator();
     TServerInstance result = assignments.next();
     if (!locations.containsKey(result)) {
       assignments = null;
-      return locations.keySet().iterator().next();
+      return randomize(locations.keySet()).iterator().next();
     }
     return result;
   }



Mime
View raw message