- LUCENE-388: optimize maybeMergeSegments() to speed up indexing.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@431153 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2006-08-13 08:20:13 +00:00
parent a9691a40e8
commit c5d950da35
2 changed files with 16 additions and 0 deletions

View File

@ -121,6 +121,9 @@ Optimizations
during segment merges (e.g. during indexing or optimizing), thus improving
performance . (Michael Busch via Otis Gospodnetic)
4. LUCENE-388: Changes to maybeMergeSegments() to improve indexing speed.
(Paul Smith via Otis Gospodnetic)
Release 2.0.0 2006-05-26
API Changes

View File

@ -110,6 +110,7 @@ public class IndexWriter {
private SegmentInfos segmentInfos = new SegmentInfos(); // the segments
private final Directory ramDirectory = new RAMDirectory(); // for temp segs
private long bufferedDocCount = 0;
private Lock writeLock;
private int termIndexInterval = DEFAULT_TERM_INDEX_INTERVAL;
@ -509,6 +510,7 @@ public class IndexWriter {
dw.addDocument(segmentName, doc);
synchronized (this) {
segmentInfos.addElement(new SegmentInfo(segmentName, 1, ramDirectory));
bufferedDocCount++;
maybeMergeSegments();
}
}
@ -691,6 +693,15 @@ public class IndexWriter {
/** Incremental segment merger. */
private final void maybeMergeSegments() throws IOException {
/**
* do not bother checking the segment details to determine
* if we should merge, but instead honour the maxBufferedDocs(minMergeDocs)
* property to ensure we do not spend time checking for merge conditions
*
*/
if(bufferedDocCount<minMergeDocs) {
return;
}
long targetMergeDocs = minMergeDocs;
while (targetMergeDocs <= maxMergeDocs) {
// find segments smaller than current target size
@ -741,6 +752,8 @@ public class IndexWriter {
int mergedDocCount = merger.merge();
bufferedDocCount -= mergedDocCount; // update bookkeeping about how many docs we have buffered
if (infoStream != null) {
infoStream.println(" into "+mergedName+" ("+mergedDocCount+" docs)");
}