mirror of https://github.com/apache/lucene.git
retain zero size segments resulting from a merge: LUCENE-672
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@447570 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4465baafa5
commit
b1322d5acd
|
@ -734,15 +734,14 @@ public class IndexWriter {
|
||||||
/** Merges all RAM-resident segments, then may merge segments. */
|
/** Merges all RAM-resident segments, then may merge segments. */
|
||||||
private final void flushRamSegments() throws IOException {
|
private final void flushRamSegments() throws IOException {
|
||||||
if (ramSegmentInfos.size() > 0) {
|
if (ramSegmentInfos.size() > 0) {
|
||||||
if (mergeSegments(ramSegmentInfos, 0, ramSegmentInfos.size()) > 0) {
|
mergeSegments(ramSegmentInfos, 0, ramSegmentInfos.size());
|
||||||
maybeMergeSegments();
|
maybeMergeSegments();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Incremental segment merger. */
|
/** Incremental segment merger. */
|
||||||
private final void maybeMergeSegments() throws IOException {
|
private final void maybeMergeSegments() throws IOException {
|
||||||
long lowerBound = 0;
|
long lowerBound = -1;
|
||||||
long upperBound = minMergeDocs;
|
long upperBound = minMergeDocs;
|
||||||
|
|
||||||
while (upperBound * mergeFactor <= maxMergeDocs) {
|
while (upperBound * mergeFactor <= maxMergeDocs) {
|
||||||
|
@ -782,7 +781,7 @@ public class IndexWriter {
|
||||||
// continue to merge the rest of the worthy segments on this level
|
// continue to merge the rest of the worthy segments on this level
|
||||||
minSegment++;
|
minSegment++;
|
||||||
exceedsUpperLimit = true;
|
exceedsUpperLimit = true;
|
||||||
} else if (docCount > 0) {
|
} else {
|
||||||
// if the merged segment does not exceed upperBound, consider
|
// if the merged segment does not exceed upperBound, consider
|
||||||
// this segment for further merges on this same level
|
// this segment for further merges on this same level
|
||||||
numSegments++;
|
numSegments++;
|
||||||
|
@ -810,7 +809,6 @@ public class IndexWriter {
|
||||||
if (infoStream != null) infoStream.print("merging segments");
|
if (infoStream != null) infoStream.print("merging segments");
|
||||||
SegmentMerger merger = new SegmentMerger(this, mergedName);
|
SegmentMerger merger = new SegmentMerger(this, mergedName);
|
||||||
|
|
||||||
boolean fromRAM = false;
|
|
||||||
final Vector segmentsToDelete = new Vector();
|
final Vector segmentsToDelete = new Vector();
|
||||||
for (int i = minSegment; i < end; i++) {
|
for (int i = minSegment; i < end; i++) {
|
||||||
SegmentInfo si = sourceSegments.info(i);
|
SegmentInfo si = sourceSegments.info(i);
|
||||||
|
@ -821,9 +819,6 @@ public class IndexWriter {
|
||||||
if ((reader.directory() == this.directory) || // if we own the directory
|
if ((reader.directory() == this.directory) || // if we own the directory
|
||||||
(reader.directory() == this.ramDirectory))
|
(reader.directory() == this.ramDirectory))
|
||||||
segmentsToDelete.addElement(reader); // queue segment for deletion
|
segmentsToDelete.addElement(reader); // queue segment for deletion
|
||||||
if (!fromRAM && (reader.directory() == this.ramDirectory)) {
|
|
||||||
fromRAM = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mergedDocCount = merger.merge();
|
int mergedDocCount = merger.merge();
|
||||||
|
@ -834,17 +829,13 @@ public class IndexWriter {
|
||||||
|
|
||||||
SegmentInfo newSegment = new SegmentInfo(mergedName, mergedDocCount,
|
SegmentInfo newSegment = new SegmentInfo(mergedName, mergedDocCount,
|
||||||
directory);
|
directory);
|
||||||
if (fromRAM) {
|
if (sourceSegments == ramSegmentInfos) {
|
||||||
sourceSegments.removeAllElements();
|
sourceSegments.removeAllElements();
|
||||||
if (mergedDocCount > 0)
|
segmentInfos.addElement(newSegment);
|
||||||
segmentInfos.addElement(newSegment);
|
|
||||||
} else {
|
} else {
|
||||||
for (int i = end-1; i > minSegment; i--) // remove old infos & add new
|
for (int i = end-1; i > minSegment; i--) // remove old infos & add new
|
||||||
sourceSegments.remove(i);
|
sourceSegments.remove(i);
|
||||||
if (mergedDocCount > 0)
|
segmentInfos.set(minSegment, newSegment);
|
||||||
segmentInfos.set(minSegment, newSegment);
|
|
||||||
else
|
|
||||||
sourceSegments.remove(minSegment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// close readers before we attempt to delete now-obsolete segments
|
// close readers before we attempt to delete now-obsolete segments
|
||||||
|
|
|
@ -157,9 +157,9 @@ public class TestIndexWriterMergePolicy extends TestCase {
|
||||||
writer.setMaxBufferedDocs(10);
|
writer.setMaxBufferedDocs(10);
|
||||||
writer.setMergeFactor(5);
|
writer.setMergeFactor(5);
|
||||||
|
|
||||||
|
// merge factor is changed, so check invariants after all adds
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
addDoc(writer);
|
addDoc(writer);
|
||||||
checkInvariants(writer);
|
|
||||||
}
|
}
|
||||||
checkInvariants(writer);
|
checkInvariants(writer);
|
||||||
assertEquals(10, writer.docCount());
|
assertEquals(10, writer.docCount());
|
||||||
|
@ -173,7 +173,7 @@ public class TestIndexWriterMergePolicy extends TestCase {
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInvariants(IndexWriter writer) {
|
private void checkInvariants(IndexWriter writer) throws IOException {
|
||||||
int maxBufferedDocs = writer.getMaxBufferedDocs();
|
int maxBufferedDocs = writer.getMaxBufferedDocs();
|
||||||
int mergeFactor = writer.getMergeFactor();
|
int mergeFactor = writer.getMergeFactor();
|
||||||
int maxMergeDocs = writer.getMaxMergeDocs();
|
int maxMergeDocs = writer.getMaxMergeDocs();
|
||||||
|
@ -188,10 +188,10 @@ public class TestIndexWriterMergePolicy extends TestCase {
|
||||||
int segmentCount = writer.getSegmentCount();
|
int segmentCount = writer.getSegmentCount();
|
||||||
for (int i = segmentCount - 1; i >= 0; i--) {
|
for (int i = segmentCount - 1; i >= 0; i--) {
|
||||||
int docCount = writer.getDocCount(i);
|
int docCount = writer.getDocCount(i);
|
||||||
assertTrue(docCount > lowerBound);
|
assertTrue(docCount > lowerBound || docCount == 0);
|
||||||
|
|
||||||
if (docCount <= upperBound) {
|
if (docCount <= upperBound) {
|
||||||
segmentCount++;
|
numSegments++;
|
||||||
} else {
|
} else {
|
||||||
if (upperBound * mergeFactor <= maxMergeDocs) {
|
if (upperBound * mergeFactor <= maxMergeDocs) {
|
||||||
assertTrue(numSegments < mergeFactor);
|
assertTrue(numSegments < mergeFactor);
|
||||||
|
@ -199,12 +199,21 @@ public class TestIndexWriterMergePolicy extends TestCase {
|
||||||
|
|
||||||
lowerBound = upperBound;
|
lowerBound = upperBound;
|
||||||
upperBound *= mergeFactor;
|
upperBound *= mergeFactor;
|
||||||
segmentCount = 1;
|
numSegments = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (upperBound * mergeFactor <= maxMergeDocs) {
|
if (upperBound * mergeFactor <= maxMergeDocs) {
|
||||||
assertTrue(numSegments < mergeFactor);
|
assertTrue(numSegments < mergeFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] files = writer.getDirectory().list();
|
||||||
|
int segmentCfsCount = 0;
|
||||||
|
for (int i = 0; i < files.length; i++) {
|
||||||
|
if (files[i].endsWith(".cfs")) {
|
||||||
|
segmentCfsCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(segmentCount, segmentCfsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printSegmentDocCounts(IndexWriter writer) {
|
private void printSegmentDocCounts(IndexWriter writer) {
|
||||||
|
|
Loading…
Reference in New Issue