init: Invoke reindex only once.
Instead of calling reindex multiple times with specific index each
time, call it once by specifying all the indices at once. This would
help reduce the common console logs outputed by reindex command.
Change-Id: Ia634d97243e762b69295031d3b39c0cc6682298d
diff --git a/java/com/google/gerrit/pgm/Init.java b/java/com/google/gerrit/pgm/Init.java
index 4e62a0f..5c397d1 100644
--- a/java/com/google/gerrit/pgm/Init.java
+++ b/java/com/google/gerrit/pgm/Init.java
@@ -18,6 +18,7 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gerrit.common.IoUtil;
import com.google.gerrit.common.PageLinks;
@@ -157,11 +158,13 @@
modules.add(new GerritServerConfigModule());
Guice.createInjector(modules).injectMembers(this);
if (!ReplicaUtil.isReplica(run.flags.cfg)) {
+ List<String> indicesToReindex = new ArrayList<>();
for (SchemaDefinitions<?> schemaDef : schemaDefs) {
if (!indexStatus.exists(schemaDef.getName())) {
- reindex(schemaDef);
+ indicesToReindex.add(schemaDef.getName());
}
}
+ reindex(indicesToReindex);
}
start(run);
}
@@ -274,17 +277,20 @@
}
}
- private void reindex(SchemaDefinitions<?> schemaDef) throws Exception {
+ private void reindex(List<String> indices) throws Exception {
+ if (indices.isEmpty()) {
+ return;
+ }
List<String> reindexArgs =
- ImmutableList.of(
- "--site-path",
- getSitePath().toString(),
- "--threads",
- Integer.toString(1),
- "--index",
- schemaDef.getName());
+ Lists.newArrayList(
+ "--site-path", getSitePath().toString(), "--threads", Integer.toString(1));
+ for (String index : indices) {
+ reindexArgs.add("--index");
+ reindexArgs.add(index);
+ }
+
getConsoleUI()
- .message(String.format("Init complete, reindexing %s with:", schemaDef.getName()));
+ .message(String.format("Init complete, reindexing %s with:", String.join(",", indices)));
getConsoleUI().message(" reindex " + reindexArgs.stream().collect(joining(" ")));
Reindex reindexPgm = new Reindex();
reindexPgm.main(reindexArgs.stream().toArray(String[]::new));