Merge branch 'stable-2.13'

* stable-2.13:
  Drain executor of index change requests before closing index

Change-Id: I2d676adf60d2eab0f9f7602b124574050af0ee3d
This commit is contained in:
David Pursehouse
2016-12-31 10:15:56 +00:00
10 changed files with 45 additions and 16 deletions

View File

@@ -46,6 +46,10 @@ public class ReadOnlyChangeIndex implements ChangeIndex {
index.close();
}
@Override
public void stop() {
}
@Override
public void replace(ChangeData obj) throws IOException {
// do nothing

View File

@@ -117,6 +117,10 @@ class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, AccountState>
}
}
@Override
public void stop() {
}
@Override
public DataSource<AccountState> getSource(Predicate<AccountState> p,
QueryOptions opts) throws QueryParseException {

View File

@@ -158,6 +158,10 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
}
}
@Override
public void stop() {
}
@Override
public ChangeDataSource getSource(Predicate<ChangeData> p, QueryOptions opts)
throws QueryParseException {

View File

@@ -97,4 +97,8 @@ public class ChangeSubIndex extends AbstractLuceneIndex<Change.Id, ChangeData>
}
super.add(doc, values);
}
@Override
public void stop() {
}
}

View File

@@ -205,4 +205,8 @@ public class LuceneAccountIndex
// to reindex when those change.
return accountCache.get(id);
}
@Override
public void stop() {
}
}

View File

@@ -28,12 +28,11 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Collections2;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -96,6 +95,7 @@ import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* Secondary index implementation using Apache Lucene.
@@ -190,21 +190,18 @@ public class LuceneChangeIndex implements ChangeIndex {
}
@Override
public void close() {
List<ListenableFuture<?>> closeFutures = Lists.newArrayListWithCapacity(2);
closeFutures.add(executor.submit(new Runnable() {
@Override
public void run() {
openIndex.close();
public void stop() {
MoreExecutors.shutdownAndAwaitTermination(
executor, Long.MAX_VALUE, TimeUnit.SECONDS);
}
}));
closeFutures.add(executor.submit(new Runnable() {
@Override
public void run() {
public void close() {
try {
openIndex.close();
} finally {
closedIndex.close();
}
}));
Futures.getUnchecked(Futures.allAsList(closeFutures));
}
@Override

View File

@@ -37,6 +37,9 @@ public interface Index<K, V> {
/** @return the schema version used by this index. */
Schema<V> getSchema();
/** Stop and await termination of all executor threads */
void stop();
/** Close this index. */
void close();

View File

@@ -98,6 +98,7 @@ public abstract class IndexCollection<K, V, I extends Index<K, V>>
}
for (I write : writeIndexes) {
if (write != read) {
write.stop();
write.close();
}
}

View File

@@ -57,4 +57,8 @@ public class DummyChangeIndex implements ChangeIndex {
public int getMaxLimit() {
return Integer.MAX_VALUE;
}
@Override
public void stop() {
}
}

View File

@@ -108,4 +108,8 @@ public class FakeChangeIndex implements ChangeIndex {
public void markReady(boolean ready) {
throw new UnsupportedOperationException();
}
@Override
public void stop() {
}
}