Reindex: Add --list option to list available indices

Change-Id: I3d46d39d9cc9751489cb348e22c63c60c2f1dbd1
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
David Ostrovsky
2016-03-20 12:00:40 +01:00
committed by Edwin Kempin
parent d1969dec32
commit bba1994755
2 changed files with 22 additions and 4 deletions

View File

@@ -24,6 +24,9 @@ Rebuilds the secondary index.
--dry-run::
Dry run. Don't write anything to index.
--list::
List available index names.
== CONTEXT
The secondary index must be enabled. See
link:config-gerrit.html#index.type[index.type].

View File

@@ -60,6 +60,9 @@ public class Reindex extends SiteProgram {
@Option(name = "--verbose", usage = "Output debug information for each change")
private boolean verbose;
@Option(name = "--list", usage = "List supported indices and exit")
private boolean list;
private Injector dbInjector;
private Injector sysInjector;
private Config globalConfig;
@@ -88,10 +91,7 @@ public class Reindex extends SiteProgram {
sysInjector.injectMembers(this);
try {
boolean ok = true;
for (IndexDefinition<?, ?, ?> def : indexDefs) {
ok &= reindex(def);
}
boolean ok = list ? list() : reindex();
return ok ? 0 : 1;
} catch (Exception e) {
throw die(e.getMessage(), e);
@@ -101,6 +101,21 @@ public class Reindex extends SiteProgram {
}
}
private boolean list() {
for (IndexDefinition<?, ?, ?> def : indexDefs) {
System.out.format("%s\n", def.getName());
}
return true;
}
private boolean reindex() throws IOException {
boolean ok = true;
for (IndexDefinition<?, ?, ?> def : indexDefs) {
ok &= reindex(def);
}
return ok;
}
private void checkNotSlaveMode() throws Die {
if (globalConfig.getBoolean("container", "slave", false)) {
throw die("Cannot run reindex in slave mode");