Merge "Expose Lucene Index Writers for plug-ins"

This commit is contained in:
David Pursehouse 2015-09-30 08:37:16 +00:00 committed by Gerrit Code Review
commit 714e8d684e
3 changed files with 33 additions and 6 deletions

View File

@ -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();
}

View File

@ -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<SubIndex> indexes;
private final Query query;

View File

@ -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();
}