فهرست منبع

HADOOP-277. Fix a race condition when creating directories.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@412496 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 سال پیش
والد
کامیت
c04b1fb6b8
3فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 3 0
      CHANGES.txt
  2. 2 1
      src/java/org/apache/hadoop/fs/FileSystem.java
  3. 10 3
      src/java/org/apache/hadoop/fs/LocalFileSystem.java

+ 3 - 0
CHANGES.txt

@@ -20,6 +20,9 @@ Trunk (unreleased changes)
  5. HADOOP-285.  Fix DFS datanodes to be able to re-join the cluster
     after the connection to the namenode is lost.  (omalley via cutting)
 
+ 6. HADOOP-277.  Fix a race condition when creating directories.
+   (Sameer Paranjpye via cutting)
+
 
 Release 0.3.1 - 2006-06-05
 

+ 2 - 1
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -459,7 +459,8 @@ public abstract class FileSystem extends Configured {
 
     /**
      * Make the given file and all non-existent parents into
-     * directories.
+     * directories. Has the semantics of Unix 'mkdir -p'.
+     * Existence of the directory hierarchy is not an error.
      */
     public abstract boolean mkdirs(Path f) throws IOException;
 

+ 10 - 3
src/java/org/apache/hadoop/fs/LocalFileSystem.java

@@ -223,11 +223,18 @@ public class LocalFileSystem extends FileSystem {
         }
         return results;
     }
-
+    
+    /**
+     * Creates the specified directory hierarchy. Does not
+     * treat existence as an error.
+     */
     public boolean mkdirs(Path f) throws IOException {
-      return pathToFile(f).mkdirs();
+      Path parent = f.getParent();
+      File p2f = pathToFile(f);
+      return (parent == null || mkdirs(parent)) &&
+             (p2f.mkdir() || p2f.isDirectory());
     }
-
+    
     /**
      * Set the working directory to the given directory.
      */