lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r495760 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/store/ src/test/org/apache/lucene/store/
Date Fri, 12 Jan 2007 22:09:45 GMT
Author: mikemccand
Date: Fri Jan 12 14:09:45 2007
New Revision: 495760

URL: http://svn.apache.org/viewvc?view=rev&rev=495760
Log:
LUCENE-771:

  * Default write lock location to the index directory and use the
    name "write.lock" (without prefix).

  * Make the LockFactory.clearAllLocks() method package protected.

  * Remove LOCK_DIR and no-argument constructors for
    SimpleFSLockFactory and NativeFSLockFactory (no more global lock
    directory).

  * Deprecate FSDirectory.LOCK_DIR

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java
    lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
    lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.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?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Jan 12 14:09:45 2007
@@ -46,6 +46,13 @@
     that has since been fixed, plus we no longer support pre-1.4.2 JVMs.
     (Otis Gospodnetic)
 
+ 9. LUCENE-771: The default location of the write lock is now the
+    index directory, and is named simply "write.lock" (without a big
+    digest prefix).  The system properties "org.apache.lucene.lockDir"
+    nor "java.io.tmpdir" are no longer used as the global directory
+    for storing lock files, and the LOCK_DIR field of FSDirectory is
+    now deprecated.  (Mike McCandless)
+
 New features
 
  1. LUCENE-503: New ThaiAnalyzer and ThaiWordFilter in contrib/analyzers

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Fri Jan 12 14:09:45
2007
@@ -28,6 +28,9 @@
 
 import org.apache.lucene.index.IndexFileNameFilter;
 
+// Used only for WRITE_LOCK_NAME:
+import org.apache.lucene.index.IndexWriter;
+
 /**
  * Straightforward implementation of {@link Directory} as a directory of files.
  * Locking implementation is by default the {@link SimpleFSLockFactory}, but
@@ -73,17 +76,23 @@
     return FSDirectory.disableLocks;
   }
 
-  // TODO: LOCK_DIR really should only appear in the SimpleFSLockFactory
-  // (and any other file-system based locking implementations).  When we
-  // can next break backwards compatibility we should deprecate it and then
-  // move it.
-
   /**
    * Directory specified by <code>org.apache.lucene.lockDir</code>
-   * or <code>java.io.tmpdir</code> system property.  This may be deprecated
in the future.  Please use
-   * {@link SimpleFSLockFactory#LOCK_DIR} instead.
+   * or <code>java.io.tmpdir</code> system property.
+
+   * @deprecated As of 2.1, <code>LOCK_DIR</code> is unused
+   * because the write.lock is now stored by default in the
+   * index directory.  If you really want to store locks
+   * elsewhere you can create your own {@link
+   * SimpleFSLockFactory} (or {@link NativeFSLockFactory},
+   * etc.) passing in your preferred lock directory.  Then,
+   * pass this <code>LockFactory</code> instance to one of
+   * the <code>getDirectory</code> methods that take a
+   * <code>lockFactory</code> (for example, {@link
+   * #getDirectory(String, boolean, LockFactory)}).
    */
-  public static final String LOCK_DIR = SimpleFSLockFactory.LOCK_DIR;
+  public static final String LOCK_DIR = System.getProperty("org.apache.lucene.lockDir",
+                                                           System.getProperty("java.io.tmpdir"));
 
   /** The default class which implements filesystem-based directories. */
   private static Class IMPL;
@@ -250,6 +259,8 @@
     // system property org.apache.lucene.store.FSDirectoryLockFactoryClass is set,
     // instantiate that; else, use SimpleFSLockFactory:
 
+    boolean doClearLockID = false;
+
     if (lockFactory == null) {
 
       if (disableLocks) {
@@ -258,7 +269,7 @@
       } else {
         String lockClassName = System.getProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass");
 
-        if (lockClassName != null) {
+        if (lockClassName != null && !lockClassName.equals("")) {
           Class c;
 
           try {
@@ -277,14 +288,10 @@
             throw new IOException("unable to cast LockClass " + lockClassName + " instance
to a LockFactory");
           }
         } else {
-          // Our default lock is SimpleFSLockFactory:
-          File lockDir;
-          if (LOCK_DIR == null) {
-            lockDir = directory;
-          } else {
-            lockDir = new File(LOCK_DIR);
-          }
-          lockFactory = new SimpleFSLockFactory(lockDir);
+          // Our default lock is SimpleFSLockFactory;
+          // default lockDir is our index directory:
+          lockFactory = new SimpleFSLockFactory(path);
+          doClearLockID = true;
         }
       }
     }
@@ -297,6 +304,11 @@
     directory = path;
 
     setLockFactory(lockFactory);
+    if (doClearLockID) {
+      // Clear the prefix because write.lock will be
+      // stored in our directory:
+      lockFactory.setLockPrefix(null);
+    }
 
     init(path, create, doRemoveOldFiles);
   }
@@ -320,7 +332,15 @@
       }
     }
 
