Add ssh command to activate the latest index
In case the online indexer fails, this allows the admins to activate the latest index. Change-Id: I59ebf2bce02a599b87d0f7771fc806ff64a3ba64
This commit is contained in:
32
Documentation/cmd-index-activate.txt
Normal file
32
Documentation/cmd-index-activate.txt
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
= gerrit index activate
|
||||||
|
|
||||||
|
== NAME
|
||||||
|
gerrit index activate - Activate the latest index version available
|
||||||
|
|
||||||
|
== SYNOPSIS
|
||||||
|
--
|
||||||
|
'ssh' -p @SSH_PORT@ @SSH_HOST@ 'gerrit index activate'
|
||||||
|
--
|
||||||
|
|
||||||
|
== DESCRIPTION
|
||||||
|
Gerrit supports online index schema upgrades. When starting Gerrit for the first
|
||||||
|
time after an upgrade that requires an index schema upgrade, the online indexer
|
||||||
|
will be started. If the schema upgrade is a success, the new index will be
|
||||||
|
activated and if it fails, a statement in the logs will be printed with the
|
||||||
|
number of successfully/failed indexed changes.
|
||||||
|
|
||||||
|
This command allows to activate the latest index even if there were some
|
||||||
|
failures.
|
||||||
|
|
||||||
|
== ACCESS
|
||||||
|
Caller must be a member of the privileged 'Administrators' group.
|
||||||
|
|
||||||
|
== SCRIPTING
|
||||||
|
This command is intended to be used in scripts.
|
||||||
|
|
||||||
|
GERRIT
|
||||||
|
------
|
||||||
|
Part of link:index.html[Gerrit Code Review]
|
||||||
|
|
||||||
|
SEARCHBOX
|
||||||
|
---------
|
@@ -117,6 +117,9 @@ link:cmd-gc.html[gerrit gc]::
|
|||||||
link:cmd-gsql.html[gerrit gsql]::
|
link:cmd-gsql.html[gerrit gsql]::
|
||||||
Administrative interface to active database.
|
Administrative interface to active database.
|
||||||
|
|
||||||
|
link:cmd-index-index.html[gerrit index activate]::
|
||||||
|
Activate the latest index version available.
|
||||||
|
|
||||||
link:cmd-index-start.html[gerrit index start]::
|
link:cmd-index-start.html[gerrit index start]::
|
||||||
Start the online indexer.
|
Start the online indexer.
|
||||||
|
|
||||||
|
@@ -182,6 +182,22 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activate the latest index if the current index is not already the latest.
|
||||||
|
*
|
||||||
|
* @return true if index was activate, otherwise false.
|
||||||
|
* @throws ReindexerAlreadyRunningException
|
||||||
|
*/
|
||||||
|
public synchronized boolean activateLatestIndex()
|
||||||
|
throws ReindexerAlreadyRunningException {
|
||||||
|
validateReindexerNotRunning();
|
||||||
|
if (!isCurrentIndexVersionLatest()) {
|
||||||
|
reindexer.activateIndex();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isCurrentIndexVersionLatest() {
|
private boolean isCurrentIndexVersionLatest() {
|
||||||
return reindexer == null
|
return reindexer == null
|
||||||
|| reindexer.getVersion() == indexes.getSearchIndex().getSchema()
|
|| reindexer.getVersion() == indexes.getSearchIndex().getSchema()
|
||||||
|
@@ -43,6 +43,7 @@ public class OnlineReindexer {
|
|||||||
private final SiteIndexer batchIndexer;
|
private final SiteIndexer batchIndexer;
|
||||||
private final ProjectCache projectCache;
|
private final ProjectCache projectCache;
|
||||||
private final int version;
|
private final int version;
|
||||||
|
private ChangeIndex index;
|
||||||
private final AtomicBoolean running = new AtomicBoolean();
|
private final AtomicBoolean running = new AtomicBoolean();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -88,7 +89,7 @@ public class OnlineReindexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reindex() {
|
private void reindex() {
|
||||||
ChangeIndex index = checkNotNull(indexes.getWriteIndex(version),
|
index = checkNotNull(indexes.getWriteIndex(version),
|
||||||
"not an active write schema version: %s", version);
|
"not an active write schema version: %s", version);
|
||||||
log.info("Starting online reindex from schema version {} to {}",
|
log.info("Starting online reindex from schema version {} to {}",
|
||||||
version(indexes.getSearchIndex()), version(index));
|
version(indexes.getSearchIndex()), version(index));
|
||||||
@@ -100,9 +101,13 @@ public class OnlineReindexer {
|
|||||||
version(index), result.doneCount(), result.failedCount());
|
version(index), result.doneCount(), result.failedCount());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("Reindex to version {} complete", version(index));
|
||||||
|
activateIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
void activateIndex() {
|
||||||
indexes.setSearchIndex(index);
|
indexes.setSearchIndex(index);
|
||||||
log.info("Reindex complete, using schema version {}", version(index));
|
log.info("Using schema version {}", version(index));
|
||||||
try {
|
try {
|
||||||
index.markReady(true);
|
index.markReady(true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -59,6 +59,7 @@ public class DefaultCommandModule extends CommandModule {
|
|||||||
command(gerrit, GarbageCollectionCommand.class);
|
command(gerrit, GarbageCollectionCommand.class);
|
||||||
|
|
||||||
command(index).toProvider(new DispatchCommandProvider(index));
|
command(index).toProvider(new DispatchCommandProvider(index));
|
||||||
|
command(index, IndexActivateCommand.class);
|
||||||
command(index, IndexStartCommand.class);
|
command(index, IndexStartCommand.class);
|
||||||
|
|
||||||
command(gerrit, "plugin").toProvider(new DispatchCommandProvider(plugin));
|
command(gerrit, "plugin").toProvider(new DispatchCommandProvider(plugin));
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (C) 2015 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.sshd.commands;
|
||||||
|
|
||||||
|
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
|
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||||
|
import com.google.gerrit.lucene.LuceneVersionManager;
|
||||||
|
import com.google.gerrit.lucene.ReindexerAlreadyRunningException;
|
||||||
|
import com.google.gerrit.sshd.CommandMetaData;
|
||||||
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||||
|
@CommandMetaData(name = "activate",
|
||||||
|
description = "Activate the latest index version available",
|
||||||
|
runsAt = MASTER)
|
||||||
|
public class IndexActivateCommand extends SshCommand {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private LuceneVersionManager luceneVersionManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void run() throws UnloggedFailure {
|
||||||
|
try {
|
||||||
|
if (luceneVersionManager.activateLatestIndex()) {
|
||||||
|
stdout.println("Activated latest index version");
|
||||||
|
} else {
|
||||||
|
stdout.println("Not activating index, already using latest version");
|
||||||
|
}
|
||||||
|
} catch (ReindexerAlreadyRunningException e) {
|
||||||
|
throw new UnloggedFailure("Failed to activate latest index: "
|
||||||
|
+ e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user