Apache Lucene open-source search software
LUCENE-843: fixed the triggerMerger logic from LUCENE-887 that I accidentally lost
Michael McCandless8355ab88b338
diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.javaindex 322fce6c85d..87ec6d74c01 100644--- a/src/java/org/apache/lucene/index/IndexWriter.java+++ b/src/java/org/apache/lucene/index/IndexWriter.java@@ -1828,10 +1828,6 @@ public class IndexWriter {flush(true, false);}- public final synchronized void flush() throws CorruptIndexException, IOException {- flush(true, false);- }-/*** Flush all in-memory buffered updates (adds and deletes)* to the Directory.@@ -1840,7 +1836,19 @@ public class IndexWriter {* @throws CorruptIndexException if the index is corrupt* @throws IOException if there is a low-level IO error*/- public final synchronized void flush(boolean triggerMerge, boolean flushDocStores) throws CorruptIndexException, IOException {+ public final synchronized void flush() throws CorruptIndexException, IOException {+ flush(true, false);+ }++ /**+ * Flush all in-memory buffered udpates (adds and deletes)+ * to the Directory.+ * @param triggerMerge if true, we may merge segments (if+ * deletes or docs were flushed) if necessary+ * @param flushDocStores if false we are allowed to keep+ * doc stores open to share with the next segment+ */+ protected final synchronized void flush(boolean triggerMerge, boolean flushDocStores) throws CorruptIndexException, IOException {ensureOpen();// Make sure no threads are actively adding a document@@ -1986,7 +1994,8 @@ public class IndexWriter {elsemaybeMergeSegments(docWriter.getMaxBufferedDocs());*/- maybeMergeSegments(docWriter.getMaxBufferedDocs());+ if (triggerMerge)+ maybeMergeSegments(docWriter.getMaxBufferedDocs());}} finally {docWriter.clearFlushPending();diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 2812943fd34..90eb628c46d 100644--- a/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -1293,6 +1293,23 @@ public class TestIndexWriter extends TestCasedir.close();}+ public void testFlushWithNoMerging() throws IOException {+ Directory dir = new RAMDirectory();+ IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);+ writer.setMaxBufferedDocs(2);+ Document doc = new Document();+ doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));+ for(int i=0;i<19;i++)+ writer.addDocument(doc);+ writer.flush(false, true);+ writer.close();+ SegmentInfos sis = new SegmentInfos();+ sis.read(dir);+ // Since we flushed w/o allowing merging we should now+ // have 10 segments+ assert sis.size() == 10;+ }+// Make sure we can flush segment w/ norms, then add// empty doc (no norms) and flushpublic void testEmptyDocAfterFlushingRealDoc() throws IOException {