Merge branch 'stable-3.1' into stable-3.2

* stable-3.1:
  Simplify Init for Elasticsearch
  Refactor reindexProjects in Init to be general
  Avoid auto-reindex of projects during init when unneeded

Change-Id: Ib42a890ab15177803ad0eb20978c4038e11da15f
This commit is contained in:
Hamza Kaced
2020-06-12 14:06:57 -04:00
2 changed files with 22 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ import com.google.common.collect.Sets;
import com.google.gerrit.common.IoUtil; import com.google.gerrit.common.IoUtil;
import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.PluginData; import com.google.gerrit.common.PluginData;
import com.google.gerrit.index.SchemaDefinitions;
import com.google.gerrit.index.project.ProjectSchemaDefinitions; import com.google.gerrit.index.project.ProjectSchemaDefinitions;
import com.google.gerrit.pgm.init.BaseInit; import com.google.gerrit.pgm.init.BaseInit;
import com.google.gerrit.pgm.init.Browser; import com.google.gerrit.pgm.init.Browser;
@@ -31,6 +32,9 @@ import com.google.gerrit.pgm.util.ErrorLogFile;
import com.google.gerrit.server.config.GerritServerConfigModule; import com.google.gerrit.server.config.GerritServerConfigModule;
import com.google.gerrit.server.config.SitePath; import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.index.GerritIndexStatus; import com.google.gerrit.server.index.GerritIndexStatus;
import com.google.gerrit.server.index.account.AccountSchemaDefinitions;
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
import com.google.gerrit.server.index.group.GroupSchemaDefinitions;
import com.google.gerrit.server.ioutil.HostPlatform; import com.google.gerrit.server.ioutil.HostPlatform;
import com.google.gerrit.server.securestore.SecureStoreClassName; import com.google.gerrit.server.securestore.SecureStoreClassName;
import com.google.gerrit.server.util.ReplicaUtil; import com.google.gerrit.server.util.ReplicaUtil;
@@ -89,7 +93,7 @@ public class Init extends BaseInit {
@Inject Browser browser; @Inject Browser browser;
private boolean projectsIndexExists; private GerritIndexStatus indexStatus;
public Init() { public Init() {
super(new WarDistribution(), null); super(new WarDistribution(), null);
@@ -103,7 +107,7 @@ public class Init extends BaseInit {
@Override @Override
protected boolean beforeInit(SiteInit init) throws Exception { protected boolean beforeInit(SiteInit init) throws Exception {
projectsIndexExists = new GerritIndexStatus(init.site).exists(ProjectSchemaDefinitions.NAME); indexStatus = new GerritIndexStatus(init.site);
ErrorLogFile.errorOnlyConsole(); ErrorLogFile.errorOnlyConsole();
if (!skipPlugins) { if (!skipPlugins) {
@@ -132,6 +136,12 @@ public class Init extends BaseInit {
@Override @Override
protected void afterInit(SiteRun run) throws Exception { protected void afterInit(SiteRun run) throws Exception {
List<SchemaDefinitions<?>> schemaDefs =
ImmutableList.of(
AccountSchemaDefinitions.INSTANCE,
ChangeSchemaDefinitions.INSTANCE,
GroupSchemaDefinitions.INSTANCE,
ProjectSchemaDefinitions.INSTANCE);
List<Module> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
modules.add( modules.add(
new AbstractModule() { new AbstractModule() {
@@ -146,8 +156,12 @@ public class Init extends BaseInit {
}); });
modules.add(new GerritServerConfigModule()); modules.add(new GerritServerConfigModule());
Guice.createInjector(modules).injectMembers(this); Guice.createInjector(modules).injectMembers(this);
if (!ReplicaUtil.isReplica(run.flags.cfg) && !projectsIndexExists) { if (!ReplicaUtil.isReplica(run.flags.cfg)) {
reindexProjects(); for (SchemaDefinitions<?> schemaDef : schemaDefs) {
if (!indexStatus.exists(schemaDef.getName())) {
reindex(schemaDef);
}
}
} }
start(run); start(run);
} }
@@ -260,8 +274,7 @@ public class Init extends BaseInit {
} }
} }
private void reindexProjects() throws Exception { private void reindex(SchemaDefinitions<?> schemaDef) throws Exception {
// Reindex all projects, so that we bootstrap the project index for new installations
List<String> reindexArgs = List<String> reindexArgs =
ImmutableList.of( ImmutableList.of(
"--site-path", "--site-path",
@@ -269,8 +282,9 @@ public class Init extends BaseInit {
"--threads", "--threads",
Integer.toString(1), Integer.toString(1),
"--index", "--index",
ProjectSchemaDefinitions.NAME); schemaDef.getName());
getConsoleUI().message("Init complete, reindexing projects with:"); getConsoleUI()
.message(String.format("Init complete, reindexing %s with:", schemaDef.getName()));
getConsoleUI().message(" reindex " + reindexArgs.stream().collect(joining(" "))); getConsoleUI().message(" reindex " + reindexArgs.stream().collect(joining(" ")));
Reindex reindexPgm = new Reindex(); Reindex reindexPgm = new Reindex();
reindexPgm.main(reindexArgs.stream().toArray(String[]::new)); reindexPgm.main(reindexArgs.stream().toArray(String[]::new));

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.elasticsearch.ElasticVersion;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.inject.Injector; import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.Before;
public class ElasticReindexIT extends AbstractReindexTests { public class ElasticReindexIT extends AbstractReindexTests {
@@ -39,10 +38,4 @@ public class ElasticReindexIT extends AbstractReindexTests {
public void configureIndex(Injector injector) { public void configureIndex(Injector injector) {
createAllIndexes(injector); createAllIndexes(injector);
} }
@Before
public void reindexFirstSinceElastic() throws Exception {
assertServerStartupFails();
runGerrit("reindex", "-d", sitePaths.site_path.toString(), "--show-stack-trace");
}
} }