Merge "Add an optional flag to force an online reindex"

This commit is contained in:
Hugo Arès
2016-08-03 13:18:35 +00:00
committed by Gerrit Code Review
3 changed files with 15 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ gerrit index start - Start the online indexer
== SYNOPSIS == SYNOPSIS
[verse] [verse]
-- --
_ssh_ -p <port> <host> _gerrit index start_ <INDEX> _ssh_ -p <port> <host> _gerrit index start_ <INDEX> [--force]
-- --
== DESCRIPTION == DESCRIPTION
@@ -33,8 +33,11 @@ This command is intended to be used in scripts.
* changes * changes
* accounts * accounts
--force::
Force an online re-index.
== EXAMPLES == EXAMPLES
Start the online indexer for the changes index: Start the online indexer for the 'changes' index:
---- ----
$ ssh -p 29418 review.example.com gerrit index start changes $ ssh -p 29418 review.example.com gerrit index start changes

View File

@@ -163,11 +163,11 @@ public class LuceneVersionManager implements LifecycleListener {
markNotReady(cfg, def.getName(), versions.values(), write); markNotReady(cfg, def.getName(), versions.values(), write);
int latest = write.get(0).version; int latest = write.get(0).version;
if (onlineUpgrade && latest != search.version) {
OnlineReindexer<K, V, I> reindexer = new OnlineReindexer<>(def, latest); OnlineReindexer<K, V, I> reindexer = new OnlineReindexer<>(def, latest);
reindexers.put(def.getName(), reindexer);
if (onlineUpgrade && latest != search.version) {
synchronized (this) { synchronized (this) {
if (!reindexers.containsKey(def.getName())) { if (!reindexers.containsKey(def.getName())) {
reindexers.put(def.getName(), reindexer);
reindexer.start(); reindexer.start();
} }
} }
@@ -177,14 +177,15 @@ public class LuceneVersionManager implements LifecycleListener {
/** /**
* Start the online reindexer if the current index is not already the latest. * Start the online reindexer if the current index is not already the latest.
* *
* @param force start re-index
* @return true if started, otherwise false. * @return true if started, otherwise false.
* @throws ReindexerAlreadyRunningException * @throws ReindexerAlreadyRunningException
*/ */
public synchronized boolean startReindexer(String name) public synchronized boolean startReindexer(String name, boolean force)
throws ReindexerAlreadyRunningException { throws ReindexerAlreadyRunningException {
OnlineReindexer<?, ?, ?> reindexer = reindexers.get(name); OnlineReindexer<?, ?, ?> reindexer = reindexers.get(name);
validateReindexerNotRunning(reindexer); validateReindexerNotRunning(reindexer);
if (!isCurrentIndexVersionLatest(name, reindexer)) { if (force || !isCurrentIndexVersionLatest(name, reindexer)) {
reindexer.start(); reindexer.start();
return true; return true;
} }

View File

@@ -23,11 +23,15 @@ import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER) @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
@CommandMetaData(name = "start", description = "Start the online reindexer") @CommandMetaData(name = "start", description = "Start the online reindexer")
public class IndexStartCommand extends SshCommand { public class IndexStartCommand extends SshCommand {
@Option(name = "--force", usage = "force a re-index")
private boolean force;
@Argument(index = 0, required = true, metaVar = "INDEX", @Argument(index = 0, required = true, metaVar = "INDEX",
usage = "index name to start") usage = "index name to start")
private String name; private String name;
@@ -38,7 +42,7 @@ public class IndexStartCommand extends SshCommand {
@Override @Override
protected void run() throws UnloggedFailure { protected void run() throws UnloggedFailure {
try { try {
if (luceneVersionManager.startReindexer(name)) { if (luceneVersionManager.startReindexer(name, force)) {
stdout.println("Reindexer started"); stdout.println("Reindexer started");
} else { } else {
stdout.println("Nothing to reindex, index is already the latest version"); stdout.println("Nothing to reindex, index is already the latest version");