Author: cutting Date: Wed Dec 13 14:10:40 2006 New Revision: 486856 URL: http://svn.apache.org/viewvc?view=rev&rev=486856 Log: HADOOP-454. Add a 'dfs -dus' command that provides summary disk usage. Contributed by Hairong.
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=486856&r1=486855&r2=486856 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Wed Dec 13 14:10:40 2006 @@ -89,6 +89,9 @@ 25. HADOOP-794. Fix a divide-by-zero exception when a job specifies zero map tasks. (omalley via cutting) +26. HADOOP-454. Add a 'dfs -dus' command that provides summary disk + usage. (Hairong Kuang via cutting) + Release 0.9.1 - 2006-12-06 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java?view=diff&rev=486856&r1=486855&r2=486856 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Wed Dec 13 14:10:40 2006 @@ -327,6 +327,32 @@ } } } + + /** + * Show the summary disk usage of each dir/file in DFS + * that matches the file pattern <i>src</i> + * @param src a file pattern specifying source files + * @throws IOException + * @see org.apache.hadoop.fs.FileSystem#globPaths(Path) + */ + public void dus(String src) throws IOException { + Path paths[] = fs.globPaths( new Path(src) ); + if( paths==null && paths.length==0 ) { + throw new IOException( "dus: No match: " + src ); + } + for(int i=0; i<paths.length; i++) { + Path items[] = fs.listPaths( paths[i] ); + if (items != null) { + int totalSize=0; + for(int j=0; j<items.length; j++) { + totalSize += ((DfsPath)items[j]).getContentsLength(); + } + String pathStr = paths[i].toString(); + System.out.println( + ("".equals(pathStr)?".":pathStr) + "\t" + totalSize); + } + } + } /** * Create the given dir @@ -594,6 +620,8 @@ delete(argv[i], true); } else if ("-du".equals(cmd)) { du(argv[i]); + } else if ("-dus".equals(cmd)) { + dus(argv[i]); } else if ("-ls".equals(cmd)) { ls(argv[i], false); } else if ("-lsr".equals(cmd)) { @@ -641,8 +669,9 @@ System.err.println("Usage: java DFSShell" + " [-D <[property=value>]"); } else if ("-ls".equals(cmd) || "-lsr".equals(cmd) || - "-du".equals(cmd) || "-rm".equals(cmd) || - "-rmr".equals(cmd) || "-mkdir".equals(cmd)) { + "-du".equals(cmd) || "-dus".equals(cmd) || + "-rm".equals(cmd) || "-rmr".equals(cmd) || + "-mkdir".equals(cmd)) { System.err.println("Usage: java DFSShell" + " [" + cmd + " <path>]"); } else if ("-mv".equals(cmd) || "-cp".equals(cmd)) { @@ -673,6 +702,7 @@ System.err.println(" [-ls <path>]" ); System.err.println(" [-lsr <path>]"); System.err.println(" [-du <path>]"); + System.err.println(" [-dus <path>]"); System.err.println(" [-mv <src> <dst>]"); System.err.println(" [-cp <src> <dst>]"); System.err.println(" [-rm <path>]"); @@ -789,6 +819,12 @@ } else { du(""); } + } else if( "-dus".equals(cmd)) { + if (i < argv.length) { + exitCode = doall(cmd, argv, conf, i); + } else { + dus(""); + } } else if ("-mkdir".equals(cmd)) { exitCode = doall(cmd, argv, conf, i); } else {