lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r634831 - in /lucene/java/trunk/src: java/org/apache/lucene/index/DocumentsWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Fri, 07 Mar 2008 21:47:17 GMT
Author: mikemccand
Date: Fri Mar  7 13:47:15 2008
New Revision: 634831

URL: http://svn.apache.org/viewvc?rev=634831&view=rev
Log:
LUCENE-1208: if exception is hit after marking flushPending but before flushing, clear flushPending
to prevent deadlock

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

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=634831&r1=634830&r2=634831&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java Fri Mar  7 13:47:15
2008
@@ -2615,6 +2615,15 @@
       } finally {
         if (!success) {
           synchronized(this) {
+
+            // If this thread state had decided to flush, we
+            // must clear it so another thread can flush
+            if (state.doFlushAfter) {
+              state.doFlushAfter = false;
+              flushPending = false;
+              notifyAll();
+            }
+
             // Immediately mark this document as deleted
             // since likely it was partially added.  This
             // keeps indexing as "all or none" (atomic) when

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=634831&r1=634830&r2=634831&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 Fri Mar  7 13:47:15
2008
@@ -3159,4 +3159,34 @@
     _TestUtil.checkIndex(dir);
     dir.close();
   }
+
+  // LUCENE-1208
+  public void testExceptionJustBeforeFlush() throws IOException {
+    MockRAMDirectory dir = new MockRAMDirectory();
+    MockIndexWriter w = new MockIndexWriter(dir, false, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
+    w.setMaxBufferedDocs(2);
+    Document doc = new Document();
+    doc.add(new Field("field", "a field", Field.Store.YES,
+                      Field.Index.TOKENIZED));
+    w.addDocument(doc);
+
+    Analyzer analyzer = new Analyzer() {
+      public TokenStream tokenStream(String fieldName, Reader reader) {
+        return new CrashingFilter(fieldName, new WhitespaceTokenizer(reader));
+      }
+    };
+
+    Document crashDoc = new Document();
+    crashDoc.add(new Field("crash", "do it on token 4", Field.Store.YES,
+                           Field.Index.TOKENIZED));
+    try {
+      w.addDocument(crashDoc, analyzer);
+      fail("did not hit exxpected exception");
+    } catch (IOException ioe) {
+      // expected
+    }
+    w.addDocument(doc);
+    w.close();
+    dir.close();
+  }    
 }



Mime
View raw message