lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r891205 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/NativeFSLockFactory.java src/test/org/apache/lucene/store/TestLockFactory.java
Date Wed, 16 Dec 2009 12:01:46 GMT
Author: uschindler
Date: Wed Dec 16 12:01:45 2009
New Revision: 891205

URL: http://svn.apache.org/viewvc?rev=891205&view=rev
Log:
LUCENE-2104: Fix NativeFSLock.release() to throw exception if lock is held by another thread/process.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=891205&r1=891204&r2=891205&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Dec 16 12:01:45 2009
@@ -56,6 +56,9 @@
 
 * LUCENE-2166: Don't incorrectly keep warning about the same immense
   term, when IndexWriter.infoStream is on.  (Mike McCandless)
+
+* LUCENE-2104: NativeFSLock.release() would silently fail if the lock is held by 
+  another thread/process.  (Shai Erera via Uwe Schindler)
   
 New features
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=891205&r1=891204&r2=891205&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java Wed Dec 16
12:01:45 2009
@@ -146,7 +146,7 @@
       }
     }
   }
-};
+}
 
 class NativeFSLock extends Lock {
 
@@ -300,6 +300,24 @@
       }
       if (!path.delete())
         throw new LockReleaseFailedException("failed to delete " + path);
+    } else {
+      // if we don't hold the lock, and somebody still called release(), for
+      // example as a result of calling IndexWriter.unlock(), we should attempt
+      // to obtain the lock and release it. If the obtain fails, it means the
+      // lock cannot be released, and we should throw a proper exception rather
+      // than silently failing/not doing anything.
+      boolean obtained = false;
+      try {
+        if (!(obtained = obtain())) {
+          throw new LockReleaseFailedException(
+              "Cannot forcefully unlock a NativeFSLock which is held by another indexer component:
"
+                  + path);
+        }
+      } finally {
+        if (obtained) {
+          release();
+        }
+      }
     }
   }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?rev=891205&r1=891204&r2=891205&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Wed Dec 16 12:01:45
2009
@@ -198,6 +198,26 @@
       assertFalse(l2.isLocked());
     }
 
+    public void testNativeFSLockReleaseByOtherLock() throws IOException {
+
+      NativeFSLockFactory f = new NativeFSLockFactory(System.getProperty("tempDir"));
+
+      f.setLockPrefix("test");
+      Lock l = f.makeLock("commit");
+      Lock l2 = f.makeLock("commit");
+
+      assertTrue("failed to obtain lock", l.obtain());
+      try {
+        assertTrue(l2.isLocked());
+        l2.release();
+        fail("should not have reached here. LockReleaseFailedException should have been thrown");
+      } catch (IOException e) {
+        assertTrue("Unexpected exception", e instanceof LockReleaseFailedException);
+      } finally {
+        l.release();
+      }
+    }
+
     // Verify: NativeFSLockFactory assigns null as lockPrefix if the lockDir is inside directory
     public void testNativeFSLockFactoryPrefix() throws IOException {
 



Mime
View raw message