Lucene: allow configuring writer flush options
Use index.changes_{open,closed}.{ramBufferSize,maxBufferedDocs} in the
server config to set the corresponding parameters on the
IndexWriterConfigs.
Change-Id: Idaa3ac3c541c330ceee052e8de23a63aea0dcf30
This commit is contained in:
@@ -43,11 +43,14 @@ import com.google.gerrit.server.query.change.IndexRewriteImpl;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.IntField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
@@ -60,6 +63,7 @@ import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -86,19 +90,33 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
||||
public static final String CHANGES_OPEN = "changes_open";
|
||||
public static final String CHANGES_CLOSED = "changes_closed";
|
||||
|
||||
private static IndexWriterConfig getIndexWriterConfig(Config cfg, String name) {
|
||||
IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION,
|
||||
new StandardAnalyzer(LUCENE_VERSION));
|
||||
writerConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
|
||||
double m = 1 << 20;
|
||||
writerConfig.setRAMBufferSizeMB(cfg.getLong("index", name, "ramBufferSize",
|
||||
(long) (IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB * m)) / m);
|
||||
writerConfig.setMaxBufferedDocs(cfg.getInt("index", name, "maxBufferedDocs",
|
||||
IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS));
|
||||
return writerConfig;
|
||||
}
|
||||
|
||||
private final RefreshThread refreshThread;
|
||||
private final FillArgs fillArgs;
|
||||
private final boolean readOnly;
|
||||
private final SubIndex openIndex;
|
||||
private final SubIndex closedIndex;
|
||||
|
||||
LuceneChangeIndex(SitePaths sitePaths, FillArgs fillArgs, boolean readOnly)
|
||||
throws IOException {
|
||||
LuceneChangeIndex(Config cfg, SitePaths sitePaths, FillArgs fillArgs,
|
||||
boolean readOnly) throws IOException {
|
||||
this.refreshThread = new RefreshThread();
|
||||
this.fillArgs = fillArgs;
|
||||
this.readOnly = readOnly;
|
||||
openIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_OPEN));
|
||||
closedIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_CLOSED));
|
||||
openIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_OPEN),
|
||||
getIndexWriterConfig(cfg, "changes_open"));
|
||||
closedIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_CLOSED),
|
||||
getIndexWriterConfig(cfg, "changes_closed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.lucene;
|
||||
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.index.ChangeIndex;
|
||||
import com.google.gerrit.server.index.FieldDef.FillArgs;
|
||||
@@ -22,6 +23,8 @@ import com.google.gerrit.server.index.IndexModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LuceneIndexModule extends LifecycleModule {
|
||||
@@ -52,8 +55,8 @@ public class LuceneIndexModule extends LifecycleModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LuceneChangeIndex getChangeIndex(SitePaths sitePaths,
|
||||
FillArgs fillArgs) throws IOException {
|
||||
return new LuceneChangeIndex(sitePaths, fillArgs, readOnly);
|
||||
public LuceneChangeIndex getChangeIndex(@GerritServerConfig Config cfg,
|
||||
SitePaths sitePaths, FillArgs fillArgs) throws IOException {
|
||||
return new LuceneChangeIndex(cfg, sitePaths, fillArgs, readOnly);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,9 @@
|
||||
|
||||
package com.google.gerrit.lucene;
|
||||
|
||||
import static com.google.gerrit.lucene.LuceneChangeIndex.LUCENE_VERSION;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.SearcherManager;
|
||||
@@ -40,11 +36,8 @@ class SubIndex {
|
||||
private final IndexWriter writer;
|
||||
private final SearcherManager searcherManager;
|
||||
|
||||
SubIndex(File file) throws IOException {
|
||||
SubIndex(File file, IndexWriterConfig writerConfig) throws IOException {
|
||||
dir = FSDirectory.open(file);
|
||||
IndexWriterConfig writerConfig =
|
||||
new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION));
|
||||
writerConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
|
||||
writer = new IndexWriter(dir, writerConfig);
|
||||
searcherManager = new SearcherManager(writer, true, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user