lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r494492 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexReader.java src/test/org/apache/lucene/index/TestIndexReader.java
Date Tue, 09 Jan 2007 17:14:06 GMT
Author: mikemccand
Date: Tue Jan  9 09:13:57 2007
New Revision: 494492

URL: http://svn.apache.org/viewvc?view=rev&rev=494492
Log:
LUCENE-768: make sure IndexReader.close releases write lock even after hitting an exception
in one of the methods that acquire the write lock

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=494492&r1=494491&r2=494492
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jan  9 09:13:57 2007
@@ -295,6 +295,11 @@
     in mergeSegments, when the corrupted segment is merged with
     segment(s) after it. (Mike McCandless)
 
+30. LUCENE-768: Fix case where an Exception during deleteDocument,
+    undeleteAll or setNorm in IndexReader could leave the reader in a
+    state where close() fails to release the write lock.
+    (Mike McCandless)
+
 Optimizations
 
   1. LUCENE-586: TermDocs.skipTo() is now more efficient for

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?view=diff&rev=494492&r1=494491&r2=494492
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Tue Jan  9 09:13:57
2007
@@ -425,8 +425,8 @@
           throws IOException{
     if(directoryOwner)
       aquireWriteLock();
-    doSetNorm(doc, field, value);
     hasChanges = true;
+    doSetNorm(doc, field, value);
   }
 
   /** Implements setNorm in subclass.*/
@@ -580,8 +580,8 @@
   public final synchronized void undeleteAll() throws IOException{
     if(directoryOwner)
       aquireWriteLock();
-    doUndeleteAll();
     hasChanges = true;
+    doUndeleteAll();
   }
 
   /** Implements actual undeleteAll() in subclass. */

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?view=diff&rev=494492&r1=494491&r2=494492
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Tue Jan  9 09:13:57
2007
@@ -788,7 +788,39 @@
         fail("delete of out-of-bounds doc number failed to hit exception");
       }
     }
-    
+
+    public void testExceptionReleaseWriteLockJIRA768() throws IOException {
+
+      Directory dir = new RAMDirectory();      
+      IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+      addDoc(writer, "aaa");
+      writer.close();
+
+      IndexReader reader = IndexReader.open(dir);
+      try {
+        reader.deleteDocument(1);
+        fail("did not hit exception when deleting an invalid doc number");
+      } catch (ArrayIndexOutOfBoundsException e) {
+        // expected
+      }
+      reader.close();
+      if (IndexReader.isLocked(dir)) {
+        fail("write lock is still held after close");
+      }
+
+      reader = IndexReader.open(dir);
+      try {
+        reader.setNorm(1, "content", (float) 2.0);
+        fail("did not hit exception when calling setNorm on an invalid doc number");
+      } catch (ArrayIndexOutOfBoundsException e) {
+        // expected
+      }
+      reader.close();
+      if (IndexReader.isLocked(dir)) {
+        fail("write lock is still held after close");
+      }
+    }
+
     private String arrayToString(String[] l) {
       String s = "";
       for(int i=0;i<l.length;i++) {



Mime
View raw message