hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r561245 - in /lucene/hadoop/branches/branch-0.14: CHANGES.txt src/java/org/apache/hadoop/dfs/DFSFileInfo.java src/java/org/apache/hadoop/dfs/FSDirectory.java src/java/org/apache/hadoop/dfs/FSEditLog.java
Date Tue, 31 Jul 2007 06:50:02 GMT
Author: dhruba
Date: Mon Jul 30 23:50:00 2007
New Revision: 561245

URL: http://svn.apache.org/viewvc?view=rev&rev=561245
Log:
HADOOP-1653. Cleanup of FsDirectory. Made INode a static class.
Contributed by Christophe Taton.
Merge -r r561200 from trunk to 0.14 branch.


Modified:
    lucene/hadoop/branches/branch-0.14/CHANGES.txt
    lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/DFSFileInfo.java
    lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSDirectory.java
    lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSEditLog.java

Modified: lucene/hadoop/branches/branch-0.14/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/branches/branch-0.14/CHANGES.txt?view=diff&rev=561245&r1=561244&r2=561245
==============================================================================
--- lucene/hadoop/branches/branch-0.14/CHANGES.txt (original)
+++ lucene/hadoop/branches/branch-0.14/CHANGES.txt Mon Jul 30 23:50:00 2007
@@ -1,6 +1,5 @@
 Hadoop Change Log
 
-
 Branch 0.14 (unreleased changes)
 
   1. HADOOP-1197.  In Configuration, deprecate getObject() and add
@@ -411,6 +410,10 @@
      (Devaraj Das via omalley)
 
 138. HADOOP-1628.  Add block CRC protocol unit tests. (Raghu Angadi via omalley)
+
+139. HADOOP-1653. FSDirectory code-cleanups. FSDirectory.INode becomes a static
+     class.  (Christophe Taton via dhruba)
+
 
 Release 0.13.0 - 2007-06-08
 

Modified: lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/DFSFileInfo.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/DFSFileInfo.java?view=diff&rev=561245&r1=561244&r2=561245
==============================================================================
--- lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/DFSFileInfo.java (original)
+++ lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/DFSFileInfo.java Mon
Jul 30 23:50:00 2007
@@ -56,7 +56,7 @@
    * Create DFSFileInfo by file INode 
    */
   public DFSFileInfo(FSDirectory.INode node) {
-    this.path = new Path(node.computeName());
+    this.path = new Path(node.getAbsoluteName());
     this.isDir = node.isDir();
     this.len = isDir ? node.computeContentsLength() : node.computeFileLength();
     this.blockReplication = node.getReplication();

Modified: lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSDirectory.java?view=diff&rev=561245&r1=561244&r2=561245
==============================================================================
--- lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSDirectory.java Mon
Jul 30 23:50:00 2007
@@ -20,7 +20,6 @@
 import java.io.*;
 import java.util.*;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.dfs.FSConstants.StartupOption;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.metrics.MetricsRecord;
@@ -44,7 +43,8 @@
    * 
    * TODO: Factor out INode to a standalone class.
    ******************************************************/
-  class INode {
+  static class INode {
+
     private String name;
     private INode parent;
     private TreeMap<String, INode> children = null;
@@ -54,16 +54,6 @@
 
     /**
      */
-    INode(String name, Block blocks[], short replication) {
-      this.name = name;
-      this.parent = null;
-      this.blocks = blocks;
-      this.blockReplication = replication;
-      this.modificationTime = 0;
-    }
-
-    /**
-     */
     INode(String name) {
       this.name = name;
       this.parent = null;
@@ -113,12 +103,29 @@
     String getLocalName() {
       return name;
     }
-    
+
+    /**
+     * Get the full absolute path name of this file (recursively computed).
+     * 
+     * @return the string representation of the absolute path of this file
+     */
     String getAbsoluteName() {
-      // recursively constructs the absolute path.
-      // Any escaping of name required?
-      return ((parent != null) ? 
-              (parent.getAbsoluteName() + Path.SEPARATOR): "") + name;
+      return internalGetAbsolutePathName().toString();
+    }
+
+    /**
+     * Recursive computation of the absolute path name of this INode using a
+     * StringBuffer. This relies on the root INode name being "".
+     * 
+     * @return the StringBuffer containing the absolute path name.
+     */
+    private StringBuffer internalGetAbsolutePathName() {
+      if (parent == null) {
+        return new StringBuffer(name);
+      } else {
+        return parent.internalGetAbsolutePathName().append(
+            Path.SEPARATOR_CHAR).append(name);
+      }
     }
 
     /**
@@ -270,16 +277,16 @@
      * This operation is performed after a node is removed from the tree,
      * and we want to GC all the blocks at this node and below.
      */
-    void collectSubtreeBlocks(Vector<Block> v) {
+    void collectSubtreeBlocks(FSDirectory fsDir, Vector<Block> v) {
       if (blocks != null) {
         for (int i = 0; i < blocks.length; i++) {
           v.add(blocks[i]);
         }
       }
-      incrDeletedFileCount();
+      fsDir.incrDeletedFileCount();
       for (Iterator<INode> it = getChildIterator(); it != null &&
              it.hasNext();) {
-        it.next().collectSubtreeBlocks(v);
+        it.next().collectSubtreeBlocks(fsDir, v);
       }
     }
 
@@ -296,16 +303,6 @@
 
     /**
      */
-    String computeName() {
-      if (parent != null) {
-        return parent.computeName() + "/" + name;
-      } else {
-        return name;
-      }
-    }
-
-    /**
-     */
     long computeFileLength() {
       long total = 0;
       if (blocks != null) {
@@ -642,7 +639,7 @@
                                         +src+" is removed");
           targetNode.getParent().setModificationTime(modificationTime);
           Vector<Block> v = new Vector<Block>();
-          targetNode.collectSubtreeBlocks(v);
+          targetNode.collectSubtreeBlocks(this, v);
           for (Block b : v) {
             namesystem.blocksMap.removeINode(b);
           }

Modified: lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSEditLog.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSEditLog.java?view=diff&rev=561245&r1=561244&r2=561245
==============================================================================
--- lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSEditLog.java (original)
+++ lucene/hadoop/branches/branch-0.14/src/java/org/apache/hadoop/dfs/FSEditLog.java Mon Jul
30 23:50:00 2007
@@ -478,7 +478,7 @@
    */
   void logCreateFile(FSDirectory.INode newNode) {
     UTF8 nameReplicationPair[] = new UTF8[] { 
-      new UTF8(newNode.computeName()), 
+      new UTF8(newNode.getAbsoluteName()), 
       FSEditLog.toLogReplication(newNode.getReplication()),
       FSEditLog.toLogTimeStamp(newNode.getModificationTime())};
     logEdit(OP_ADD,
@@ -491,7 +491,7 @@
    */
   void logMkDir(FSDirectory.INode newNode) {
     UTF8 info[] = new UTF8[] {
-      new UTF8(newNode.computeName()),
+      new UTF8(newNode.getAbsoluteName()),
       FSEditLog.toLogTimeStamp(newNode.getModificationTime())
     };
     logEdit(OP_MKDIR, new ArrayWritable(UTF8.class, info), null);



Mime
View raw message