diff --git a/src/java/org/apache/lucene/index/DocumentsWriter.java b/src/java/org/apache/lucene/index/DocumentsWriter.java index df0b8204989..5551012786c 100644 --- a/src/java/org/apache/lucene/index/DocumentsWriter.java +++ b/src/java/org/apache/lucene/index/DocumentsWriter.java @@ -423,6 +423,8 @@ final class DocumentsWriter { resetPostingsData(); docStoreSegment = null; + numDocsInStore = 0; + docStoreOffset = 0; files = null; } finally { diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java index 8fa311dcb59..c39de74f247 100644 --- a/src/java/org/apache/lucene/index/IndexWriter.java +++ b/src/java/org/apache/lucene/index/IndexWriter.java @@ -2447,6 +2447,11 @@ public class IndexWriter { } int docStoreOffset = docWriter.getDocStoreOffset(); + + // docStoreOffset should only be non-zero when + // autoCommit == false + assert !autoCommit || 0 == docStoreOffset; + boolean docStoreIsCompoundFile = false; // Check if the doc stores must be separately flushed diff --git a/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java b/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java index 22a6c5d4369..6189fdb1c23 100644 --- a/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java +++ b/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java @@ -76,10 +76,8 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase { writer.addDocument(doc); } - // Even though this won't delete any docs, - // IndexWriter's flush will still make a clone for all - // SegmentInfos on hitting the exception: - writer.deleteDocuments(new Term("id", "1000")); + writer.addDocument(doc); + failure.setDoFail(); try { writer.flush(); diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.java index 82ae63020c8..18c7b0459b8 100644 --- a/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -2254,8 +2254,9 @@ public class TestIndexWriter extends LuceneTestCase int idUpto = 0; int fullCount = 0; + final long stopTime = System.currentTimeMillis() + 500; - while(true) { + while(System.currentTimeMillis() < stopTime) { try { writer.updateDocument(new Term("id", ""+(idUpto++)), doc); } catch (IOException ioe) { @@ -2435,13 +2436,20 @@ public class TestIndexWriter extends LuceneTestCase // Throws IOException during FieldsWriter.flushDocument and during DocumentsWriter.abort private static class FailOnlyOnAbortOrFlush extends MockRAMDirectory.Failure { + private boolean onlyOnce; + public FailOnlyOnAbortOrFlush(boolean onlyOnce) { + this.onlyOnce = true; + } public void eval(MockRAMDirectory dir) throws IOException { if (doFail) { StackTraceElement[] trace = new Exception().getStackTrace(); for (int i = 0; i < trace.length; i++) { if ("abort".equals(trace[i].getMethodName()) || - "flushDocument".equals(trace[i].getMethodName())) + "flushDocument".equals(trace[i].getMethodName())) { + if (onlyOnce) + doFail = false; throw new IOException("now failing on purpose"); + } } } } @@ -2522,11 +2530,24 @@ public class TestIndexWriter extends LuceneTestCase assertTrue("hit unexpected Throwable", threads[i].error == null); } + boolean success = false; try { writer.close(false); + success = true; } catch (IOException ioe) { } + if (success) { + IndexReader reader = IndexReader.open(dir); + for(int j=0;j