diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/AutoCommitWriter.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/AutoCommitWriter.java index 27ded17170..4e47bcaadf 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/AutoCommitWriter.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/AutoCommitWriter.java @@ -25,13 +25,28 @@ import org.apache.lucene.store.Directory; import java.io.IOException; /** Writer that optionally flushes/commits after every write. */ -class AutoCommitWriter extends IndexWriter { +public class AutoCommitWriter extends IndexWriter { private boolean autoCommit; + AutoCommitWriter(Directory dir, IndexWriterConfig config) + throws IOException { + this(dir, config, false); + } + AutoCommitWriter(Directory dir, IndexWriterConfig config, boolean autoCommit) throws IOException { super(dir, config); - this.autoCommit = autoCommit; + setAutoCommit(autoCommit); + } + + /** + * This method will override Gerrit configuration index.name.commitWithin + * until next Gerrit restart (or reconfiguration through this method). + * + * @param enable auto commit + */ + public void setAutoCommit(boolean enable) { + this.autoCommit = enable; } @Override @@ -99,7 +114,7 @@ class AutoCommitWriter extends IndexWriter { } } - private void autoFlush() throws IOException { + public void autoFlush() throws IOException { if (autoCommit) { manualFlush(); } diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java index 55ed22d388..99003ee39d 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java @@ -386,6 +386,14 @@ public class LuceneChangeIndex implements ChangeIndex { } } + public SubIndex getOpenChangesIndex() { + return openIndex; + } + + public SubIndex getClosedChangesIndex() { + return closedIndex; + } + private class QuerySource implements ChangeDataSource { private final List indexes; private final Query query; diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/SubIndex.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/SubIndex.java index 5778008f8c..bb69533bf8 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/SubIndex.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/SubIndex.java @@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; /** Piece of the change index that is implemented as a separate Lucene index. */ -class SubIndex { +public class SubIndex { private static final Logger log = LoggerFactory.getLogger(SubIndex.class); private final Directory dir; @@ -70,13 +70,13 @@ class SubIndex { long commitPeriod = writerConfig.getCommitWithinMs(); if (commitPeriod < 0) { - delegateWriter = new IndexWriter(dir, writerConfig.getLuceneConfig()); + delegateWriter = new AutoCommitWriter(dir, writerConfig.getLuceneConfig()); } else if (commitPeriod == 0) { delegateWriter = new AutoCommitWriter(dir, writerConfig.getLuceneConfig(), true); } else { final AutoCommitWriter autoCommitWriter = - new AutoCommitWriter(dir, writerConfig.getLuceneConfig(), false); + new AutoCommitWriter(dir, writerConfig.getLuceneConfig()); delegateWriter = autoCommitWriter; new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder() @@ -191,6 +191,10 @@ class SubIndex { writer.deleteAll(); } + public TrackingIndexWriter getWriter() { + return writer; + } + IndexSearcher acquire() throws IOException { return searcherManager.acquire(); }