LUCENE-3432: TMP should not enforce maxMergedSegMB for expungeDeletes

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1170157 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-09-13 12:54:33 +00:00
parent 0b55ddeedf
commit c8bec3f17d
4 changed files with 63 additions and 31 deletions

View File

@ -585,6 +585,10 @@ Bug fixes
* LUCENE-3421: PayloadTermQuery's explain was wrong when includeSpanScore=false.
(Edward Drapkin via Robert Muir)
* LUCENE-3432: IndexWriter.expungeDeletes with TieredMergePolicy
should ignore the maxMergedSegmentMB setting (v.sevel via Mike
McCandless)
======================= Lucene 3.4.0 =======================
Bug fixes

View File

@ -576,45 +576,20 @@ public class TieredMergePolicy extends MergePolicy {
MergeSpecification spec = null;
while(start < eligible.size()) {
long totAfterMergeBytes = 0;
int upto = start;
boolean done = false;
while(upto < start + maxMergeAtOnceExplicit) {
if (upto == eligible.size()) {
done = true;
break;
}
final SegmentInfo info = eligible.get(upto);
final long segBytes = size(info);
if (totAfterMergeBytes + segBytes > maxMergedSegmentBytes) {
// TODO: we could be smarter here, eg cherry
// picking smaller merges that'd sum up to just
// around the max size
break;
}
totAfterMergeBytes += segBytes;
upto++;
}
if (upto == start) {
// Single segment is too big; grace it
start++;
continue;
}
// Don't enforce max merged size here: app is explicitly
// calling expungeDeletes, and knows this may take a
// long time / produce big segments (like optimize):
final int end = Math.min(start + maxMergeAtOnceExplicit, eligible.size());
if (spec == null) {
spec = new MergeSpecification();
}
final OneMerge merge = new OneMerge(eligible.subList(start, upto));
final OneMerge merge = new OneMerge(eligible.subList(start, end));
if (verbose()) {
message("add merge=" + writer.get().segString(merge.segments));
}
spec.add(merge);
start = upto;
if (done) {
break;
}
start = end;
}
return spec;

View File

@ -326,6 +326,14 @@ public class RandomIndexWriter implements Closeable {
private boolean doRandomOptimize = true;
private boolean doRandomOptimizeAssert = true;
public void expungeDeletes(boolean doWait) throws IOException {
w.expungeDeletes(doWait);
}
public void expungeDeletes() throws IOException {
w.expungeDeletes();
}
public void setDoRandomOptimize(boolean v) {
doRandomOptimize = v;
}

View File

@ -19,6 +19,7 @@ package org.apache.lucene.index;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
@ -107,4 +108,48 @@ public class TestTieredMergePolicy extends LuceneTestCase {
dir.close();
}
}
public void testExpungeMaxSegSize() throws Exception {
final Directory dir = newDirectory();
final IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));
final TieredMergePolicy tmp = new TieredMergePolicy();
tmp.setMaxMergedSegmentMB(0.01);
tmp.setExpungeDeletesPctAllowed(0.0);
conf.setMergePolicy(tmp);
final RandomIndexWriter w = new RandomIndexWriter(random, dir, conf);
w.setDoRandomOptimize(false);
final int numDocs = atLeast(200);
for(int i=0;i<numDocs;i++) {
Document doc = new Document();
doc.add(newField("id", "" + i, StringField.TYPE_UNSTORED));
doc.add(newField("content", "aaa " + i, TextField.TYPE_UNSTORED));
w.addDocument(doc);
}
w.optimize();
IndexReader r = w.getReader();
assertEquals(numDocs, r.maxDoc());
assertEquals(numDocs, r.numDocs());
r.close();
w.deleteDocuments(new Term("id", ""+(42+17)));
r = w.getReader();
assertEquals(numDocs, r.maxDoc());
assertEquals(numDocs-1, r.numDocs());
r.close();
w.expungeDeletes();
r = w.getReader();
assertEquals(numDocs-1, r.maxDoc());
assertEquals(numDocs-1, r.numDocs());
r.close();
w.close();
dir.close();
}
}