[Swift-commit] cog r3616

swift at ci.uchicago.edu swift at ci.uchicago.edu
Sun Mar 3 15:25:05 CST 2013


------------------------------------------------------------------------
r3616 | hategan | 2013-03-03 15:24:15 -0600 (Sun, 03 Mar 2013) | 1 line

use a sorted map to sort blocks by their time left since a comparator cannot guaranteed to be correct because calls to block.sizeLeft() are dependent on the time when the call is made
------------------------------------------------------------------------
Index: modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/job/manager/BlockQueueProcessor.java
===================================================================
--- modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/job/manager/BlockQueueProcessor.java	(revision 3615)
+++ modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/job/manager/BlockQueueProcessor.java	(working copy)
@@ -6,14 +6,13 @@
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
 import org.apache.log4j.Logger;
@@ -429,31 +428,18 @@
      *
      */
     protected void removeIdleBlocks() {
-        ArrayList<Block> sorted;
-
+        SortedMap<Double, Block> sorted = new TreeMap<Double, Block>();
+        
         synchronized (blocks) {
-            sorted = new ArrayList<Block>(blocks.values());
-            Collections.sort(sorted, new Comparator<Block>() {
-                public int compare(Block b1, Block b2) {
-                    double s1 = b1.sizeLeft();
-                    double s2 = b2.sizeLeft();
-                    if (s1 == s2) {
-                    	return 0;
-                    }
-                    else if (s1 < s2) {
-                        return -1;
-                    }
-                    else {
-                        return 1;
-                    }
-                }
-            });
+            for (Block b : blocks.values()) {
+                sorted.put(b.sizeLeft(), b);
+            }
         }
 
         double needed = queued.getJSize() + running.getSize();
 
         double sum = 0;
-        for (Block b : sorted) {
+        for (Block b : sorted.values()) {
             if (sum >= needed
                     && !b.isSuspended()
                     && (System.currentTimeMillis() - b.getLastUsed()) > Block.SUSPEND_SHUTDOWN_DELAY) {



More information about the Swift-commit mailing list