Browse Source

HADOOP-4339. Remove redundant calls from FileSystem/FsShell when
generating/processing ContentSummary. Contributed by David Phillips.


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

Christopher Douglas 16 years ago
parent
commit
316420e5a8

+ 3 - 0
CHANGES.txt

@@ -129,6 +129,9 @@ Trunk (unreleased changes)
     HADOOP-4666. Launch reduces only after a few maps have run in the 
     HADOOP-4666. Launch reduces only after a few maps have run in the 
     Fair Scheduler. (Matei Zaharia via johan)    
     Fair Scheduler. (Matei Zaharia via johan)    
 
 
+    HADOOP-4339. Remove redundant calls from FileSystem/FsShell when
+    generating/processing ContentSummary. (David Phillips via cdouglas)
+
   OPTIMIZATIONS
   OPTIMIZATIONS
 
 
     HADOOP-3293. Fixes FileInputFormat to do provide locations for splits
     HADOOP-3293. Fixes FileInputFormat to do provide locations for splits

+ 2 - 1
src/core/org/apache/hadoop/fs/FileSystem.java

@@ -693,7 +693,8 @@ public abstract class FileSystem extends Configured implements Closeable {
     // f is a directory
     // f is a directory
     long[] summary = {0, 0, 1};
     long[] summary = {0, 0, 1};
     for(FileStatus s : listStatus(f)) {
     for(FileStatus s : listStatus(f)) {
-      ContentSummary c = getContentSummary(s.getPath());
+      ContentSummary c = s.isDir() ? getContentSummary(s.getPath()) :
+                                     new ContentSummary(s.getLen(), 1, 0);
       summary[0] += c.getLength();
       summary[0] += c.getLength();
       summary[1] += c.getFileCount();
       summary[1] += c.getFileCount();
       summary[2] += c.getDirectoryCount();
       summary[2] += c.getDirectoryCount();

+ 7 - 5
src/core/org/apache/hadoop/fs/FsShell.java

@@ -654,14 +654,16 @@ public class FsShell extends Configured implements Tool {
       System.out.println("Found " + items.length + " items");
       System.out.println("Found " + items.length + " items");
       int maxLength = 10;
       int maxLength = 10;
       
       
+      long length[] = new long[items.length];
       for (int i = 0; i < items.length; i++) {
       for (int i = 0; i < items.length; i++) {
-        String size = String.valueOf(srcFs.getContentSummary(items[i]
-                                                                   .getPath()).getLength());
-        if (size.length() > maxLength) maxLength = size.length();
+        length[i] = items[i].isDir() ?
+          srcFs.getContentSummary(items[i].getPath()).getLength() :
+          items[i].getLen();
+        int len = String.valueOf(length[i]).length();
+        if (len > maxLength) maxLength = len;
       }
       }
       for(int i = 0; i < items.length; i++) {
       for(int i = 0; i < items.length; i++) {
-        System.out.printf("%-"+ (maxLength + BORDER) +"d", 
-            srcFs.getContentSummary(items[i].getPath()).getLength());
+        System.out.printf("%-"+ (maxLength + BORDER) +"d", length[i]);
         System.out.println(items[i].getPath());
         System.out.println(items[i].getPath());
       }
       }
     }
     }