01: package org.apache.lucene.benchmark.byTask.tasks;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.analysis.Analyzer;
21: import org.apache.lucene.benchmark.byTask.PerfRunData;
22: import org.apache.lucene.benchmark.byTask.utils.Config;
23: import org.apache.lucene.index.IndexWriter;
24: import org.apache.lucene.index.LogMergePolicy;
25: import org.apache.lucene.store.Directory;
26:
27: import java.io.IOException;
28:
29: /**
30: * Open an index writer.
31: * <br>Other side effects: index writer object in perfRunData is set.
32: * <br>Relevant properties: <code>merge.factor, max.buffered,
33: * max.field.length, ram.flush.mb [default 0], autocommit
34: * [default true]</code>.
35: */
36: public class OpenIndexTask extends PerfTask {
37:
38: public static final int DEFAULT_MAX_BUFFERED = IndexWriter.DEFAULT_MAX_BUFFERED_DOCS;
39: public static final int DEFAULT_MAX_FIELD_LENGTH = IndexWriter.DEFAULT_MAX_FIELD_LENGTH;
40: public static final int DEFAULT_MERGE_PFACTOR = LogMergePolicy.DEFAULT_MERGE_FACTOR;
41: public static final double DEFAULT_RAM_FLUSH_MB = (int) IndexWriter.DEFAULT_RAM_BUFFER_SIZE_MB;
42: public static final boolean DEFAULT_AUTO_COMMIT = true;
43:
44: public OpenIndexTask(PerfRunData runData) {
45: super (runData);
46: }
47:
48: public int doLogic() throws IOException {
49: Directory dir = getRunData().getDirectory();
50: Analyzer analyzer = getRunData().getAnalyzer();
51:
52: Config config = getRunData().getConfig();
53:
54: boolean cmpnd = config.get("compound", true);
55: int mrgf = config.get("merge.factor", DEFAULT_MERGE_PFACTOR);
56: int mxbf = config.get("max.buffered", DEFAULT_MAX_BUFFERED);
57: int mxfl = config.get("max.field.length",
58: DEFAULT_MAX_FIELD_LENGTH);
59: double flushAtRAMUsage = config.get("ram.flush.mb",
60: DEFAULT_RAM_FLUSH_MB);
61: boolean autoCommit = config.get("autocommit",
62: DEFAULT_AUTO_COMMIT);
63: IndexWriter writer = new IndexWriter(dir, autoCommit, analyzer,
64: false);
65:
66: // must update params for newly opened writer
67: writer.setRAMBufferSizeMB(flushAtRAMUsage);
68: writer.setMaxBufferedDocs(mxbf);
69: writer.setMaxFieldLength(mxfl);
70: writer.setMergeFactor(mrgf);
71: writer.setUseCompoundFile(cmpnd); // this one redundant?
72: if (flushAtRAMUsage > 0)
73: writer.setRAMBufferSizeMB(flushAtRAMUsage);
74:
75: getRunData().setIndexWriter(writer);
76: return 1;
77: }
78:
79: }
|