You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/10/07 10:46:13 UTC

svn commit: r1005363 - in /lucene/dev/trunk/lucene: CHANGES.txt src/java/org/apache/lucene/store/NativeFSLockFactory.java

Author: mikemccand
Date: Thu Oct  7 08:46:12 2010
New Revision: 1005363

URL: http://svn.apache.org/viewvc?rev=1005363&view=rev
Log:
LUCENE-2689: don't attemp to acquire a test lock in NativeFSLockFactory

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

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1005363&r1=1005362&r2=1005363&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Oct  7 08:46:12 2010
@@ -382,6 +382,10 @@ Changes in runtime behavior
   usage, allowing applications to accidentally open two writers on the
   same directory.  (Mike McCandless)
 
+* LUCENE-2689: NativeFSLockFactory no longer attempts to acquire a
+  test lock just before the real lock is acquired.  (Surinder Pal
+  Singh Bindra via Mike McCandless)
+
 API Changes
 
 * LUCENE-2076: Rename FSDirectory.getFile -> getDirectory.  (George

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=1005363&r1=1005362&r2=1005363&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java Thu Oct  7 08:46:12 2010
@@ -17,14 +17,12 @@ package org.apache.lucene.store;
  * limitations under the License.
  */
 
-import java.lang.management.ManagementFactory;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.io.File;
 import java.io.RandomAccessFile;
 import java.io.IOException;
 import java.util.HashSet;
-import java.util.Random;
 
 /**
  * <p>Implements {@link LockFactory} using native OS file
@@ -58,54 +56,6 @@ import java.util.Random;
 
 public class NativeFSLockFactory extends FSLockFactory {
 
-  private volatile boolean tested = false;
-
-  // Simple test to verify locking system is "working".  On
-  // NFS, if it's misconfigured, you can hit long (35
-  // second) timeouts which cause Lock.obtain to take far
-  // too long (it assumes the obtain() call takes zero
-  // time). 
-  private synchronized void acquireTestLock() {
-    if (tested) return;
-    tested = true;
-    
-    // Ensure that lockDir exists and is a directory.
-    if (!lockDir.exists()) {
-      if (!lockDir.mkdirs())
-        throw new RuntimeException("Cannot create directory: " +
-                              lockDir.getAbsolutePath());
-    } else if (!lockDir.isDirectory()) {
-      throw new RuntimeException("Found regular file where directory expected: " + 
-                            lockDir.getAbsolutePath());
-    }
-
-    // add the RuntimeMXBean's name to the lock file, to reduce the chance for
-    // name collisions when this code is invoked by multiple JVMs (such as in
-    // our tests). On most systems, the name includes the process Id.
-    // Also, remove any non-alphanumeric characters, so that the lock file will
-    // be created for sure on all systems.
-    String randomLockName = "lucene-"
-        + ManagementFactory.getRuntimeMXBean().getName().replaceAll("[^a-zA-Z0-9]+","") + "-"
-        + Long.toString(new Random().nextInt(), Character.MAX_RADIX)
-        + "-test.lock";
-    
-    Lock l = makeLock(randomLockName);
-    try {
-      l.obtain();
-      l.release();
-      // If the test lock failed to delete after all the attempts, attempt a
-      // delete when the JVM exits.
-      File lockFile = new File(lockDir, randomLockName);
-      if (lockFile.exists()) {
-        lockFile.deleteOnExit();
-      }
-    } catch (IOException e) {
-      RuntimeException e2 = new RuntimeException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking");
-      e2.initCause(e);
-      throw e2;
-    }    
-  }
-
   /**
    * Create a NativeFSLockFactory instance, with null (unset)
    * lock directory. When you pass this factory to a {@link FSDirectory}
@@ -139,7 +89,6 @@ public class NativeFSLockFactory extends
 
   @Override
   public synchronized Lock makeLock(String lockName) {
-    acquireTestLock();
     if (lockPrefix != null)
       lockName = lockPrefix + "-" + lockName;
     return new NativeFSLock(lockDir, lockName);