lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r745788 - in /lucene/java/branches/lucene_2_4: ./ CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Thu, 19 Feb 2009 09:32:01 GMT
Author: mikemccand
Date: Thu Feb 19 09:32:00 2009
New Revision: 745788

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

Modified:
    lucene/java/branches/lucene_2_4/   (props changed)
    lucene/java/branches/lucene_2_4/CHANGES.txt
    lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java

Propchange: lucene/java/branches/lucene_2_4/
------------------------------------------------------------------------------
    svn:mergeinfo = /lucene/java/trunk:708549

Modified: lucene/java/branches/lucene_2_4/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/CHANGES.txt?rev=745788&r1=745787&r2=745788&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_4/CHANGES.txt Thu Feb 19 09:32:00 2009
@@ -11,6 +11,10 @@
    numbers).  This bug was introduced with LUCENE-1219.  (Andrzej
    Bialecki via Mike McCandless).
 
+2. LUCENE-1429: Don't throw incorrect IllegalStateException from
+   IndexWriter.close() if you've hit an OOM when autoCommit is true.
+   (Mike McCandless)
+
 ======================= Release 2.4.0 2008-10-06 =======================
 
 Changes in backwards compatibility policy

Modified: lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java?rev=745788&r1=745787&r2=745788&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/index/IndexWriter.java Thu
Feb 19 09:32:00 2009
@@ -1575,17 +1575,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
@@ -3297,6 +3296,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/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=745788&r1=745787&r2=745788&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/index/TestIndexWriter.java
Thu Feb 19 09:32:00 2009
@@ -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;
@@ -4140,4 +4142,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