lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r708549 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 28 Oct 2008 12:08:20 GMT
Author: mikemccand
Date: Tue Oct 28 05:08:19 2008
New Revision: 708549

URL: http://svn.apache.org/viewvc?rev=708549&view=rev
Log:
LUCENE-1429: don't throw IllegalStateEx during close() after hitting OOME when autoCommit=true

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=708549&r1=708548&r2=708549&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 Tue Oct 28 05:08:19
2008
@@ -1675,17 +1675,16 @@
    */
   public void close(boolean waitForMerges) throws CorruptIndexException, IOException {
 
-    // If any methods have hit OutOfMemoryError, then abort
-    // on close, in case the internal state of IndexWriter
-    // or DocumentsWriter is corrupt
-    if (hitOOM) {
-      rollback();
-      return;
-    }
-
     // Ensure that only one thread actually gets to do the closing:
-    if (shouldClose())
-      closeInternal(waitForMerges);
+    if (shouldClose()) {
+      // If any methods have hit OutOfMemoryError, then abort
+      // on close, in case the internal state of IndexWriter
+      // or DocumentsWriter is corrupt
+      if (hitOOM)
+        rollbackInternal();
+      else
+        closeInternal(waitForMerges);
+    }
   }
 
   // Returns true if this thread should attempt to close, or
@@ -3397,6 +3396,9 @@
    * @deprecated please call {@link #commit()}) instead
    */
   public final void flush() throws CorruptIndexException, IOException {  
+    if (hitOOM)
+      throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot flush");
+
     flush(true, false, 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=708549&r1=708548&r2=708549&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 Tue Oct 28 05:08:19
2008
@@ -20,6 +20,8 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.File;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.List;
@@ -4178,4 +4180,30 @@
       dir.close();
     }
   }
+
+  // LUCENE-1429
+  public void testOutOfMemoryErrorCausesCloseToFail() throws Exception {
+
+    final List thrown = new ArrayList();
+
+    final IndexWriter writer = new IndexWriter(new MockRAMDirectory(), new StandardAnalyzer())
{
+        public void message(final String message) {
+          if (message.startsWith("now flush at close") && 0 == thrown.size()) {
+            thrown.add(null);
+            throw new OutOfMemoryError("fake OOME at " + message);
+          }
+        }
+      };
+
+    // need to set an info stream so message is called
+    writer.setInfoStream(new PrintStream(new ByteArrayOutputStream()));
+    try {
+      writer.close();
+      fail("OutOfMemoryError expected");
+    }
+    catch (final OutOfMemoryError expected) {}
+
+    // throws IllegalStateEx w/o bug fix
+    writer.close();
+  }
 }



Mime
View raw message