hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r425720 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/FSNamesystem.java
Date Wed, 26 Jul 2006 12:25:05 GMT
Author: cutting
Date: Wed Jul 26 05:25:05 2006
New Revision: 425720

URL: http://svn.apache.org/viewvc?rev=425720&view=rev
Log:
HADOOP-386.  When removing excess DFS block replicas, remove those on nodes with the least
free space first.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=425720&r1=425719&r2=425720&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Wed Jul 26 05:25:05 2006
@@ -97,6 +97,9 @@
     that multiple datanode's can be run on a single host.
     (Devaraj Das via cutting)
 
+28. HADOOP-386.  When removing excess DFS block replicas, remove those
+    on nodes with the least space first.  (Johan Oskarson via cutting)
+
 
 Release 0.4.0 - 2006-06-28
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?rev=425720&r1=425719&r2=425720&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Wed Jul 26 05:25:05
2006
@@ -1391,14 +1391,26 @@
      *
      * srcNodes.size() - dstNodes.size() == replication
      *
-     * For now, we choose nodes randomly.  In the future, we might enforce some
-     * kind of policy (like making sure replicates are spread across racks).
+     * We pick node with least free space
+     * In the future, we might enforce some kind of policy 
+     * (like making sure replicates are spread across racks).
      */
     void chooseExcessReplicates(Vector nonExcess, Block b, short replication) {
         while (nonExcess.size() - replication > 0) {
-            int chosenNode = r.nextInt(nonExcess.size());
-            DatanodeDescriptor cur = (DatanodeDescriptor) nonExcess.elementAt(chosenNode);
-            nonExcess.removeElementAt(chosenNode);
+            DatanodeInfo cur = null;
+            long minSpace = Long.MAX_VALUE;
+            
+            for (Iterator iter = nonExcess.iterator(); iter.hasNext();) {
+                DatanodeInfo node = (DatanodeInfo) iter.next();
+                long free = node.getRemaining();
+                
+                if(minSpace > free) {
+                    minSpace = free;
+                    cur = node;
+                }
+            }
+            
+            nonExcess.remove(cur);
 
             TreeSet excessBlocks = (TreeSet) excessReplicateMap.get(cur.getStorageID());
             if (excessBlocks == null) {



Mime
View raw message