Merge branch 'stable-2.15'

* stable-2.15:
  Fix binding of VersionManager
  Document gerrit#serverId configuration in gerrit.config
  Release 2.15.1
  GerritServerId: Update comment for correct location of server Id
  Index{Activate,Start}Command: Include name in error message when unknown
  Index start/activate command: fix unknown name use
  Index start/activate commands: fix Elastic support

Change-Id: I9ad569c653b9f14a33c3da008685d5a96abd2348
This commit is contained in:
David Pursehouse
2018-04-11 01:45:25 +09:00
7 changed files with 45 additions and 13 deletions

View File

@@ -2167,6 +2167,19 @@ gerrit.ui is an enabled UI.
Defaults to GWT (if GWT is enabled) or POLYGERRIT (if POLYGERRIT is
enabled and GWT is disabled)
[[gerrit.serverId]]gerrit.serverId::
+
Used by NoteDb to, amongst other things, identify author identities from
per-server specific account IDs.
+
If this value is not set on startup it is automatically set to a random UUID.
+
[NOTE]
If this value doesn't match the serverId used when creating an already existing
NoteDb, Gerrit will not be able to use that instance of NoteDb. The serverId
used to create the NoteDb will show in the resulting exception message in case
the value differs.
[[gitweb]]
=== Section gitweb

View File

@@ -96,6 +96,7 @@ public class ElasticIndexModule extends AbstractModule {
} else {
install(new SingleVersionModule(singleVersions));
}
bind(VersionManager.class).to(ElasticVersionManager.class);
}
@SuppressWarnings("unused")
@@ -112,7 +113,6 @@ public class ElasticIndexModule extends AbstractModule {
private class MultiVersionModule extends LifecycleModule {
@Override
public void configure() {
bind(VersionManager.class).to(ElasticVersionManager.class);
listener().to(ElasticVersionManager.class);
if (onlineUpgrade) {
listener().to(OnlineUpgrader.class);

View File

@@ -106,6 +106,7 @@ public class LuceneIndexModule extends AbstractModule {
} else {
install(new SingleVersionModule(singleVersions));
}
bind(VersionManager.class).to(LuceneVersionManager.class);
}
@SuppressWarnings("unused")
@@ -124,7 +125,6 @@ public class LuceneIndexModule extends AbstractModule {
private class MultiVersionModule extends LifecycleModule {
@Override
public void configure() {
bind(VersionManager.class).to(LuceneVersionManager.class);
listener().to(LuceneVersionManager.class);
if (onlineUpgrade) {
listener().to(OnlineUpgrader.class);

View File

@@ -22,7 +22,8 @@ import java.lang.annotation.Retention;
/**
* Marker on a string holding a unique identifier for the server.
*
* <p>This value is generated on first use and stored in {@code $site_path/etc/uuid}.
* <p>This value is generated on first use and stored in {@code gerrit.serverId} in {@code
* gerrit.config}.
*/
@Retention(RUNTIME)
@BindingAnnotation

View File

@@ -137,6 +137,16 @@ public abstract class VersionManager implements LifecycleListener {
return false;
}
/**
* Tells if an index with this name is currently known or not.
*
* @param name index name
* @return true if index is known and can be used, otherwise false.
*/
public boolean isKnownIndex(String name) {
return defs.get(name) != null;
}
protected <K, V, I extends Index<K, V>> void initIndex(
IndexDefinition<K, V, I> def, GerritIndexStatus cfg) {
TreeMap<Integer, Version<V>> versions = scanVersions(def, cfg);

View File

@@ -16,8 +16,8 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.lucene.LuceneVersionManager;
import com.google.gerrit.server.index.ReindexerAlreadyRunningException;
import com.google.gerrit.server.index.VersionManager;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject;
@@ -30,15 +30,19 @@ public class IndexActivateCommand extends SshCommand {
@Argument(index = 0, required = true, metaVar = "INDEX", usage = "index name to activate")
private String name;
@Inject private LuceneVersionManager luceneVersionManager;
@Inject private VersionManager versionManager;
@Override
protected void run() throws UnloggedFailure {
try {
if (luceneVersionManager.activateLatestIndex(name)) {
stdout.println("Activated latest index version");
if (versionManager.isKnownIndex(name)) {
if (versionManager.activateLatestIndex(name)) {
stdout.println("Activated latest index version");
} else {
stdout.println("Not activating index, already using latest version");
}
} else {
stdout.println("Not activating index, already using latest version");
stderr.println(String.format("Cannot activate index %s: unknown", name));
}
} catch (ReindexerAlreadyRunningException e) {
throw die("Failed to activate latest index: " + e.getMessage());

View File

@@ -16,8 +16,8 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.lucene.LuceneVersionManager;
import com.google.gerrit.server.index.ReindexerAlreadyRunningException;
import com.google.gerrit.server.index.VersionManager;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject;
@@ -34,15 +34,19 @@ public class IndexStartCommand extends SshCommand {
@Argument(index = 0, required = true, metaVar = "INDEX", usage = "index name to start")
private String name;
@Inject private LuceneVersionManager luceneVersionManager;
@Inject private VersionManager versionManager;
@Override
protected void run() throws UnloggedFailure {
try {
if (luceneVersionManager.startReindexer(name, force)) {
stdout.println("Reindexer started");
if (versionManager.isKnownIndex(name)) {
if (versionManager.startReindexer(name, force)) {
stdout.println("Reindexer started");
} else {
stdout.println("Nothing to reindex, index is already the latest version");
}
} else {
stdout.println("Nothing to reindex, index is already the latest version");
stderr.println(String.format("Cannot reindex %s: unknown", name));
}
} catch (ReindexerAlreadyRunningException e) {
throw die("Failed to start reindexer: " + e.getMessage());