Browse Source

Merge -r 753345:753346 to move the change of HADOOP-5465 from trunk to branch 0.20.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20@753364 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 years ago
parent
commit
f597a6c915
2 changed files with 10 additions and 5 deletions
  1. 4 0
      CHANGES.txt
  2. 6 5
      src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java

+ 4 - 0
CHANGES.txt

@@ -1841,6 +1841,10 @@ Release 0.18.4 - Unreleased
     HADOOP-5412. Simulated DataNode should not write to a block that's being
     written by another thread. (hairong)
 
+    HADOOP-5414. Fix the problem of blocks remaining under-replicated by
+    providing synchronized modification to the counter xmitsInProgress in
+    DataNode. (hairong)
+
 Release 0.18.3 - 2009-01-27
 
   IMPROVEMENTS

+ 6 - 5
src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -39,6 +39,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -162,7 +163,7 @@ public class DataNode extends Configured
   private final Map<Block, Block> ongoingRecovery = new HashMap<Block, Block>();
   private LinkedList<String> delHints = new LinkedList<String>();
   public final static String EMPTY_DEL_HINT = "";
-  int xmitsInProgress = 0;
+  AtomicInteger xmitsInProgress = new AtomicInteger();
   Daemon dataXceiverServer = null;
   ThreadGroup threadGroup = null;
   long blockReportInterval;
@@ -702,7 +703,7 @@ public class DataNode extends Configured
                                                        data.getCapacity(),
                                                        data.getDfsUsed(),
                                                        data.getRemaining(),
-                                                       xmitsInProgress,
+                                                       xmitsInProgress.get(),
                                                        getXceiverCount());
           myMetrics.heartbeats.inc(now() - startTime);
           //LOG.info("Just sent heartbeat, with name " + localName);
@@ -1109,7 +1110,7 @@ public class DataNode extends Configured
      * Do the deed, write the bytes
      */
     public void run() {
-      xmitsInProgress++;
+      xmitsInProgress.getAndIncrement();
       Socket sock = null;
       DataOutputStream out = null;
       BlockSender blockSender = null;
@@ -1158,10 +1159,10 @@ public class DataNode extends Configured
         LOG.warn(dnRegistration + ":Failed to transfer " + b + " to " + targets[0].getName()
             + " got " + StringUtils.stringifyException(ie));
       } finally {
+        xmitsInProgress.getAndDecrement();
         IOUtils.closeStream(blockSender);
         IOUtils.closeStream(out);
         IOUtils.closeSocket(sock);
-        xmitsInProgress--;
       }
     }
   }
@@ -1290,7 +1291,7 @@ public class DataNode extends Configured
       "data=" + data +
       ", localName='" + dnRegistration.getName() + "'" +
       ", storageID='" + dnRegistration.getStorageID() + "'" +
-      ", xmitsInProgress=" + xmitsInProgress +
+      ", xmitsInProgress=" + xmitsInProgress.get() +
       "}";
   }