Lucene: close sub-indexes in parallel
The open and closed sub-indexes may each take a while to close as they flush and commit writes. They are completely independent, so close them in parallel, reusing the existing indexing executor, which shouldn't be doing much else during shutdown. Change-Id: I3c56a972d19c793e2b8601727c03b6e7bf53e77d
This commit is contained in:
@@ -23,6 +23,8 @@ import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
|
||||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
@@ -73,6 +75,8 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secondary index implementation using Apache Lucene.
|
* Secondary index implementation using Apache Lucene.
|
||||||
@@ -104,14 +108,17 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
|||||||
|
|
||||||
private final RefreshThread refreshThread;
|
private final RefreshThread refreshThread;
|
||||||
private final FillArgs fillArgs;
|
private final FillArgs fillArgs;
|
||||||
|
private final ExecutorService executor;
|
||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
private final SubIndex openIndex;
|
private final SubIndex openIndex;
|
||||||
private final SubIndex closedIndex;
|
private final SubIndex closedIndex;
|
||||||
|
|
||||||
LuceneChangeIndex(Config cfg, SitePaths sitePaths, FillArgs fillArgs,
|
LuceneChangeIndex(Config cfg, SitePaths sitePaths,
|
||||||
|
ListeningScheduledExecutorService executor, FillArgs fillArgs,
|
||||||
boolean readOnly) throws IOException {
|
boolean readOnly) throws IOException {
|
||||||
this.refreshThread = new RefreshThread();
|
this.refreshThread = new RefreshThread();
|
||||||
this.fillArgs = fillArgs;
|
this.fillArgs = fillArgs;
|
||||||
|
this.executor = executor;
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
openIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_OPEN),
|
openIndex = new SubIndex(new File(sitePaths.index_dir, CHANGES_OPEN),
|
||||||
getIndexWriterConfig(cfg, "changes_open"));
|
getIndexWriterConfig(cfg, "changes_open"));
|
||||||
@@ -127,9 +134,23 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
|
|||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
refreshThread.halt();
|
refreshThread.halt();
|
||||||
|
List<Future<?>> closeFutures = Lists.newArrayListWithCapacity(2);
|
||||||
|
closeFutures.add(executor.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
openIndex.close();
|
openIndex.close();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
closeFutures.add(executor.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
closedIndex.close();
|
closedIndex.close();
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
|
for (Future<?> future : closeFutures) {
|
||||||
|
Futures.getUnchecked(future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insert(ChangeData cd) throws IOException {
|
public void insert(ChangeData cd) throws IOException {
|
||||||
|
@@ -14,11 +14,13 @@
|
|||||||
|
|
||||||
package com.google.gerrit.lucene;
|
package com.google.gerrit.lucene;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
|
||||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gerrit.server.index.ChangeIndex;
|
import com.google.gerrit.server.index.ChangeIndex;
|
||||||
import com.google.gerrit.server.index.FieldDef.FillArgs;
|
import com.google.gerrit.server.index.FieldDef.FillArgs;
|
||||||
|
import com.google.gerrit.server.index.IndexExecutor;
|
||||||
import com.google.gerrit.server.index.IndexModule;
|
import com.google.gerrit.server.index.IndexModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -56,7 +58,9 @@ public class LuceneIndexModule extends LifecycleModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public LuceneChangeIndex getChangeIndex(@GerritServerConfig Config cfg,
|
public LuceneChangeIndex getChangeIndex(@GerritServerConfig Config cfg,
|
||||||
SitePaths sitePaths, FillArgs fillArgs) throws IOException {
|
SitePaths sitePaths,
|
||||||
return new LuceneChangeIndex(cfg, sitePaths, fillArgs, readOnly);
|
@IndexExecutor ListeningScheduledExecutorService executor,
|
||||||
|
FillArgs fillArgs) throws IOException {
|
||||||
|
return new LuceneChangeIndex(cfg, sitePaths, executor, fillArgs, readOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,5 +27,5 @@ import java.lang.annotation.Retention;
|
|||||||
*/
|
*/
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
@interface IndexExecutor {
|
public @interface IndexExecutor {
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user