hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r443455 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/FSConstants.java src/java/org/apache/hadoop/dfs/NameNode.java src/java/org/apache/hadoop/fs/Path.java
Date Thu, 14 Sep 2006 20:16:20 GMT
Author: cutting
Date: Thu Sep 14 13:16:19 2006
New Revision: 443455

URL: http://svn.apache.org/viewvc?view=rev&rev=443455
Log:
HADOOP-438.  Limit the length of paths permitted by DFS.  Contributed by Wendy.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSConstants.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=443455&r1=443454&r2=443455
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Thu Sep 14 13:16:19 2006
@@ -7,6 +7,10 @@
    so that things are not shown to be 100% complete until they are in
    fact finished.  (omalley via cutting) 
 
+2. HADOOP-438.  Limit the length of absolute paths in DFS, since the
+   file format used to store pathnames has some limitations.
+   (Wendy Chien via cutting)
+
 
 Release 0.6.1 - 2006-08-13
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSConstants.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSConstants.java?view=diff&rev=443455&r1=443454&r2=443455
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSConstants.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSConstants.java Thu Sep 14 13:16:19
2006
@@ -106,6 +106,11 @@
     public static long LEASE_PERIOD = 60 * 1000;
     public static int READ_TIMEOUT = 60 * 1000;
 
+    // We need to limit the length and depth of a path in the filesystem.  HADOOP-438
+    // Currently we set the maximum length to 8k characters and the maximum depth to 1k.
 
+    public static int MAX_PATH_LENGTH = 8000;
+    public static int MAX_PATH_DEPTH = 1000;
+    
     //TODO mb@media-style.com: should be conf injected?
     public static final int BUFFER_SIZE = new Configuration().getInt("io.file.buffer.size",
4096);
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?view=diff&rev=443455&r1=443454&r2=443455
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Thu Sep 14 13:16:19 2006
@@ -17,6 +17,7 @@
 
 import org.apache.commons.logging.*;
 
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.*;
 import org.apache.hadoop.ipc.*;
 import org.apache.hadoop.conf.*;
@@ -199,6 +200,10 @@
     ) throws IOException {
        stateChangeLog.debug("*DIR* NameNode.create: file "
             +src+" for "+clientName+" at "+clientMachine);
+       if (!checkPathLength(src)) {
+           throw new IOException("create: Pathname too long.  Limit " 
+               + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
+       }
        Object results[] = namesystem.startFile(new UTF8(src), 
                                                 new UTF8(clientName), 
                                                 new UTF8(clientMachine), 
@@ -304,6 +309,10 @@
      */
     public boolean rename(String src, String dst) throws IOException {
         stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst );
+        if (!checkPathLength(dst)) {
+            throw new IOException("rename: Pathname too long.  Limit " 
+                + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
+        }
         boolean ret = namesystem.renameTo(new UTF8(src), new UTF8(dst));
         if (ret) {
             myMetrics.renameFile();
@@ -331,9 +340,25 @@
     }
 
     /**
+     * Check path length does not exceed maximum.  Returns true if
+     * length and depth are okay.  Returns false if length is too long 
+     * or depth is too great.
+     * 
+     */
+    private boolean checkPathLength(String src) {
+        Path srcPath = new Path(src);
+        return (src.length() <= MAX_PATH_LENGTH &&
+                srcPath.depth() <= MAX_PATH_DEPTH);
+    }
+    
+    /**
      */
     public boolean mkdirs(String src) throws IOException {
         stateChangeLog.debug("*DIR* NameNode.mkdirs: " + src );
+        if (!checkPathLength(src)) {
+            throw new IOException("mkdirs: Pathname too long.  Limit " 
+                + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
+        }
         return namesystem.mkdirs(new UTF8(src));
     }
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java?view=diff&rev=443455&r1=443454&r2=443455
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java Thu Sep 14 13:16:19 2006
@@ -174,5 +174,11 @@
     Path that = (Path)o;
     return this.toString().compareTo(that.toString());
   }
+  
+  /** Return the number of elements in this path. */
+  public int depth() {
+    return elements.length;
+  }
 
 }
+



Mime
View raw message