瀏覽代碼

Merge -r 745179:745180 from trunk to move the change of HADOOP-5134 to branch 0.19.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.19@745182 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 年之前
父節點
當前提交
33fd336f5c
共有 2 個文件被更改,包括 33 次插入7 次删除
  1. 3 0
      CHANGES.txt
  2. 30 7
      src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

+ 3 - 0
CHANGES.txt

@@ -1099,6 +1099,9 @@ Release 0.18.4 - Unreleased
     HADOOP-5192. Block receiver should not remove a block that's created or
     being written by other threads. (hairong)
  
+    HADOOP-5134. FSNamesystem#commitBlockSynchronization adds under-construction
+    block locations to blocksMap. (Dhruba Borthakur via hairong)
+
 Release 0.18.3 - 2009-01-27
 
   IMPROVEMENTS

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

@@ -1175,7 +1175,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
     //
     LocatedBlock lb = null;
     synchronized (this) {
-      INodeFile file = dir.getFileINode(src);
+      INodeFileUnderConstruction file = (INodeFileUnderConstruction)dir.getFileINode(src);
 
       Block[] blocks = file.getBlocks();
       if (blocks != null && blocks.length > 0) {
@@ -1188,6 +1188,13 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
           for (int i = 0; it != null && it.hasNext(); i++) {
             targets[i] = it.next();
           }
+          // remove the replica locations of this block from the blocksMap
+          for (int i = 0; i < targets.length; i++) {
+            targets[i].removeBlock(storedBlock);
+          }
+          // set the locations of the last block in the lease record
+          file.setLastBlock(storedBlock, targets);
+
           lb = new LocatedBlock(last, targets, 
                                 fileLength-storedBlock.getNumBytes());
 
@@ -1890,7 +1897,10 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
     LOG.info("commitBlockSynchronization(lastblock=" + lastblock
           + ", newgenerationstamp=" + newgenerationstamp
           + ", newlength=" + newlength
-          + ", newtargets=" + Arrays.asList(newtargets) + ")");
+          + ", newtargets=" + Arrays.asList(newtargets)
+          + ", closeFile=" + closeFile
+          + ", deleteBlock=" + deleteblock
+          + ")");
     final BlockInfo oldblockinfo = blocksMap.getStoredBlock(lastblock);
     if (oldblockinfo == null) {
       throw new IOException("Block (=" + lastblock + ") not found");
@@ -1903,6 +1913,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
     }
     INodeFileUnderConstruction pendingFile = (INodeFileUnderConstruction)iFile;
 
+
     // Remove old block from blocks map. This always have to be done
     // because the generation stamp of this block is changing.
     blocksMap.removeBlock(oldblockinfo);
@@ -1914,22 +1925,33 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
       // 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);
-    
-      //update block info
+
+      // find the DatanodeDescriptor objects
+      // There should be no locations in the blocksMap till now because the
+      // file is underConstruction
       DatanodeDescriptor[] descriptors = null;
       if (newtargets.length > 0) {
         descriptors = new DatanodeDescriptor[newtargets.length];
         for(int i = 0; i < newtargets.length; i++) {
           descriptors[i] = getDatanode(newtargets[i]);
+        }
+      }
+      if (closeFile) {
+        // the file is getting closed. Insert block locations into blocksMap.
+        // Otherwise fsck will report these blocks as MISSING, especially if the
+        // blocksReceived from Datanodes take a long time to arrive.
+        for (int i = 0; i < descriptors.length; i++) {
           descriptors[i].addBlock(newblockinfo);
         }
+        pendingFile.setLastBlock(newblockinfo, null);
+      } else {
+        // add locations into the INodeUnderConstruction
+        pendingFile.setLastBlock(newblockinfo, descriptors);
       }
-
-      pendingFile.setLastBlock(newblockinfo, descriptors);
     }
 
     // If this commit does not want to close the file, just persist
-    // block locations and return
+    // blocks and return
     String src = leaseManager.findPath(pendingFile);
     if (!closeFile) {
       dir.persistBlocks(src, pendingFile);
@@ -1942,6 +1964,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
     finalizeINodeFileUnderConstruction(src, pendingFile);
     getEditLog().logSync();
     LOG.info("commitBlockSynchronization(newblock=" + lastblock
+          + ", file=" + src
           + ", newgenerationstamp=" + newgenerationstamp
           + ", newlength=" + newlength
           + ", newtargets=" + Arrays.asList(newtargets) + ") successful");