hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r925345 - in /hadoop/zookeeper/trunk: CHANGES.txt src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java
Date Fri, 19 Mar 2010 17:29:50 GMT
Author: mahadev
Date: Fri Mar 19 17:29:50 2010
New Revision: 925345

URL: http://svn.apache.org/viewvc?rev=925345&view=rev
Log:
ZOOKEEPER-717.  add a preferred list to the instancemanager (breed via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=925345&r1=925344&r2=925345&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Mar 19 17:29:50 2010
@@ -310,6 +310,9 @@ BUGFIXES: 
 
   ZOOKEEPER-718. the fatjar is missing libraries (ben via mahadev)
 
+  ZOOKEEPER-717.  add a preferred list to the instancemanager (breed via
+  mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java?rev=925345&r1=925344&r2=925345&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java
(original)
+++ hadoop/zookeeper/trunk/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java
Fri Mar 19 17:29:50 2010
@@ -18,6 +18,8 @@
 
 package org.apache.zookeeper.test.system;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -67,6 +69,16 @@ public class InstanceManager implements 
             this.weight = weight;
         }
     }
+    private static List<String> preferredList = new ArrayList<String>();
+    static {
+        String list = System.getProperty("ic.preferredList");
+        if (list != null) {
+            preferredList = Arrays.asList(list.split(","));
+            System.err.println("Preferred List: " + preferredList);
+        } else {
+            System.err.println("Preferred List is empty");
+        }
+    }
     private HashMap<String, HashSet<Assigned>> assignments = new HashMap<String,
HashSet<Assigned>>();
     private HashMap<String, Assigned> instanceToAssignment = new HashMap<String,
Assigned>();
     public InstanceManager(ZooKeeper zk, String prefix) throws KeeperException, InterruptedException
{
@@ -174,6 +186,19 @@ public class InstanceManager implements 
         // find most idle node
         String mostIdle = null;
         int mostIdleWeight = Integer.MAX_VALUE;
+        for(String preferred: preferredList) {
+            HashSet<Assigned> assignmentList = assignments.get(preferred);
+            int w = 0;
+            if (assignmentList != null) {
+                for(Assigned a: assignmentList) {
+                    w += a.weight;
+                }
+                if (w < mostIdleWeight) {
+                    mostIdleWeight = w;
+                    mostIdle = preferred;
+                }
+            }
+        }
         for(Entry<String, HashSet<Assigned>> e: assignments.entrySet()) {
             int w = 0;
             for(Assigned a: e.getValue()) {



Mime
View raw message