lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r635912 - in /lucene/java/branches/lucene_2_3: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 11 Mar 2008 13:03:55 GMT
Author: mikemccand
Date: Tue Mar 11 06:03:54 2008
New Revision: 635912

URL: http://svn.apache.org/viewvc?rev=635912&view=rev
Log:
LUCENE-1210 (porting to 2.3): fix deadlock case on hitting an exception while starting a merge
when using CMS

Modified:
    lucene/java/branches/lucene_2_3/CHANGES.txt
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/branches/lucene_2_3/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/CHANGES.txt?rev=635912&r1=635911&r2=635912&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_3/CHANGES.txt Tue Mar 11 06:03:54 2008
@@ -22,6 +22,9 @@
  6. LUCENE-1208: Fix deadlock case on hitting an exception while
     processing a document that had triggered a flush (Mike McCandless)
 
+ 7. LUCENE-1210: Fix deadlock case on hitting an exception while
+    starting a merge when using ConcurrentMergeScheduler (Mike McCandless)
+
 ======================= Release 2.3.1 2008-02-22 =======================
 
 Bug fixes

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java?rev=635912&r1=635911&r2=635912&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java Tue
Mar 11 06:03:54 2008
@@ -3037,8 +3037,23 @@
   }
 
   /** 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");
 
     assert merge.registerDone;
 

Modified: lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=635912&r1=635911&r2=635912&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
Tue Mar 11 06:03:54 2008
@@ -2904,7 +2904,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
     }
@@ -2912,4 +2912,46 @@
     w.close();
     dir.close();
   }    
+
+  public class MockIndexWriter2 extends IndexWriter {
+
+    public MockIndexWriter2(Directory dir, boolean autoCommit, Analyzer a, boolean create)
throws IOException {
+      super(dir, autoCommit, a, create);
+    }
+
+    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);
+    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