lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r632871 - in /lucene/java/trunk/src: java/org/apache/lucene/index/DocumentsWriter.java java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java test/org/apache/lucene/util/_TestUtil.java
Date Sun, 02 Mar 2008 23:24:08 GMT
Author: mikemccand
Date: Sun Mar  2 15:24:07 2008
New Revision: 632871

URL: http://svn.apache.org/viewvc?rev=632871&view=rev
Log:
LUCENE-1198: don't increment numDocsInRAM unless DocumentsWriter.ThreadState.init succeeds

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.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=632871&r1=632870&r2=632871&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 Sun Mar  2 15:24:07
2008
@@ -722,6 +722,7 @@
     void init(Document doc, int docID) throws IOException, AbortException {
 
       assert !isIdle;
+      assert writer.testPoint("DocumentsWriter.ThreadState.init start");
 
       this.docID = docID;
       docBoost = doc.getBoost();
@@ -2440,18 +2441,6 @@
     if (segment == null)
       segment = writer.newSegmentName();
 
-    numDocsInRAM++;
-
-    // We must at this point commit to flushing to ensure we
-    // always get N docs when we flush by doc count, even if
-    // > 1 thread is adding documents:
-    if (!flushPending && maxBufferedDocs != IndexWriter.DISABLE_AUTO_FLUSH
-        && numDocsInRAM >= maxBufferedDocs) {
-      flushPending = true;
-      state.doFlushAfter = true;
-    } else
-      state.doFlushAfter = false;
-
     state.isIdle = false;
 
     try {
@@ -2460,11 +2449,21 @@
         state.init(doc, nextDocID);
         if (delTerm != null) {
           addDeleteTerm(delTerm, state.docID);
-          if (!state.doFlushAfter)
-            state.doFlushAfter = timeToFlushDeletes();
+          state.doFlushAfter = timeToFlushDeletes();
         }
-        // Only increment nextDocID on successful init
+        // Only increment nextDocID & numDocsInRAM on successful init
         nextDocID++;
+        numDocsInRAM++;
+
+        // We must at this point commit to flushing to ensure we
+        // always get N docs when we flush by doc count, even if
+        // > 1 thread is adding documents:
+        if (!flushPending && maxBufferedDocs != IndexWriter.DISABLE_AUTO_FLUSH
+            && numDocsInRAM >= maxBufferedDocs) {
+          flushPending = true;
+          state.doFlushAfter = true;
+        }
+
         success = true;
       } finally {
         if (!success) {

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=632871&r1=632870&r2=632871&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  2 15:24:07
2008
@@ -4243,4 +4243,10 @@
     public static final MaxFieldLength LIMITED
         = new MaxFieldLength("LIMITED", DEFAULT_MAX_FIELD_LENGTH);
   }
+
+  // Used only by assert for testing.  Current points:
+  //  "DocumentsWriter.ThreadState.init start"
+  boolean testPoint(String name) {
+    return true;
+  }
 }

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=632871&r1=632870&r2=632871&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  2 15:24:07
2008
@@ -3123,4 +3123,39 @@
     writer.addDocument(doc);
     writer.close();
   }
+
+  // LUCENE-1198
+  public class MockIndexWriter extends IndexWriter {
+
+    public MockIndexWriter(Directory dir, boolean autoCommit, Analyzer a, boolean create,
MaxFieldLength mfl) throws IOException {
+      super(dir, autoCommit, a, create, mfl);
+    }
+
+    boolean doFail;
+
+    boolean testPoint(String name) {
+      if (doFail && name.equals("DocumentsWriter.ThreadState.init start"))
+        throw new RuntimeException("intentionally failing");
+      return true;
+    }
+  }
+
+  public void testExceptionDocumentsWriterInit() throws IOException {
+    MockRAMDirectory dir = new MockRAMDirectory();
+    MockIndexWriter w = new MockIndexWriter(dir, false, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
+    Document doc = new Document();
+    doc.add(new Field("field", "a field", Field.Store.YES,
+                      Field.Index.TOKENIZED));
+    w.addDocument(doc);
+    w.doFail = true;
+    try {
+      w.addDocument(doc);
+      fail("did not hit exception");
+    } catch (RuntimeException re) {
+      // expected
+    }
+    w.close();
+    _TestUtil.checkIndex(dir);
+    dir.close();
+  }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java?rev=632871&r1=632870&r2=632871&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java Sun Mar  2 15:24:07 2008
@@ -22,6 +22,10 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.MergeScheduler;
 import org.apache.lucene.index.ConcurrentMergeScheduler;
+import org.apache.lucene.index.CheckIndex;
+import org.apache.lucene.store.Directory;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 
 public class _TestUtil {
 
@@ -49,4 +53,16 @@
     if (ms instanceof ConcurrentMergeScheduler)
       ((ConcurrentMergeScheduler) ms).sync();
   }
+
+  public static boolean checkIndex(Directory dir) throws IOException {
+    ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
+    CheckIndex.out = new PrintStream(bos);
+    if (!CheckIndex.check(dir, false, null)) {
+      System.out.println("CheckIndex failed");
+      System.out.println(bos.toString());
+      return false;
+    } else
+      return true;
+  }
+
 }



Mime
View raw message