浏览代码

HADOOP-2976. When a lease expires, the Namenode ensures that
blocks of the file are adequately replicated. (dhruba)



git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@637722 13f79535-47bb-0310-9956-ffa450edef68

Dhruba Borthakur 17 年之前
父节点
当前提交
936ab973c8
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 3 0
      CHANGES.txt
  2. 14 3
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 3 - 0
CHANGES.txt

@@ -227,6 +227,9 @@ Trunk (unreleased changes)
 
     HADOOP-2679. Fix a typo in libhdfs.  (Jason via dhruba)
 
+    HADOOP-2976. When a lease expires, the Namenode ensures that 
+    blocks of the file are adequately replicated. (dhruba)
+
 Release 0.16.1 - 2008-03-13
 
   INCOMPATIBLE CHANGES

+ 14 - 3
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -1280,8 +1280,17 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
 
     // Now that the file is real, we need to be sure to replicate
     // the blocks.
-    int numExpectedReplicas = pendingFile.getReplication();
-    Block[] pendingBlocks = pendingFile.getBlocks();
+    checkReplicationFactor(newFile);
+    return COMPLETE_SUCCESS;
+  }
+
+  /** 
+   * Check all blocks of a file. If any blocks are lower than their intended
+   * replication factor, then insert them into neededReplication
+   */
+  private void checkReplicationFactor(INodeFile file) {
+    int numExpectedReplicas = file.getReplication();
+    Block[] pendingBlocks = file.getBlocks();
     int nrBlocks = pendingBlocks.length;
     for (int i = 0; i < nrBlocks; i++) {
       // filter out containingNodes that are marked for decommission.
@@ -1293,7 +1302,6 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
                                numExpectedReplicas);
       }
     }
-    return COMPLETE_SUCCESS;
   }
 
   static Random randBlockId = new Random();
@@ -1822,6 +1830,9 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
 
     // close file and persist block allocations for this file
     dir.closeFile(src, newFile);
+
+    // replicate blocks of this file.
+    checkReplicationFactor(newFile);
   
     NameNode.stateChangeLog.debug("DIR* NameSystem.internalReleaseCreate: " + 
                                   src + " is no longer written to by " +