lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r635190 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Sun, 09 Mar 2008 08:19:01 GMT
Author: mikemccand
Date: Sun Mar  9 00:19:00 2008
New Revision: 635190

URL: http://svn.apache.org/viewvc?rev=635190&view=rev
Log:
LUCENE-1210: fix deadlock case on hitting exception in mergeInit

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

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?rev=635190&r1=635189&r2=635190&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Sun Mar  9 00:19:00
2008
@@ -3588,8 +3588,21 @@
   }
 
   /** Does initial setup for a merge, which is fast but holds
-   *  the synchronized lock on IndexWriter instance. */
+   *  the synchronized lock on IndexWriter instance.  */
   final synchronized void mergeInit(MergePolicy.OneMerge merge) throws IOException {
+    boolean success = false;
+    try {
+      _mergeInit(merge);
+      success = true;
+    } finally {
+      if (!success) {
+        mergeFinish(merge);
+        runningMerges.remove(merge);
+      }
+    }
+  }
+
+  final synchronized private void _mergeInit(MergePolicy.OneMerge merge) throws IOException
{
 
     assert testPoint("startMergeInit");
 

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?rev=635190&r1=635189&r2=635190&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Sun Mar  9 00:19:00
2008
@@ -3181,7 +3181,7 @@
                            Field.Index.TOKENIZED));
     try {
       w.addDocument(crashDoc, analyzer);
-      fail("did not hit exxpected exception");
+      fail("did not hit expected exception");
     } catch (IOException ioe) {
       // expected
     }
@@ -3189,4 +3189,46 @@
     w.close();
     dir.close();
   }    
+
+  public class MockIndexWriter2 extends IndexWriter {
+
+    public MockIndexWriter2(Directory dir, boolean autoCommit, Analyzer a, boolean create,
MaxFieldLength mfl) throws IOException {
+      super(dir, autoCommit, a, create, mfl);
+    }
+
+    boolean doFail;
+    boolean failed;
+
+    boolean testPoint(String name) {
+      if (doFail && name.equals("startMergeInit")) {
+        failed = true;
+        throw new RuntimeException("intentionally failing");
+      }
+      return true;
+    }
+  }
+
+  // LUCENE-1210
+  public void testExceptionOnMergeInit() throws IOException {
+    MockRAMDirectory dir = new MockRAMDirectory();
+    MockIndexWriter2 w = new MockIndexWriter2(dir, false, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.UNLIMITED);
+    w.setMaxBufferedDocs(2);
+    w.setMergeFactor(2);
+    w.doFail = true;
+    w.setMergeScheduler(new ConcurrentMergeScheduler());
+    Document doc = new Document();
+    doc.add(new Field("field", "a field", Field.Store.YES,
+                      Field.Index.TOKENIZED));
+    for(int i=0;i<10;i++)
+      try {
+        w.addDocument(doc);
+      } catch (RuntimeException re) {
+        break;
+      }
+
+    ((ConcurrentMergeScheduler) w.getMergeScheduler()).sync();
+    assertTrue(w.failed);
+    w.close();
+    dir.close();
+  }
 }



Mime
View raw message