Simplify Init for Elasticsearch
Perform reindex operation for all indexes on init for elasticsearch index. This change allows for starting an elasticsearch index with only the init command, similar to a Lucene index. Remove reindex operation on ElasticReindexIT, since with this change performing a reindex manually is no longer needed. Test plan: Run InitIT, ElasticReindexIT and ReindexIT. Feature: Issue 12704 Change-Id: If7741771e25a6063c5116ab2bce39fbe0e0ea93b
This commit is contained in:
@@ -32,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;
|
||||||
@@ -90,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);
|
||||||
@@ -104,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) {
|
||||||
@@ -133,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() {
|
||||||
@@ -147,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)) {
|
||||||
reindex(ProjectSchemaDefinitions.INSTANCE);
|
for (SchemaDefinitions<?> schemaDef : schemaDefs) {
|
||||||
|
if (!indexStatus.exists(schemaDef.getName())) {
|
||||||
|
reindex(schemaDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
start(run);
|
start(run);
|
||||||
}
|
}
|
||||||
|
@@ -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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user