Browse Source

HDFS-2638. Improve a block recovery log. Contributed by Eli Collins

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1211578 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins 13 years ago
parent
commit
5c04c392d7

+ 2 - 0
CHANGES.txt

@@ -105,6 +105,8 @@ Release 1.1.0 - unreleased
 
     MAPREDUCE-2103. task-controller shouldn't require o-r permissions. (eli)
 
+    HDFS-2638. Improve a block recovery log. (eli)
+
 Release 1.0.0 - unreleased
 
   NEW FEATURES

+ 2 - 2
src/hdfs/org/apache/hadoop/hdfs/DFSClient.java

@@ -2823,7 +2823,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
               // get new block from namenode.
               if (blockStream == null) {
                 LOG.debug("Allocating new block");
-                nodes = nextBlockOutputStream(src); 
+                nodes = nextBlockOutputStream();
                 this.setName("DataStreamer for file " + src +
                              " block " + block);
                 response = new ResponseProcessor(nodes);
@@ -3354,7 +3354,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
      * Must get block ID and the IDs of the destinations from the namenode.
      * Returns the list of target datanodes.
      */
-    private DatanodeInfo[] nextBlockOutputStream(String client) throws IOException {
+    private DatanodeInfo[] nextBlockOutputStream() throws IOException {
       LocatedBlock lb = null;
       boolean retry = false;
       DatanodeInfo[] nodes;

+ 4 - 0
src/hdfs/org/apache/hadoop/hdfs/protocol/Block.java

@@ -116,6 +116,10 @@ public class Block implements Writable, Comparable<Block> {
     generationStamp = stamp;
   }
 
+  public Block getWithWildcardGS() {
+    return new Block(blockId, numBytes, GenerationStamp.WILDCARD_STAMP);
+  }
+
   /**
    */
   public String toString() {

+ 1 - 3
src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -1875,9 +1875,7 @@ public class DataNode extends Configured
     // This can happen if the namenode and client start recovering the same
     // file at the same time.
     synchronized (ongoingRecovery) {
-      Block tmp = new Block();
-      tmp.set(block.getBlockId(), block.getNumBytes(), GenerationStamp.WILDCARD_STAMP);
-      if (ongoingRecovery.get(tmp) != null) {
+      if (ongoingRecovery.get(block.getWithWildcardGS()) != null) {
         String msg = "Block " + block + " is already being recovered, " +
                      " ignoring this request to recover it.";
         LOG.info(msg);

+ 8 - 3
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -2252,8 +2252,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean,
 
     if (deleteblock) {
       pendingFile.removeBlock(lastblock);
-    }
-    else {
+    } else {
       // update last block, construct newblockinfo and add it to the blocks map
       lastblock.set(lastblock.getBlockId(), newlength, newgenerationstamp);
       final BlockInfo newblockinfo = blocksMap.addINode(lastblock, pendingFile);
@@ -5381,7 +5380,13 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean,
     }
     BlockInfo storedBlock = blocksMap.getStoredBlock(block);
     if (storedBlock == null) {
-      String msg = block + " is already commited, storedBlock == null.";
+      BlockInfo match =
+        blocksMap.getStoredBlock(block.getWithWildcardGS());
+      String msg = (match == null)
+        ? block + " is missing"
+        : block + " has out of date GS " + block.getGenerationStamp() +
+                  " found " + match.getGenerationStamp() +
+                  ", may already be committed";
       LOG.info(msg);
       throw new IOException(msg);
     }