-    lockFactory.clearAllLocks();
+    if (lockFactory.getLockPrefix() != null) {
+      lockFactory.clearAllLocks();
+    } else {
+      // Lock file is stored in the index, so we just remove
+      // it ourselves here:
+      File lockFile = new File(directory, IndexWriter.WRITE_LOCK_NAME);
+      if (lockFile.exists() && !lockFile.delete())
+        throw new IOException("Cannot delete " + lockFile);
+    }
   }
 
   /** Returns an array of strings, one for each Lucene index file in the directory. */

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java Fri Jan 12 14:09:45
2007
@@ -60,5 +60,5 @@
    * are certain the lock files are not in use. {@link FSDirectory}
    * calls this when creating a new index.
    */
-  public abstract void clearAllLocks() throws IOException;
+  abstract void clearAllLocks() throws IOException;
 }

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?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java Fri Jan 12
14:09:45 2007
@@ -67,10 +67,6 @@
    * system property is used.
    */
 
-  public static final String LOCK_DIR =
-    System.getProperty("org.apache.lucene.lockDir",
-                       System.getProperty("java.io.tmpdir"));
-
   private File lockDir;
 
   // Simple test to verify locking system is "working".  On
@@ -96,17 +92,6 @@
 
   /**
    * Create a NativeFSLockFactory instance, storing lock
-   * files into the default LOCK_DIR:
-   * <code>org.apache.lucene.lockDir</code> system property,
-   * or (if that is null) then the
-   * <code>java.io.tmpdir</code> system property.
-   */
-  public NativeFSLockFactory() throws IOException {
-    this(new File(LOCK_DIR));
-  }
-
-  /**
-   * Create a NativeFSLockFactory instance, storing lock
    * files into the specified lockDirName:
    *
    * @param lockDirName where lock files are created.
@@ -139,22 +124,17 @@
   }
 
   public synchronized Lock makeLock(String lockName) {
-    String fullName;
-    if (lockPrefix.equals("")) {
-      fullName = lockName;
-    } else {
-      fullName = lockPrefix + "-n-" + lockName;
-    }
-
-    return new NativeFSLock(lockDir, fullName);
+    if (lockPrefix != null)
+      lockName = lockPrefix + "-n-" + lockName;
+    return new NativeFSLock(lockDir, lockName);
   }
 
-  public void clearAllLocks() throws IOException {
+  protected void clearAllLocks() throws IOException {
     // Note that this isn't strictly required anymore
     // because the existence of these files does not mean
     // they are locked, but, still do this in case people
     // really want to see the files go away:
-    if (lockDir.exists()) {
+    if (lockDir.exists() && lockPrefix != null) {
         String[] files = lockDir.list();
         if (files == null)
           throw new IOException("Cannot read lock directory " +

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java Fri Jan 12
14:09:45 2007
@@ -38,22 +38,9 @@
    * system property is used.
    */
 
-  public static final String LOCK_DIR =
-    System.getProperty("org.apache.lucene.lockDir",
-                       System.getProperty("java.io.tmpdir"));
-
   private File lockDir;
 
   /**
-   * Instantiate using default LOCK_DIR: <code>org.apache.lucene.lockDir</code>
-   * system property, or (if that is null) then <code>java.io.tmpdir</code>.
-   */
-  public SimpleFSLockFactory() throws IOException {
-    lockDir = new File(LOCK_DIR);
-    init(lockDir);
-  }
-
-  /**
    * Instantiate using the provided directory (as a File instance).
    * @param lockDir where lock files should be created.
    */
