Bläddra i källkod

Merge -r 761481:761482 from trunk to move the change of HADOOP-5605 to branch 0.20.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20@761485 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 år sedan
förälder
incheckning
20cab66c99
2 ändrade filer med 17 tillägg och 7 borttagningar
  1. 2 0
      CHANGES.txt
  2. 15 7
      src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

+ 2 - 0
CHANGES.txt

@@ -834,6 +834,8 @@ Release 0.20.0 - Unreleased
 
     HADOOP-5607. Fix NPE in TestCapacityScheduler. (cdouglas)
 
+    HADOOP-5605. All the replicas incorrectly got marked as corrupt. (hairong)
+
 Release 0.19.2 - Unreleased
 
   BUG FIXES

+ 15 - 7
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1536,7 +1536,8 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
                             " does not exist. ");
     }
     
-    if (!blocksMap.contains(blk, node)) {
+    final BlockInfo storedBlockInfo = blocksMap.getStoredBlock(blk);
+    if (storedBlockInfo == null) {
       // Check if the replica is in the blockMap, if not 
       // ignore the request for now. This could happen when BlockScanner
       // thread of Datanode reports bad block before Block reports are sent
@@ -1546,16 +1547,23 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
                                    "as corrupt as it does not exists in " +
                                    "blocksMap");
     } else {
-      INodeFile inode = blocksMap.getINode(blk);
-      assert inode!=null : (blk + " in blocksMap must belongs to a file.");
+      INodeFile inode = storedBlockInfo.getINode();
+      if (inode == null) {
+        NameNode.stateChangeLog.info("BLOCK NameSystem.markBlockAsCorrupt: " +
+                                     "block " + blk + " could not be marked " +
+                                     "as corrupt as it does not belong to " +
+                                     "any file");
+        addToInvalidates(storedBlockInfo, node);
+        return;
+      } 
       // Add this replica to corruptReplicas Map 
-      corruptReplicas.addToCorruptReplicasMap(blk, node);
-      if (countNodes(blk).liveReplicas()>inode.getReplication()) {
+      corruptReplicas.addToCorruptReplicasMap(storedBlockInfo, node);
+      if (countNodes(storedBlockInfo).liveReplicas()>inode.getReplication()) {
         // the block is over-replicated so invalidate the replicas immediately
-        invalidateBlock(blk, node);
+        invalidateBlock(storedBlockInfo, node);
       } else {
         // add the block to neededReplication 
-        updateNeededReplications(blk, -1, 0);
+        updateNeededReplications(storedBlockInfo, -1, 0);
       }
     }
   }