Forráskód Böngészése

HADOOP-561. Fix DFS to write one replica of each block locally, if possible. Contributed by Dhruba.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@466216 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 éve
szülő
commit
858e05f88e
2 módosított fájl, 24 hozzáadás és 6 törlés
  1. 4 0
      CHANGES.txt
  2. 20 6
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 4 - 0
CHANGES.txt

@@ -27,6 +27,10 @@ Trunk (unreleased changes)
     incorrect numbers of arguments result in informative errors rather
     than ArrayOutOfBoundsException.  (Dhruba Borthakur via cutting) 
 
+ 8. HADOOP-561.  Fix DFS so that one replica of each block is written
+    locally, if possible.  This was the intent, but there as a bug.
+    (Dhruba Borthakur via cutting) 
+
 
 Release 0.7.2 - 2006-10-18
 

+ 20 - 6
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -1971,9 +1971,9 @@ class FSNamesystem implements FSConstants {
             if (clientMachine != null && clientMachine.getLength() > 0) {
                 for (Iterator it = targetList.iterator(); it.hasNext(); ) {
                     DatanodeDescriptor node = (DatanodeDescriptor) it.next();
-                    if (clientMachine.equals(node.getHost())) {
-                        if ((node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) &&
-                            (node.getXceiverCount() < (2.0 * avgLoad))) {
+                    if (clientMachine.toString().equals(node.getHost())) {
+                        if ((node.getRemaining() >= blockSize * MIN_BLOCKS_FOR_WRITE) &&
+                            (node.getXceiverCount() <= (2.0 * avgLoad))) {
                             return node;
                         }
                     }
@@ -1985,12 +1985,26 @@ class FSNamesystem implements FSConstants {
             //
             for (Iterator it = targetList.iterator(); it.hasNext(); ) {
                 DatanodeDescriptor node = (DatanodeDescriptor) it.next();
-                if ((node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) &&
-                    (node.getXceiverCount() < (2.0 * avgLoad))) {
+                if ((node.getRemaining() >= blockSize * MIN_BLOCKS_FOR_WRITE) &&
+                    (node.getXceiverCount() <= (2.0 * avgLoad))) {
                     return node;
                 }
             }
 
+            //
+            // If we are still not able to find a good node, then see if
+            // we can pick the clientmachine itself.
+            //
+            if (clientMachine != null && clientMachine.getLength() > 0) {
+                for (Iterator it = targetList.iterator(); it.hasNext(); ) {
+                    DatanodeDescriptor node = (DatanodeDescriptor) it.next();
+                    if (clientMachine.toString().equals(node.getHost()) &&
+                        node.getRemaining() >= blockSize) {
+                        return node;
+                    }
+                }
+            }
+
             //
             // That should do the trick.  But we might not be able
             // to pick any node if the target was out of bytes.  As
@@ -1998,7 +2012,7 @@ class FSNamesystem implements FSConstants {
             //
             for (Iterator it = targetList.iterator(); it.hasNext(); ) {
                 DatanodeDescriptor node = (DatanodeDescriptor) it.next();
-                if (node.getRemaining() > blockSize) {
+                if (node.getRemaining() >= blockSize) {
                     return node;
                 }
             }