@@ -71,17 +58,18 @@
   }
 
   protected void init(File lockDir) throws IOException {
-
     this.lockDir = lockDir;
-
   }
 
   public Lock makeLock(String lockName) {
-    return new SimpleFSLock(lockDir, lockPrefix + "-" + lockName);
+    if (lockPrefix != null) {
+      lockName = lockPrefix + "-" + lockName;
+    }
+    return new SimpleFSLock(lockDir, lockName);
   }
 
-  public void clearAllLocks() throws IOException {
-    if (lockDir.exists()) {
+  protected void clearAllLocks() throws IOException {
+    if (lockDir.exists() && lockPrefix != null) {
         String[] files = lockDir.list();
         if (files == null)
           throw new IOException("Cannot read lock directory " +

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?view=diff&rev=495760&r1=495759&r2=495760
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Fri Jan 12 14:09:45
2007
@@ -210,8 +210,8 @@
                    NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
 
         // Put back to the correct default for subsequent tests:
-        System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass",
-                           "org.apache.lucene.store.SimpleFSLockFactory");
+        // System.clearProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass");
+        System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass", "");
 
         writer.close();
         // Cleanup
@@ -292,7 +292,7 @@
     // no unexpected exceptions are raised, but use
     // NativeFSLockFactory:
     public void testStressLocksNativeFSLockFactory() throws IOException {
-      _testStressLocks(new NativeFSLockFactory(), "index.TestLockFactory7");
+      _testStressLocks(new NativeFSLockFactory("index.TestLockFactory7"), "index.TestLockFactory7");
     }
 
     public void _testStressLocks(LockFactory lockFactory, String indexDirName) throws IOException
{
@@ -325,9 +325,9 @@
     // Verify: NativeFSLockFactory works correctly
     public void testNativeFSLockFactory() throws IOException {
 
-      NativeFSLockFactory f = new NativeFSLockFactory();
+      NativeFSLockFactory f = new NativeFSLockFactory(System.getProperty("tempDir"));
 
-      NativeFSLockFactory f2 = new NativeFSLockFactory();
+      NativeFSLockFactory f2 = new NativeFSLockFactory(System.getProperty("tempDir"));
 
       f.setLockPrefix("test");
       Lock l = f.makeLock("commit");
@@ -350,8 +350,8 @@
     public void testNativeFSLockFactoryPrefix() throws IOException {
 
       // Make sure we get identical instances:
-      Directory dir1 = FSDirectory.getDirectory("TestLockFactory.8", true, new NativeFSLockFactory());
-      Directory dir2 = FSDirectory.getDirectory("TestLockFactory.9", true, new NativeFSLockFactory());
+      Directory dir1 = FSDirectory.getDirectory("TestLockFactory.8", true, new NativeFSLockFactory("TestLockFactory.8"));
+      Directory dir2 = FSDirectory.getDirectory("TestLockFactory.9", true, new NativeFSLockFactory("TestLockFactory.9"));
 
       String prefix1 = dir1.getLockFactory().getLockPrefix();
       String prefix2 = dir2.getLockFactory().getLockPrefix();
@@ -362,20 +362,18 @@
       rmDir("TestLockFactory.9");
     }
 
-    // Verify: default LockFactory assigns different lock prefixes:
+    // Verify: default LockFactory has no prefix (ie
+    // write.lock is stored in index):
     public void testDefaultFSLockFactoryPrefix() throws IOException {
 
       // Make sure we get identical instances:
-      Directory dir1 = FSDirectory.getDirectory("TestLockFactory.10", true);
-      Directory dir2 = FSDirectory.getDirectory("TestLockFactory.11", true);
+      Directory dir = FSDirectory.getDirectory("TestLockFactory.10", true);
 
-      String prefix1 = dir1.getLockFactory().getLockPrefix();
-      String prefix2 = dir2.getLockFactory().getLockPrefix();
+      String prefix = dir.getLockFactory().getLockPrefix();
+
+      assertTrue("Default lock prefix should be null", null == prefix);
 
-      assertTrue("Default Lock Factories are incorrectly shared: dir1 and dir2 have same
lock prefix '" + prefix1 + "'; they should be different",
-                 !prefix1.equals(prefix2));
       rmDir("TestLockFactory.10");
-      rmDir("TestLockFactory.11");
     }
 
     private class WriterThread extends Thread { 



Mime
View raw message