Browse Source

svn merge -c 1535188 merging from trunk to branch-2 to fix HDFS-5341.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1535190 13f79535-47bb-0310-9956-ffa450edef68
Kihwal Lee 11 years ago
parent
commit
82d08eb6d4

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -101,6 +101,9 @@ Release 2.3.0 - UNRELEASED
 
 
     HDFS-5239.  Allow FSNamesystem lock fairness to be configurable (daryn)
     HDFS-5239.  Allow FSNamesystem lock fairness to be configurable (daryn)
 
 
+    HDFS-5341. Reduce fsdataset lock duration during directory scanning.
+    (Qus-Jiawei via kihwal)
+
   BUG FIXES
   BUG FIXES
     HDFS-5034.  Remove debug prints from GetFileLinkInfo (Andrew Wang via Colin
     HDFS-5034.  Remove debug prints from GetFileLinkInfo (Andrew Wang via Colin
     Patrick McCabe)
     Patrick McCabe)

+ 11 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DirectoryScanner.java

@@ -191,6 +191,11 @@ public class DirectoryScanner implements Runnable {
 
 
     private final FsVolumeSpi volume;
     private final FsVolumeSpi volume;
 
 
+    /**
+     * Get the file's length in async block scan
+     */
+    private final long blockFileLength;
+
     private final static Pattern CONDENSED_PATH_REGEX =
     private final static Pattern CONDENSED_PATH_REGEX =
         Pattern.compile("(?<!^)(\\\\|/){2,}");
         Pattern.compile("(?<!^)(\\\\|/){2,}");
     
     
@@ -235,6 +240,7 @@ public class DirectoryScanner implements Runnable {
         getCondensedPath(vol.getBasePath());
         getCondensedPath(vol.getBasePath());
       this.blockSuffix = blockFile == null ? null :
       this.blockSuffix = blockFile == null ? null :
         getSuffix(blockFile, condensedVolPath);
         getSuffix(blockFile, condensedVolPath);
+      this.blockFileLength = (blockFile != null) ? blockFile.length() : 0; 
       if (metaFile == null) {
       if (metaFile == null) {
         this.metaSuffix = null;
         this.metaSuffix = null;
       } else if (blockFile == null) {
       } else if (blockFile == null) {
@@ -251,6 +257,10 @@ public class DirectoryScanner implements Runnable {
         new File(volume.getBasePath(), blockSuffix);
         new File(volume.getBasePath(), blockSuffix);
     }
     }
 
 
+    long getBlockFileLength() {
+      return blockFileLength;
+    }
+
     File getMetaFile() {
     File getMetaFile() {
       if (metaSuffix == null) {
       if (metaSuffix == null) {
         return null;
         return null;
@@ -458,7 +468,7 @@ public class DirectoryScanner implements Runnable {
             // Block metadata file exits and block file is missing
             // Block metadata file exits and block file is missing
             addDifference(diffRecord, statsRecord, info);
             addDifference(diffRecord, statsRecord, info);
           } else if (info.getGenStamp() != memBlock.getGenerationStamp()
           } else if (info.getGenStamp() != memBlock.getGenerationStamp()
-              || info.getBlockFile().length() != memBlock.getNumBytes()) {
+              || info.getBlockFileLength() != memBlock.getNumBytes()) {
             // Block metadata file is missing or has wrong generation stamp,
             // Block metadata file is missing or has wrong generation stamp,
             // or block file length is different than expected
             // or block file length is different than expected
             statsRecord.mismatchBlocks++;
             statsRecord.mismatchBlocks++;