Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 768415) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -2043,7 +2043,8 @@ // 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 @@ -2708,6 +2709,10 @@ 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: @@ -2795,6 +2800,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. @@ -2883,6 +2892,10 @@ 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); @@ -3981,6 +3994,9 @@ // 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"); @@ -4261,7 +4277,7 @@ assert testPoint("startCommitMerge"); if (hitOOM) - return false; + throw new IllegalStateException("this writer hit an OutOfMemoryError; cannot complete merge"); if (infoStream != null) message("commitMerge: " + merge.segString(directory) + " index=" + segString()); @@ -4477,6 +4493,9 @@ 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;