mirror of https://github.com/apache/lucene.git
LUCENE-1429: don't throw IllegalStateEx during close() after hitting OOME when autoCommit=true
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@708549 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fa79b04042
commit
58966ab728
|
@ -1675,17 +1675,16 @@ public class IndexWriter {
|
|||
*/
|
||||
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 @@ public class IndexWriter {
|
|||
* @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);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.lucene.index;
|
|||
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 @@ public class TestIndexWriter extends LuceneTestCase
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue