diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java index d9779940f04..3679c680847 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java @@ -575,8 +575,8 @@ class DocumentsWriterPerThread { } finally { if (!success) { if (infoStream.isEnabled("DWPT")) { - infoStream.message("DWPT", "hit exception " + - "reating compound file for newly flushed segment " + newSegment.info.name); + infoStream.message("DWPT", + "hit exception creating compound file for newly flushed segment " + newSegment.info.name); } } } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java index dd8aacc496e..8d31013f871 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java @@ -1217,4 +1217,100 @@ public class TestIndexWriterDelete extends LuceneTestCase { r.close(); d.close(); } + + // Make sure if we hit disk full, and then later disk + // frees up, and we successfully close IW or open an NRT + // reader, we don't lose any deletes: + public void testNoLostDeletesOnDiskFull() throws Exception { + + int deleteCount = 0; + int idUpto = 0; + int docBase = 0; + int docCount = 0; + + MockDirectoryWrapper dir = newMockDirectory(); + final AtomicBoolean shouldFail = new AtomicBoolean(); + dir.failOn(new MockDirectoryWrapper.Failure() { + + boolean failedAlready; + + @Override + public void eval(MockDirectoryWrapper dir) throws IOException { + StackTraceElement[] trace = new Exception().getStackTrace(); + if (shouldFail.get()) { + for (int i = 0; i < trace.length; i++) { + if ("writeLiveDocs".equals(trace[i].getMethodName())) { + // Only sometimes throw the exc, so we get + // it sometimes on creating the file, on + // flushing buffer, on closing the file: + if (random().nextInt(3) == 2) { + if (VERBOSE) { + System.out.println("TEST: now fail; exc:"); + new Throwable().printStackTrace(System.out); + } + shouldFail.set(false); + throw new IOException("now fail on purpose"); + } else { + break; + } + } + } + } + } + }); + + for(int iter=0;iter<10*RANDOM_MULTIPLIER;iter++) { + int numDocs = atLeast(100); + if (VERBOSE) { + System.out.println("\nTEST: iter=" + iter + " numDocs=" + numDocs + " docBase=" + docBase); + } + IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + IndexWriter w = new IndexWriter(dir, iwc); + for(int i=0;i