1
package org.apache.solr.core;
3
* Licensed to the Apache Software Foundation (ASF) under one or more
4
* contributor license agreements. See the NOTICE file distributed with
5
* this work for additional information regarding copyright ownership.
6
* The ASF licenses this file to You under the Apache License, Version 2.0
7
* (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
20
import org.apache.lucene.store.Directory;
21
import org.apache.lucene.store.MMapDirectory;
22
import org.apache.solr.common.params.SolrParams;
23
import org.apache.solr.common.util.NamedList;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
28
import java.io.IOException;
32
* Directly provide MMapDirectory instead of relying on {@link org.apache.lucene.store.FSDirectory#open}
34
* Can set the following parameters:
36
* <li>unmap -- See {@link org.apache.lucene.store.MMapDirectory#setUseUnmap(boolean)}</li>
37
* <li>maxChunkSize -- The Max chunk size. See {@link org.apache.lucene.store.MMapDirectory#setMaxChunkSize(int)}</li>
41
public class MMapDirectoryFactory extends DirectoryFactory {
42
private transient static Logger log = LoggerFactory.getLogger(MMapDirectoryFactory.class);
47
public Directory open(String path) throws IOException {
48
MMapDirectory mapDirectory = new MMapDirectory(new File(path));
50
mapDirectory.setUseUnmap(unmapHack);
51
} catch (Exception e) {
52
log.warn("Unmap not supported on this JVM, continuing on without setting unmap", e);
54
mapDirectory.setMaxChunkSize(maxChunk);
59
public void init(NamedList args) {
60
SolrParams params = SolrParams.toSolrParams( args );
61
maxChunk = params.getInt("maxChunkSize", MMapDirectory.DEFAULT_MAX_BUFF);
63
throw new IllegalArgumentException("maxChunk must be greater than 0");
65
unmapHack = params.getBool("unmap", true);