Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 768598) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -1635,7 +1635,9 @@ // Only allow a new merge to be triggered if we are // going to wait for merges: - flush(waitForMerges, true, true); + if (!hitOOM) { + flush(waitForMerges, true, true); + } if (waitForMerges) // Give merge scheduler last chance to run, in case @@ -2263,6 +2265,11 @@ if (doWait) { synchronized(this) { while(true) { + + if (hitOOM) { + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot complete optimize"); + } + if (mergeExceptions.size() > 0) { // Forward any exceptions in background merge // threads to the current thread: @@ -2345,6 +2352,10 @@ boolean running = true; while(running) { + if (hitOOM) { + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot complete expungeDeletes"); + } + // Check each merge that MergePolicy asked us to // do, to see if any of them are still running and // if any of them have hit an exception. @@ -2424,6 +2435,11 @@ if (stopMerges) return; + // Do not start new merges if we've hit OOME + if (hitOOM) { + return; + } + final MergePolicy.MergeSpecification spec; if (optimize) { spec = mergePolicy.findMergesForOptimize(segmentInfos, this, maxNumSegmentsOptimize, segmentsToOptimize); @@ -3456,6 +3472,10 @@ // even while a flush is happening private synchronized final boolean doFlush(boolean flushDocStores, boolean flushDeletes) throws CorruptIndexException, IOException { + if (hitOOM) { + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot flush"); + } + ensureOpen(false); assert testPoint("startDoFlush"); @@ -3757,8 +3777,9 @@ assert testPoint("startCommitMerge"); - if (hitOOM) - return false; + if (hitOOM) { + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot complete merge"); + } if (infoStream != null) message("commitMerge: " + merge.segString(directory) + " index=" + segString()); @@ -3987,6 +4008,10 @@ assert merge.registerDone; assert !merge.optimize || merge.maxNumSegmentsOptimize > 0; + if (hitOOM) { + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot merge"); + } + if (merge.info != null) // mergeInit already done return;