Merge "Expose Lucene Index Writers for plug-ins"
This commit is contained in:
@@ -25,13 +25,28 @@ import org.apache.lucene.store.Directory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Writer that optionally flushes/commits after every write. */
|
/** Writer that optionally flushes/commits after every write. */
|
||||||
class AutoCommitWriter extends IndexWriter {
|
public class AutoCommitWriter extends IndexWriter {
|
||||||
private boolean autoCommit;
|
private boolean autoCommit;
|
||||||
|
|
||||||
|
AutoCommitWriter(Directory dir, IndexWriterConfig config)
|
||||||
|
throws IOException {
|
||||||
|
this(dir, config, false);
|
||||||
|
}
|
||||||
|
|
||||||
AutoCommitWriter(Directory dir, IndexWriterConfig config, boolean autoCommit)
|
AutoCommitWriter(Directory dir, IndexWriterConfig config, boolean autoCommit)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
super(dir, config);
|
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
|
@Override
|
||||||
@@ -99,7 +114,7 @@ class AutoCommitWriter extends IndexWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void autoFlush() throws IOException {
|
public void autoFlush() throws IOException {
|
||||||
if (autoCommit) {
|
if (autoCommit) {
|
||||||
manualFlush();
|
manualFlush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 class QuerySource implements ChangeDataSource {
|
||||||
private final List<SubIndex> indexes;
|
private final List<SubIndex> indexes;
|
||||||
private final Query query;
|
private final Query query;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
/** Piece of the change index that is implemented as a separate Lucene index. */
|
/** 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 static final Logger log = LoggerFactory.getLogger(SubIndex.class);
|
||||||
|
|
||||||
private final Directory dir;
|
private final Directory dir;
|
||||||
@@ -70,13 +70,13 @@ class SubIndex {
|
|||||||
long commitPeriod = writerConfig.getCommitWithinMs();
|
long commitPeriod = writerConfig.getCommitWithinMs();
|
||||||
|
|
||||||
if (commitPeriod < 0) {
|
if (commitPeriod < 0) {
|
||||||
delegateWriter = new IndexWriter(dir, writerConfig.getLuceneConfig());
|
delegateWriter = new AutoCommitWriter(dir, writerConfig.getLuceneConfig());
|
||||||
} else if (commitPeriod == 0) {
|
} else if (commitPeriod == 0) {
|
||||||
delegateWriter =
|
delegateWriter =
|
||||||
new AutoCommitWriter(dir, writerConfig.getLuceneConfig(), true);
|
new AutoCommitWriter(dir, writerConfig.getLuceneConfig(), true);
|
||||||
} else {
|
} else {
|
||||||
final AutoCommitWriter autoCommitWriter =
|
final AutoCommitWriter autoCommitWriter =
|
||||||
new AutoCommitWriter(dir, writerConfig.getLuceneConfig(), false);
|
new AutoCommitWriter(dir, writerConfig.getLuceneConfig());
|
||||||
delegateWriter = autoCommitWriter;
|
delegateWriter = autoCommitWriter;
|
||||||
|
|
||||||
new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder()
|
new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder()
|
||||||
@@ -191,6 +191,10 @@ class SubIndex {
|
|||||||
writer.deleteAll();
|
writer.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TrackingIndexWriter getWriter() {
|
||||||
|
return writer;
|
||||||
|
}
|
||||||
|
|
||||||
IndexSearcher acquire() throws IOException {
|
IndexSearcher acquire() throws IOException {
|
||||||
return searcherManager.acquire();
|
return searcherManager.acquire();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user