Explorar el Código

HDFS-1774. Small optimization to FSDataset. Contributed by Uma Maheswara Rao G

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1148894 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins hace 14 años
padre
commit
cda43d71be

+ 2 - 0
hdfs/CHANGES.txt

@@ -579,6 +579,8 @@ Trunk (unreleased changes)
     and Random object creation to DFSUtil; move DFSClient.stringifyToken(..)
     to DelegationTokenIdentifier.  (szetszwo)
 
+    HDFS-1774. Small optimization to FSDataset. (Uma Maheswara Rao G via eli)
+    
   OPTIMIZATIONS
 
     HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

+ 4 - 11
hdfs/src/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java

@@ -99,23 +99,16 @@ public class FSDataset implements FSConstants, FSDatasetInterface {
         }
       } else {
         File[] files = FileUtil.listFiles(dir); 
-        int numChildren = 0;
+        List<FSDir> dirList = new ArrayList<FSDir>();
         for (int idx = 0; idx < files.length; idx++) {
           if (files[idx].isDirectory()) {
-            numChildren++;
+            dirList.add(new FSDir(files[idx]));
           } else if (Block.isBlockFilename(files[idx])) {
             numBlocks++;
           }
         }
-        if (numChildren > 0) {
-          children = new FSDir[numChildren];
-          int curdir = 0;
-          for (int idx = 0; idx < files.length; idx++) {
-            if (files[idx].isDirectory()) {
-              children[curdir] = new FSDir(files[idx]);
-              curdir++;
-            }
-          }
+        if (dirList.size() > 0) {
+          children = dirList.toArray(new FSDir[dirList.size()]);
         }
       }
     }