Selaa lähdekoodia

HADOOP-1167. Remove extra synchronization in InMemoryFileSystem. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@524185 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 vuotta sitten
vanhempi
commit
bc8b87b3f5
2 muutettua tiedostoa jossa 8 lisäystä ja 7 poistoa
  1. 3 0
      CHANGES.txt
  2. 5 7
      src/java/org/apache/hadoop/fs/InMemoryFileSystem.java

+ 3 - 0
CHANGES.txt

@@ -64,6 +64,9 @@ Trunk (unreleased changes)
 19. HADOOP-1169.  Fix a cut/paste error in CopyFiles utility so that
     S3-based source files are correctly copied.  (Michael Stack via cutting)
 
+20. HADOOP-1167.  Remove extra synchronization in InMemoryFileSystem.
+    (omalley via cutting)
+
 
 Release 0.12.3 (not yet released)
 

+ 5 - 7
src/java/org/apache/hadoop/fs/InMemoryFileSystem.java

@@ -44,15 +44,13 @@ public class InMemoryFileSystem extends ChecksumFileSystem {
   private Path staticWorkingDir;
   
   //pathToFileAttribs is the final place where a file is put after it is closed
-  private Map <String, FileAttributes> pathToFileAttribs = 
-    Collections.synchronizedMap(new HashMap());
+  private Map <String, FileAttributes> pathToFileAttribs = new HashMap();
   
   //tempFileAttribs is a temp place which is updated while reserving memory for
   //files we are going to create. It is read in the createRaw method and the
   //temp key/value is discarded. If the file makes it to "close", then it
   //ends up being in the pathToFileAttribs map.
-  private Map <String, FileAttributes> tempFileAttribs = 
-    Collections.synchronizedMap(new HashMap());
+  private Map <String, FileAttributes> tempFileAttribs = new HashMap();
   
   public RawInMemoryFileSystem() {
     setConf(new Configuration());
@@ -193,10 +191,10 @@ public class InMemoryFileSystem extends ChecksumFileSystem {
   public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize,
       short replication, long blockSize, Progressable progress)
       throws IOException {
-    if (exists(f) && ! overwrite) {
-      throw new IOException("File already exists:"+f);
-    }
     synchronized (this) {
+      if (exists(f) && ! overwrite) {
+        throw new IOException("File already exists:"+f);
+      }
       FileAttributes fAttr =(FileAttributes) tempFileAttribs.remove(getPath(f));
       if (fAttr != null)
         return create(f, fAttr);