1 package org.apache.lucene.benchmark.byTask.tasks;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import org.apache.lucene.benchmark.byTask.PerfRunData;
21 import org.apache.lucene.benchmark.byTask.utils.Config;
22 import org.apache.lucene.index.IndexWriter;
23 import org.apache.lucene.index.IndexCommit;
24 import org.apache.lucene.index.IndexWriterConfig;
25 import org.apache.lucene.index.LogMergePolicy;
26 import org.apache.lucene.index.IndexWriter.MaxFieldLength;
27 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
28 import java.io.IOException;
32 * Open an index writer.
33 * <br>Other side effects: index writer object in perfRunData is set.
34 * <br>Relevant properties: <code>merge.factor, max.buffered,
35 * max.field.length, ram.flush.mb [default 0]</code>.
37 * <p> Accepts a param specifying the commit point as
38 * previously saved with CommitIndexTask. If you specify
39 * this, it rolls the index back to that commit on opening
42 public class OpenIndexTask extends PerfTask {
44 public static final int DEFAULT_MAX_BUFFERED = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS;
45 public static final int DEFAULT_MAX_FIELD_LENGTH = MaxFieldLength.UNLIMITED.getLimit();
46 public static final int DEFAULT_MERGE_PFACTOR = LogMergePolicy.DEFAULT_MERGE_FACTOR;
47 public static final double DEFAULT_RAM_FLUSH_MB = (int) IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB;
48 private String commitUserData;
50 public OpenIndexTask(PerfRunData runData) {
55 public int doLogic() throws IOException {
56 PerfRunData runData = getRunData();
57 Config config = runData.getConfig();
59 if (commitUserData != null) {
60 ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
65 final IndexWriter writer = CreateIndexTask.configureWriter(config, runData, OpenMode.APPEND, ic);
66 runData.setIndexWriter(writer);
71 public void setParams(String params) {
72 super.setParams(params);
74 // specifies which commit point to open
75 commitUserData = params;
80 public boolean supportsParams() {