Prechádzať zdrojové kódy

HDFS-736. commitBlockSynchronization() updates block GS and length in-place. Contributed by Konstantin Shvachko.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@831170 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 15 rokov pred
rodič
commit
c580ab5af6

+ 4 - 1
CHANGES.txt

@@ -318,9 +318,12 @@ Release 0.21.0 - Unreleased
 
     HDFS-730. Add 4 fault injection tests to simulate non-responsive datanode
     and out-of-memory problem for pipeline close ack.  (szetszwo)
-    
+
     HDFS-728. Create a comprehensive functional test for append. (hairong)
 
+    HDFS-736. commitBlockSynchronization() updates block GS and length in-place.
+    (shv)
+
   BUG FIXES
 
     HDFS-76. Better error message to users when commands fail because of 

+ 13 - 20
src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -2047,19 +2047,19 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
           + ", closeFile=" + closeFile
           + ", deleteBlock=" + deleteblock
           + ")");
-    final BlockInfo oldblockinfo = blockManager.getStoredBlock(lastblock);
-    if (oldblockinfo == null) {
+    final BlockInfo storedBlock = blockManager.getStoredBlock(lastblock);
+    if (storedBlock == null) {
       throw new IOException("Block (=" + lastblock + ") not found");
     }
-    INodeFile iFile = oldblockinfo.getINode();
-    if (!iFile.isUnderConstruction() || oldblockinfo.isComplete()) {
+    INodeFile iFile = storedBlock.getINode();
+    if (!iFile.isUnderConstruction() || storedBlock.isComplete()) {
       throw new IOException("Unexpected block (=" + lastblock
           + ") since the file (=" + iFile.getLocalName()
           + ") is not under construction");
     }
 
     long recoveryId =
-      ((BlockInfoUnderConstruction)oldblockinfo).getBlockRecoveryId();
+      ((BlockInfoUnderConstruction)storedBlock).getBlockRecoveryId();
     if(recoveryId != newgenerationstamp) {
       throw new IOException("The recovery id " + newgenerationstamp
           + " does not match current recovery id "
@@ -2068,21 +2068,14 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
         
     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.
-    blockManager.removeBlockFromMap(oldblockinfo);
-
     if (deleteblock) {
       pendingFile.removeLastBlock(lastblock);
+      blockManager.removeBlockFromMap(storedBlock);
     }
     else {
-      // update last block, construct newblockinfo and add it to the blocks map
-      lastblock.set(lastblock.getBlockId(), newlength, newgenerationstamp);
-      BlockInfoUnderConstruction newblockinfo = 
-        new BlockInfoUnderConstruction(
-            lastblock, pendingFile.getReplication());
-      blockManager.addINode(newblockinfo, pendingFile);
+      // update last block
+      storedBlock.setGenerationStamp(newgenerationstamp);
+      storedBlock.setNumBytes(newlength);
 
       // find the DatanodeDescriptor objects
       // There should be no locations in the blockManager till now because the
@@ -2099,11 +2092,11 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
         // 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);
+          descriptors[i].addBlock(storedBlock);
         }
       }
-      // add locations into the INodeUnderConstruction
-      pendingFile.setLastBlock(newblockinfo, descriptors);
+      // add pipeline locations into the INodeUnderConstruction
+      pendingFile.setLastBlock(storedBlock, descriptors);
     }
 
     // If this commit does not want to close the file, persist
@@ -2119,7 +2112,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
     }
 
     // commit the last block
-    blockManager.commitLastBlock(pendingFile, lastblock);
+    blockManager.commitLastBlock(pendingFile, storedBlock);
 
     //remove lease, close file
     finalizeINodeFileUnderConstruction(src, pendingFile);

+ 0 - 13
src/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java

@@ -218,19 +218,6 @@ class INodeFile extends INode {
     return blocks[blocks.length - 2];
   }
 
-  // SHV !!! this is not used anywhere - remove
-  INodeFileUnderConstruction toINodeFileUnderConstruction(
-      String clientName, String clientMachine, DatanodeDescriptor clientNode
-      ) throws IOException {
-    if (isUnderConstruction()) {
-      return (INodeFileUnderConstruction)this;
-    }
-    return new INodeFileUnderConstruction(name,
-        blockReplication, modificationTime, preferredBlockSize,
-        blocks, getPermissionStatus(),
-        clientName, clientMachine, clientNode);
-  }
-
   /**
    * Get the last block of the file.
    * Make sure it has the right type.