Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  WebAppInitializer: Move plugin modules loading to after the index one
  De-couple online reindex activation from index module
  Revert "Fix online reindexing for plugins-dependent rules"

Change-Id: Iddd0dc1ff529a950c660a510a1affac7cc61f4a2
This commit is contained in:
David Ostrovsky 2019-01-05 11:15:34 +01:00
commit d620575b94
7 changed files with 40 additions and 73 deletions

View File

@ -392,6 +392,7 @@ public class GerritServer implements AutoCloseable {
cfg.setBoolean("httpd", null, "requestLog", false);
cfg.setBoolean("sshd", null, "requestLog", false);
cfg.setBoolean("index", "lucene", "testInmemory", true);
cfg.setBoolean("index", null, "onlineUpgrade", false);
cfg.setString("gitweb", null, "cgi", "");
daemon.setEnableHttpd(desc.httpd());
daemon.setLuceneModule(LuceneIndexModule.singleVersionAllLatest(0, isSlave(baseConfig)));

View File

@ -25,20 +25,15 @@ import java.util.Map;
public class ElasticIndexModule extends AbstractIndexModule {
public static ElasticIndexModule singleVersionWithExplicitVersions(
Map<String, Integer> versions, int threads, boolean slave) {
return new ElasticIndexModule(versions, threads, false, slave);
return new ElasticIndexModule(versions, threads, slave);
}
public static ElasticIndexModule latestVersionWithOnlineUpgrade(boolean slave) {
return new ElasticIndexModule(null, 0, true, slave);
public static ElasticIndexModule latestVersion(boolean slave) {
return new ElasticIndexModule(null, 0, slave);
}
public static ElasticIndexModule latestVersionWithoutOnlineUpgrade(boolean slave) {
return new ElasticIndexModule(null, 0, false, slave);
}
private ElasticIndexModule(
Map<String, Integer> singleVersions, int threads, boolean onlineUpgrade, boolean slave) {
super(singleVersions, threads, onlineUpgrade, slave);
private ElasticIndexModule(Map<String, Integer> singleVersions, int threads, boolean slave) {
super(singleVersions, threads, slave);
}
@Override

View File

@ -74,6 +74,8 @@ import com.google.gerrit.server.git.SearchingChangeCacheImpl;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.index.IndexModule;
import com.google.gerrit.server.index.IndexModule.IndexType;
import com.google.gerrit.server.index.OnlineUpgrader;
import com.google.gerrit.server.index.VersionManager;
import com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier;
import com.google.gerrit.server.mail.receive.MailReceiver;
import com.google.gerrit.server.mail.send.SmtpEmailSender;
@ -339,21 +341,6 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
modules.add(new SignedTokenEmailTokenVerifier.Module());
modules.add(new LocalMergeSuperSetComputation.Module());
modules.add(new AuditModule());
// Plugin module needs to be inserted *before* the index module.
// There is the concept of LifecycleModule, in Gerrit's own extension
// to Guice, which has these:
// listener().to(SomeClassImplementingLifecycleListener.class);
// and the start() methods of each such listener are executed in the
// order they are declared.
// Makes sure that PluginLoader.start() is executed before the
// LuceneIndexModule.start() so that plugins get loaded and the respective
// Guice modules installed so that the on-line reindexing will happen
// with the proper classes (e.g. group backends, custom Prolog
// predicates) and the associated rules ready to be evaluated.
modules.add(new PluginModule());
modules.add(new RestApiModule());
modules.add(new GpgModule(config));
modules.add(new StartupChecks.Module());
@ -361,6 +348,12 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
// work queue can get stuck waiting on index futures that will never return.
modules.add(createIndexModule());
modules.add(new PluginModule());
if (VersionManager.getOnlineUpgrade(config)) {
modules.add(new OnlineUpgrader.Module());
}
modules.add(new RestApiModule());
modules.add(new WorkQueue.Module());
modules.add(new GerritInstanceNameModule());
modules.add(
@ -392,9 +385,9 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
private Module createIndexModule() {
switch (indexType) {
case LUCENE:
return LuceneIndexModule.latestVersionWithOnlineUpgrade(false);
return LuceneIndexModule.latestVersion(false);
case ELASTICSEARCH:
return ElasticIndexModule.latestVersionWithOnlineUpgrade(false);
return ElasticIndexModule.latestVersion(false);
default:
throw new IllegalStateException("unsupported index.type = " + indexType);
}

View File

@ -29,29 +29,24 @@ import org.eclipse.jgit.lib.Config;
public class LuceneIndexModule extends AbstractIndexModule {
public static LuceneIndexModule singleVersionAllLatest(int threads, boolean slave) {
return new LuceneIndexModule(ImmutableMap.of(), threads, false, slave);
return new LuceneIndexModule(ImmutableMap.of(), threads, slave);
}
public static LuceneIndexModule singleVersionWithExplicitVersions(
Map<String, Integer> versions, int threads, boolean slave) {
return new LuceneIndexModule(versions, threads, false, slave);
return new LuceneIndexModule(versions, threads, slave);
}
public static LuceneIndexModule latestVersionWithOnlineUpgrade(boolean slave) {
return new LuceneIndexModule(null, 0, true, slave);
}
public static LuceneIndexModule latestVersionWithoutOnlineUpgrade(boolean slave) {
return new LuceneIndexModule(null, 0, false, slave);
public static LuceneIndexModule latestVersion(boolean slave) {
return new LuceneIndexModule(null, 0, slave);
}
static boolean isInMemoryTest(Config cfg) {
return cfg.getBoolean("index", "lucene", "testInmemory", false);
}
private LuceneIndexModule(
Map<String, Integer> singleVersions, int threads, boolean onlineUpgrade, boolean slave) {
super(singleVersions, threads, onlineUpgrade, slave);
private LuceneIndexModule(Map<String, Integer> singleVersions, int threads, boolean slave) {
super(singleVersions, threads, slave);
}
@Override

View File

@ -81,6 +81,7 @@ import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.group.PeriodicGroupIndexer;
import com.google.gerrit.server.index.IndexModule;
import com.google.gerrit.server.index.IndexModule.IndexType;
import com.google.gerrit.server.index.OnlineUpgrader;
import com.google.gerrit.server.index.VersionManager;
import com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier;
import com.google.gerrit.server.mail.receive.MailReceiver;
@ -401,19 +402,6 @@ public class Daemon extends SiteProgram {
modules.add(new DropWizardMetricMaker.RestModule());
modules.add(new LogFileCompressor.Module());
// Plugin module needs to be inserted *before* the index module.
// There is the concept of LifecycleModule, in Gerrit's own extension
// to Guice, which has these:
// listener().to(SomeClassImplementingLifecycleListener.class);
// and the start() methods of each such listener are executed in the
// order they are declared.
// Makes sure that PluginLoader.start() is executed before the
// LuceneIndexModule.start() so that plugins get loaded and the respective
// Guice modules installed so that the on-line reindexing will happen
// with the proper classes (e.g. group backends, custom Prolog
// predicates) and the associated rules ready to be evaluated.
modules.add(new PluginModule());
// Index module shutdown must happen before work queue shutdown, otherwise
// work queue can get stuck waiting on index futures that will never return.
modules.add(createIndexModule());
@ -449,6 +437,12 @@ public class Daemon extends SiteProgram {
modules.add(new AuditModule());
}
modules.add(new SignedTokenEmailTokenVerifier.Module());
modules.add(new PluginModule());
if (VersionManager.getOnlineUpgrade(config)
// Schema upgrade is handled by OnlineNoteDbMigrator in this case.
&& !migrateToNoteDb()) {
modules.add(new OnlineUpgrader.Module());
}
modules.add(new RestApiModule());
modules.add(new GpgModule(config));
modules.add(new StartupChecks.Module());
@ -517,19 +511,11 @@ public class Daemon extends SiteProgram {
if (luceneModule != null) {
return luceneModule;
}
boolean onlineUpgrade =
VersionManager.getOnlineUpgrade(config)
// Schema upgrade is handled by OnlineNoteDbMigrator in this case.
&& !migrateToNoteDb();
switch (indexType) {
case LUCENE:
return onlineUpgrade
? LuceneIndexModule.latestVersionWithOnlineUpgrade(slave)
: LuceneIndexModule.latestVersionWithoutOnlineUpgrade(slave);
return LuceneIndexModule.latestVersion(slave);
case ELASTICSEARCH:
return onlineUpgrade
? ElasticIndexModule.latestVersionWithOnlineUpgrade(slave)
: ElasticIndexModule.latestVersionWithoutOnlineUpgrade(slave);
return ElasticIndexModule.latestVersion(slave);
default:
throw new IllegalStateException("unsupported index.type = " + indexType);
}

View File

@ -14,8 +14,6 @@
package com.google.gerrit.server.index;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.gerrit.index.IndexConfig;
import com.google.gerrit.index.Schema;
import com.google.gerrit.index.project.ProjectIndex;
@ -35,17 +33,11 @@ public abstract class AbstractIndexModule extends AbstractModule {
private final int threads;
private final Map<String, Integer> singleVersions;
private final boolean onlineUpgrade;
private final boolean slave;
protected AbstractIndexModule(
Map<String, Integer> singleVersions, int threads, boolean onlineUpgrade, boolean slave) {
if (singleVersions != null) {
checkArgument(!onlineUpgrade, "online upgrade is incompatible with single version map");
}
protected AbstractIndexModule(Map<String, Integer> singleVersions, int threads, boolean slave) {
this.singleVersions = singleVersions;
this.threads = threads;
this.onlineUpgrade = onlineUpgrade;
this.slave = slave;
}
@ -113,9 +105,6 @@ public abstract class AbstractIndexModule extends AbstractModule {
Class<? extends VersionManager> versionManagerClass = getVersionManager();
bind(VersionManager.class).to(versionManagerClass);
listener().to(versionManagerClass);
if (onlineUpgrade) {
listener().to(OnlineUpgrader.class);
}
}
}
}

View File

@ -15,10 +15,18 @@
package com.google.gerrit.server.index;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.inject.Inject;
/** Listener to handle upgrading index schema versions at startup. */
public class OnlineUpgrader implements LifecycleListener {
public static class Module extends LifecycleModule {
@Override
protected void configure() {
listener().to(OnlineUpgrader.class);
}
}
private final VersionManager versionManager;
@Inject