Przeglądaj źródła

Fix for HADOOP-79. Some namenode optimizations. Contributed by Konstantin Shvachko.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@385885 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 lat temu
rodzic
commit
48b7666eb0

+ 9 - 5
src/java/org/apache/hadoop/dfs/DFSFileInfo.java

@@ -45,12 +45,16 @@ class DFSFileInfo implements Writable {
     }
 
     /**
+     * Create DFSFileInfo by file INode 
      */
-    public DFSFileInfo(UTF8 path, long len, long contentsLen, boolean isDir) {
-        this.path = path;
-        this.len = len;
-        this.contentsLen = contentsLen;
-        this.isDir = isDir;
+    public DFSFileInfo( FSDirectory.INode node ) {
+        this.path = new UTF8(node.computeName());
+        this.isDir = node.isDir();
+        if( isDir ) {
+          this.len = 0;
+          this.contentsLen = node.computeContentsLength();
+        } else 
+          this.len = this.contentsLen = node.computeFileLength();
     }
 
     /**

+ 11 - 11
src/java/org/apache/hadoop/dfs/FSDirectory.java

@@ -58,6 +58,14 @@ class FSDirectory implements FSConstants {
             this.blocks = blocks;
         }
 
+        /**
+         * Check whether it's a directory
+         * @return
+         */
+        synchronized public boolean isDir() {
+          return (blocks == null);
+        }
+
         /**
          * This is the external interface
          */
@@ -612,11 +620,7 @@ class FSDirectory implements FSConstants {
                 DFSFileInfo listing[] = new DFSFileInfo[contents.size()];
                 int i = 0;
                 for (Iterator it = contents.iterator(); it.hasNext(); i++) {
-                    INode cur = (INode) it.next();
-                    UTF8 curName = new UTF8(cur.computeName());
-                    listing[i] = new DFSFileInfo(curName, cur.computeFileLength(), cur.computeContentsLength(), isDir(curName));
-                    //listing[i] = new DFSFileInfo(curName, cur.computeFileLength(), 0, isDir(curName));
-                    //listing[i] = new DFSFileInfo(curName, cur.computeFileLength(), 0, false);
+                    listing[i] = new DFSFileInfo( (INode) it.next() );
                 }
                 return listing;
             }
@@ -655,16 +659,12 @@ class FSDirectory implements FSConstants {
     }
 
     /**
-     * Check whether it's a directory
+     * Check whether the path specifies a directory
      */
     public boolean isDir(UTF8 src) {
         synchronized (rootDir) {
             INode node = rootDir.getNode(normalizePath(src));
-            if (node != null && node.blocks == null) {
-                return true;
-            } else {
-                return false;
-            }
+            return node != null && node.isDir();
         }
     }