hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r395003 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/LocalFileSystem.java
Date Tue, 18 Apr 2006 19:17:49 GMT
Author: cutting
Date: Tue Apr 18 12:17:47 2006
New Revision: 395003

URL: http://svn.apache.org/viewcvs?rev=395003&view=rev
Log:
Fix for HADOOP-139.  Fix a potential deadlock in LocalFileSystem.lock().  Contributed by Igor
Bolotin.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/CHANGES.txt?rev=395003&r1=395002&r2=395003&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Apr 18 12:17:47 2006
@@ -46,6 +46,9 @@
 12. Fix HADOOP-138.  Stop multiple tasks in a single heartbeat, rather
     than one per heartbeat.  (Stefan via cutting)
 
+13. Fix HADOOP-139.  Remove a potential deadlock in
+    LocalFileSystem.lock().  (Igor Bolotin via cutting)
+
 
 Release 0.1.1 - 2006-04-08
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java?rev=395003&r1=395002&r2=395003&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java Tue Apr 18 12:17:47
2006
@@ -224,45 +224,54 @@
       return workingDir;
     }
     
-    public synchronized void lock(Path p, boolean shared) throws IOException {
-        File f = pathToFile(p);
-        f.createNewFile();
+    public void lock(Path p, boolean shared) throws IOException {
+      File f = pathToFile(p);
+      f.createNewFile();
 
-        FileLock lockObj = null;
-        if (shared) {
-            FileInputStream lockData = new FileInputStream(f);
-            lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared);
-            sharedLockDataSet.put(f, lockData);
-        } else {
-            FileOutputStream lockData = new FileOutputStream(f);
-            lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared);
-            nonsharedLockDataSet.put(f, lockData);
+      if (shared) {
+        FileInputStream lockData = new FileInputStream(f);
+        FileLock lockObj =
+          lockData.getChannel().lock(0L, Long.MAX_VALUE, shared);
+        synchronized (this) {
+          sharedLockDataSet.put(f, lockData);
+          lockObjSet.put(f, lockObj);
         }
-        lockObjSet.put(f, lockObj);
+      } else {
+        FileOutputStream lockData = new FileOutputStream(f);
+        FileLock lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared);
+        synchronized (this) {
+          nonsharedLockDataSet.put(f, lockData);
+          lockObjSet.put(f, lockObj);
+        }
+      }
     }
 
-    public synchronized void release(Path p) throws IOException {
-        File f = pathToFile(p);
-        FileLock lockObj = (FileLock) lockObjSet.get(f);
-        FileInputStream sharedLockData = (FileInputStream) sharedLockDataSet.get(f);
-        FileOutputStream nonsharedLockData = (FileOutputStream) nonsharedLockDataSet.get(f);
+    public void release(Path p) throws IOException {
+      File f = pathToFile(p);
 
-        if (lockObj == null) {
-            throw new IOException("Given target not held as lock");
-        }
-        if (sharedLockData == null && nonsharedLockData == null) {
-            throw new IOException("Given target not held as lock");
-        }
+      FileLock lockObj;
+      FileInputStream sharedLockData;
+      FileOutputStream nonsharedLockData;
+      synchronized (this) {
+        lockObj = (FileLock) lockObjSet.remove(f);
+        sharedLockData = (FileInputStream) sharedLockDataSet.remove(f);
+        nonsharedLockData = (FileOutputStream) nonsharedLockDataSet.remove(f);
+      }
+ 
+      if (lockObj == null) {
+        throw new IOException("Given target not held as lock");
+      }
+      if (sharedLockData == null && nonsharedLockData == null) {
+        throw new IOException("Given target not held as lock");
+      }
 
-        lockObj.release();
-        lockObjSet.remove(f);
-        if (sharedLockData != null) {
-            sharedLockData.close();
-            sharedLockDataSet.remove(f);
-        } else {
-            nonsharedLockData.close();
-            nonsharedLockDataSet.remove(f);
-        }
+      lockObj.release();
+
+      if (sharedLockData != null) {
+        sharedLockData.close();
+      } else {
+        nonsharedLockData.close();
+      }
     }
 
     // In the case of the local filesystem, we can just rename the file.



Mime
View raw message