lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r499089 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/java/org/apache/lucene/store/Directory.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 23 Jan 2007 17:33:13 GMT
Author: mikemccand
Date: Tue Jan 23 09:33:11 2007
New Revision: 499089

URL: http://svn.apache.org/viewvc?view=rev&rev=499089
Log:
LUCENE-773: fixed NPE caused by IndexWriter assuming LockFactory was non-null

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=499089&r1=499088&r2=499089
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jan 23 09:33:11 2007
@@ -193,6 +193,10 @@
 17. LUCENE-780: Add a static Directory.copy() method to copy files
     from one Directory to another.  (Jiri Kuhn via Mike McCandless)
 
+18. LUCENE-773: Added Directory.clearLock(String name) to forcefully
+    remove an old lock.  The default implementation is to ask the
+    lockFactory (if non null) to clear the lock.  (Mike McCandless)
+
 Bug fixes
 
  1. Fixed the web application demo (built with "ant war-demo") which

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=499089&r1=499088&r2=499089
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Tue Jan 23 09:33:11
2007
@@ -333,7 +333,7 @@
 
     if (create) {
       // Clear the write lock in case it's leftover:
-      directory.getLockFactory().clearLock(IndexWriter.WRITE_LOCK_NAME);
+      directory.clearLock(IndexWriter.WRITE_LOCK_NAME);
     }
 
     Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java?view=diff&rev=499089&r1=499088&r2=499089
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java Tue Jan 23 09:33:11
2007
@@ -88,6 +88,17 @@
   public Lock makeLock(String name) {
       return lockFactory.makeLock(name);
   }
+  /**
+   * Attempt to clear (forcefully unlock and remove) the
+   * specified lock.  Only call this at a time when you are
+   * certain this lock is no longer in use.
+   * @param lockName name of the lock to be cleared.
+   */
+  public void clearLock(String name) throws IOException {
+    if (lockFactory != null) {
+      lockFactory.clearLock(name);
+    }
+  }
 
   /** Closes the store. */
   public abstract void close()
@@ -106,8 +117,12 @@
       this.lockFactory = lockFactory;
       lockFactory.setLockPrefix(this.getLockID());
   }
+
   /**
-   * Get the LockFactory that this Directory instance is using for its locking implementation.
+   * Get the LockFactory that this Directory instance is
+   * using for its locking implementation.  Note that this
+   * may be null for Directory implementations that provide
+   * their own locking implementation.
    */
   public LockFactory getLockFactory() {
       return this.lockFactory;

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?view=diff&rev=499089&r1=499088&r2=499089
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Jan 23 09:33:11
2007
@@ -21,6 +21,9 @@
 import org.apache.lucene.store.IndexOutput;
 
 import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.LockFactory;
+import org.apache.lucene.store.Lock;
+import org.apache.lucene.store.SingleInstanceLockFactory;
 
 /**
  * @author goller
@@ -688,6 +691,43 @@
         if (reader != null) {
           reader.close();
         }
+    }
+
+    // Make sure that a Directory implementation that does
+    // not use LockFactory at all (ie overrides makeLock and
+    // implements its own private locking) works OK.  This
+    // was raised on java-dev as loss of backwards
+    // compatibility.
+    public void testNullLockFactory() throws IOException {
+
+      final class MyRAMDirectory extends RAMDirectory {
+        private LockFactory myLockFactory;
+        MyRAMDirectory() {
+          lockFactory = null;
+          myLockFactory = new SingleInstanceLockFactory();
+        }
+        public Lock makeLock(String name) {
+          return myLockFactory.makeLock(name);
+        }
+      }
+      
+      Directory dir = new MyRAMDirectory();
+      IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+      for (int i = 0; i < 100; i++) {
+        addDoc(writer);
+      }
+      writer.close();
+      IndexReader reader = IndexReader.open(dir);
+      Term searchTerm = new Term("content", "aaa");        
+      IndexSearcher searcher = new IndexSearcher(dir);
+      Hits hits = searcher.search(new TermQuery(searchTerm));
+      assertEquals("did not get right number of hits", 100, hits.length());
+      writer.close();
+
+      writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+      writer.close();
+
+      dir.close();
     }
 
     private void rmDir(File dir) {



Mime
View raw message