LUCENE-843: fixed the triggerMerger logic from LUCENE-887 that I accidentally lost

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@555793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2007-07-12 22:15:20 +00:00
parent 5b944011ff
commit 8355ab88b3
2 changed files with 32 additions and 6 deletions

View File

@ -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 {
else
maybeMergeSegments(docWriter.getMaxBufferedDocs());
*/
maybeMergeSegments(docWriter.getMaxBufferedDocs());
if (triggerMerge)
maybeMergeSegments(docWriter.getMaxBufferedDocs());
}
} finally {
docWriter.clearFlushPending();

View File

@ -1293,6 +1293,23 @@ public class TestIndexWriter extends TestCase
dir.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 flush
public void testEmptyDocAfterFlushingRealDoc() throws IOException {