Browse Source

HADOOP-4747. Speed up FsShell::ls by removing redundant calls to the
filesystem. Contributed by David Phillips.


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

Christopher Douglas 16 năm trước cách đây
mục cha
commit
2eb39c6e52
2 tập tin đã thay đổi với 14 bổ sung7 xóa
  1. 4 1
      CHANGES.txt
  2. 10 6
      src/core/org/apache/hadoop/fs/FsShell.java

+ 4 - 1
CHANGES.txt

@@ -168,11 +168,14 @@ Trunk (unreleased changes)
     via cdouglas)
 
     HADOOP-4690.  fuse-dfs - create source file/function + utils + config +
-main source files. (pete wyckoff via mahadev)
+    main source files. (pete wyckoff via mahadev)
 
     HADOOP-3750. Fix and enforce module dependencies. (Sharad Agarwal via
     tomwhite)
 
+    HADOOP-4747. Speed up FsShell::ls by removing redundant calls to the
+    filesystem. (David Phillips via cdouglas)
+
   OPTIMIZATIONS
 
     HADOOP-3293. Fixes FileInputFormat to do provide locations for splits

+ 10 - 6
src/core/org/apache/hadoop/fs/FsShell.java

@@ -573,7 +573,7 @@ public class FsShell extends Configured implements Tool {
     boolean printHeader = (srcs.length == 1) ? true: false;
     int numOfErrors = 0;
     for(int i=0; i<srcs.length; i++) {
-      numOfErrors += ls(srcs[i].getPath(), srcFs, recursive, printHeader);
+      numOfErrors += ls(srcs[i], srcFs, recursive, printHeader);
     }
     return numOfErrors == 0 ? 0 : -1;
   }
@@ -581,7 +581,7 @@ public class FsShell extends Configured implements Tool {
   /* list all files under the directory <i>src</i>
    * ideally we should provide "-l" option, that lists like "ls -l".
    */
-  private int ls(Path src, FileSystem srcFs, boolean recursive,
+  private int ls(FileStatus src, FileSystem srcFs, boolean recursive,
       boolean printHeader) throws IOException {
     final String cmd = recursive? "lsr": "ls";
     final FileStatus[] items = shellListStatus(cmd, srcFs, src);
@@ -627,7 +627,7 @@ public class FsShell extends Configured implements Tool {
         System.out.print(mdate + " ");
         System.out.println(cur.toUri().getPath());
         if (recursive && stat.isDir()) {
-          numOfErrors += ls(cur,srcFs, recursive, printHeader);
+          numOfErrors += ls(stat,srcFs, recursive, printHeader);
         }
       }
       return numOfErrors;
@@ -1136,7 +1136,12 @@ public class FsShell extends Configured implements Tool {
   /** helper returns listStatus() */
   private static FileStatus[] shellListStatus(String cmd, 
                                                    FileSystem srcFs,
-                                                   Path path) {
+                                                   FileStatus src) {
+    if (!src.isDir()) {
+      FileStatus[] files = { src };
+      return files;
+    }
+    Path path = src.getPath();
     try {
       FileStatus[] files = srcFs.listStatus(path);
       if ( files == null ) {
@@ -1163,8 +1168,7 @@ public class FsShell extends Configured implements Tool {
     int errors = 0;
     handler.run(stat, srcFs);
     if (recursive && stat.isDir() && handler.okToContinue()) {
-      FileStatus[] files = shellListStatus(handler.getName(), srcFs, 
-                                                stat.getPath());
+      FileStatus[] files = shellListStatus(handler.getName(), srcFs, stat);
       if (files == null) {
         return 1;
       }