Support creating Lucene indexes in-memory

Control this with a config option, which is the easiest way to get it
injected. Do not document the option as it should just be used for
tests.

Change-Id: Ic7d5dd5e7a3495079bacc2c2830feb0af1fe6188
This commit is contained in:
Dave Borowitz
2013-10-08 17:38:32 -07:00
parent 4652d348a4
commit ceeff43182
2 changed files with 20 additions and 6 deletions

View File

@@ -73,6 +73,7 @@ import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Version;
import org.eclipse.jgit.errors.ConfigInvalidException;
@@ -172,10 +173,18 @@ public class LuceneChangeIndex implements ChangeIndex {
Version luceneVersion = checkNotNull(
LUCENE_VERSIONS.get(schema),
"unknown Lucene version for index schema: %s", schema);
openIndex = new SubIndex(new File(dir, CHANGES_OPEN),
getIndexWriterConfig(luceneVersion, cfg, "changes_open"));
closedIndex = new SubIndex(new File(dir, CHANGES_CLOSED),
getIndexWriterConfig(luceneVersion, cfg, "changes_closed"));
IndexWriterConfig openConfig =
getIndexWriterConfig(luceneVersion, cfg, "changes_open");
IndexWriterConfig closedConfig =
getIndexWriterConfig(luceneVersion, cfg, "changes_closed");
if (cfg.getBoolean("index", "lucene", "testInmemory", false)) {
openIndex = new SubIndex(new RAMDirectory(), "ramOpen", openConfig);
closedIndex = new SubIndex(new RAMDirectory(), "ramClosed", closedConfig);
} else {
openIndex = new SubIndex(new File(dir, CHANGES_OPEN), openConfig);
closedIndex = new SubIndex(new File(dir, CHANGES_CLOSED), closedConfig);
}
}
@Override

View File

@@ -53,7 +53,12 @@ class SubIndex {
private final ConcurrentMap<RefreshListener, Boolean> refreshListeners;
SubIndex(File file, IndexWriterConfig writerConfig) throws IOException {
dir = FSDirectory.open(file);
this(FSDirectory.open(file), file.getName(), writerConfig);
}
SubIndex(Directory dir, String dirName, IndexWriterConfig writerConfig)
throws IOException {
this.dir = dir;
writer = new TrackingIndexWriter(new IndexWriter(dir, writerConfig));
searcherManager = new SearcherManager(
writer.getIndexWriter(), true, new SearcherFactory());
@@ -76,7 +81,7 @@ class SubIndex {
writer, searcherManager,
0.500 /* maximum stale age (seconds) */,
0.010 /* minimum stale age (seconds) */);
reopenThread.setName("NRT " + file.getName());
reopenThread.setName("NRT " + dirName);
reopenThread.setPriority(Math.min(
Thread.currentThread().getPriority() + 2,
Thread.MAX_PRIORITY));