LUCENE-1139: fix IndexWriter settings (compound, merge.factor, etc.) to work again

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@614022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-01-21 21:42:43 +00:00
parent 37573a1fdc
commit dd0265469a
2 changed files with 50 additions and 13 deletions

View File

@ -40,19 +40,6 @@ public class CreateIndexTask extends PerfTask {
}
public static void setIndexWriterConfig(IndexWriter writer, Config config) throws IOException {
writer.setUseCompoundFile(config.get("compound",true));
writer.setMergeFactor(config.get("merge.factor",OpenIndexTask.DEFAULT_MERGE_PFACTOR));
writer.setMaxFieldLength(config.get("max.field.length",OpenIndexTask.DEFAULT_MAX_FIELD_LENGTH));
final double ramBuffer = config.get("ram.flush.mb",OpenIndexTask.DEFAULT_RAM_FLUSH_MB);
final int maxBuffered = config.get("max.buffered",OpenIndexTask.DEFAULT_MAX_BUFFERED);
if (maxBuffered == IndexWriter.DISABLE_AUTO_FLUSH) {
writer.setRAMBufferSizeMB(ramBuffer);
writer.setMaxBufferedDocs(maxBuffered);
} else {
writer.setMaxBufferedDocs(maxBuffered);
writer.setRAMBufferSizeMB(ramBuffer);
}
final String mergeScheduler = config.get("merge.scheduler",
"org.apache.lucene.index.ConcurrentMergeScheduler");
@ -89,6 +76,20 @@ public class CreateIndexTask extends PerfTask {
}
if (err != null)
throw err;
writer.setUseCompoundFile(config.get("compound",true));
writer.setMergeFactor(config.get("merge.factor",OpenIndexTask.DEFAULT_MERGE_PFACTOR));
writer.setMaxFieldLength(config.get("max.field.length",OpenIndexTask.DEFAULT_MAX_FIELD_LENGTH));
final double ramBuffer = config.get("ram.flush.mb",OpenIndexTask.DEFAULT_RAM_FLUSH_MB);
final int maxBuffered = config.get("max.buffered",OpenIndexTask.DEFAULT_MAX_BUFFERED);
if (maxBuffered == IndexWriter.DISABLE_AUTO_FLUSH) {
writer.setRAMBufferSizeMB(ramBuffer);
writer.setMaxBufferedDocs(maxBuffered);
} else {
writer.setMaxBufferedDocs(maxBuffered);
writer.setRAMBufferSizeMB(ramBuffer);
}
}
public int doLogic() throws IOException {

View File

@ -522,6 +522,42 @@ public class TestPerfTasksLogic extends TestCase {
ir.close();
}
/**
* Test that IndexWriter settings stick.
*/
public void testIndexWriterSettings() throws Exception {
// 1. alg definition (required in every "logic" test)
String algLines[] = {
"# ----- properties ",
"doc.maker="+Reuters20DocMaker.class.getName(),
"doc.add.log.step=3",
"ram.flush.mb=-1",
"max.buffered=2",
"compound=false",
"doc.term.vector=false",
"doc.maker.forever=false",
"directory=RAMDirectory",
"doc.stored=false",
"merge.factor=3",
"doc.tokenized=false",
"debug.level=1",
"# ----- alg ",
"{ \"Rounds\"",
" ResetSystemErase",
" CreateIndex",
" { \"AddDocs\" AddDoc > : * ",
"} : 2",
};
// 2. execute the algorithm (required in every "logic" test)
Benchmark benchmark = execBenchmark(algLines);
final IndexWriter writer = benchmark.getRunData().getIndexWriter();
assertEquals(2, writer.getMaxBufferedDocs());
assertEquals(writer.DISABLE_AUTO_FLUSH, (int) writer.getRAMBufferSizeMB());
assertEquals(3, writer.getMergeFactor());
assertEquals(false, writer.getUseCompoundFile());
}
/**
* Test that we can call optimize(maxNumSegments).
*/