Browse Source

HDFS-1257. Race condition on FSNamesystem#recentInvalidateSets introduced by HADOOP-5124. Contributed by Eric Payne.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security@1199534 13f79535-47bb-0310-9956-ffa450edef68
Jitendra Nath Pandey 13 years ago
parent
commit
b48903a260
2 changed files with 12 additions and 6 deletions
  1. 3 0
      CHANGES.txt
  2. 9 6
      src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

+ 3 - 0
CHANGES.txt

@@ -142,6 +142,9 @@ Release 0.20.205.1 - unreleased
     "HdfsFileStatus" and "localName" respectively to "FileStatus" and
     "HdfsFileStatus" and "localName" respectively to "FileStatus" and
     "pathSuffix" in JSON response.  (szetszwo)
     "pathSuffix" in JSON response.  (szetszwo)
 
 
+    HDFS-1257. Race condition on FSNamesystem#recentInvalidateSets introduced 
+    by HADOOP-5124. (Eric Payne via jitendra)
+
 Release 0.20.205.0 - 2011.10.06
 Release 0.20.205.0 - 2011.10.06
 
 
   NEW FEATURES
   NEW FEATURES

+ 9 - 6
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -2837,12 +2837,14 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean,
    * @return total number of block for deletion
    * @return total number of block for deletion
    */
    */
   int computeInvalidateWork(int nodesToProcess) {
   int computeInvalidateWork(int nodesToProcess) {
-    int numOfNodes = recentInvalidateSets.size();
+    int numOfNodes = 0;
+    ArrayList<String> keyArray;
+    synchronized (this) {
+      numOfNodes = recentInvalidateSets.size();
+      // get an array of the keys
+      keyArray = new ArrayList<String>(recentInvalidateSets.keySet());
+    }
     nodesToProcess = Math.min(numOfNodes, nodesToProcess);
     nodesToProcess = Math.min(numOfNodes, nodesToProcess);
-    
-    // get an array of the keys
-    ArrayList<String> keyArray =
-      new ArrayList<String>(recentInvalidateSets.keySet());
 
 
     // randomly pick up <i>nodesToProcess</i> nodes 
     // randomly pick up <i>nodesToProcess</i> nodes 
     // and put them at [0, nodesToProcess)
     // and put them at [0, nodesToProcess)
@@ -3164,8 +3166,9 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean,
       return 0;
       return 0;
     }
     }
     Collection<Block> invalidateSet = recentInvalidateSets.get(nodeId);
     Collection<Block> invalidateSet = recentInvalidateSets.get(nodeId);
-    if (invalidateSet == null)
+    if (invalidateSet == null) {
       return 0;
       return 0;
+    }
 
 
     ArrayList<Block> blocksToInvalidate = 
     ArrayList<Block> blocksToInvalidate = 
       new ArrayList<Block>(blockInvalidateLimit);
       new ArrayList<Block>(blockInvalidateLimit);