Revert "Support generic indexes in LuceneVersionManager"
This reverts commit 1762bacf0cab5b2138432032177339a62f502dc7. This seems to have broken master. New changes are not shown on the ChangeScreen when pushed. git-bisect indicates that Id6c58a595086e7dc22cbc7302169d96c4ccf1aa4 caused the problem. Change-Id: I5d56a1630224242078b2109941adccc6d6d8d721
This commit is contained in:
parent
1762bacf0c
commit
6247b52f41
@ -5,7 +5,7 @@ gerrit index activate - Activate the latest index version available
|
|||||||
|
|
||||||
== SYNOPSIS
|
== SYNOPSIS
|
||||||
--
|
--
|
||||||
'ssh' -p @SSH_PORT@ @SSH_HOST@ 'gerrit index activate <index>'
|
'ssh' -p @SSH_PORT@ @SSH_HOST@ 'gerrit index activate'
|
||||||
--
|
--
|
||||||
|
|
||||||
== DESCRIPTION
|
== DESCRIPTION
|
||||||
@ -18,9 +18,6 @@ number of successfully/failed indexed changes.
|
|||||||
This command allows to activate the latest index even if there were some
|
This command allows to activate the latest index even if there were some
|
||||||
failures.
|
failures.
|
||||||
|
|
||||||
The <index> argument controls which secondary index is activated. Currently, the
|
|
||||||
only supported value is "changes".
|
|
||||||
|
|
||||||
== ACCESS
|
== ACCESS
|
||||||
Caller must be a member of the privileged 'Administrators' group.
|
Caller must be a member of the privileged 'Administrators' group.
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ gerrit index start - Start the online indexer
|
|||||||
|
|
||||||
== SYNOPSIS
|
== SYNOPSIS
|
||||||
--
|
--
|
||||||
'ssh' -p @SSH_PORT@ @SSH_HOST@ 'gerrit index start <index>'
|
'ssh' -p @SSH_PORT@ @SSH_HOST@ 'gerrit index start'
|
||||||
--
|
--
|
||||||
|
|
||||||
== DESCRIPTION
|
== DESCRIPTION
|
||||||
@ -19,9 +19,6 @@ This command allows restarting the online indexer without having to restart
|
|||||||
Gerrit. This command will not start the indexer if it is already running or if
|
Gerrit. This command will not start the indexer if it is already running or if
|
||||||
the active index is the latest.
|
the active index is the latest.
|
||||||
|
|
||||||
The <index> argument controls which secondary index is started. Currently, the
|
|
||||||
only supported value is "changes".
|
|
||||||
|
|
||||||
== ACCESS
|
== ACCESS
|
||||||
Caller must be a member of the privileged 'Administrators' group.
|
Caller must be a member of the privileged 'Administrators' group.
|
||||||
|
|
||||||
|
@ -20,14 +20,15 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||||
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gerrit.server.index.Index;
|
|
||||||
import com.google.gerrit.server.index.IndexCollection;
|
|
||||||
import com.google.gerrit.server.index.IndexDefinition;
|
|
||||||
import com.google.gerrit.server.index.IndexDefinition.IndexFactory;
|
|
||||||
import com.google.gerrit.server.index.OnlineReindexer;
|
import com.google.gerrit.server.index.OnlineReindexer;
|
||||||
import com.google.gerrit.server.index.Schema;
|
import com.google.gerrit.server.index.Schema;
|
||||||
|
import com.google.gerrit.server.index.change.ChangeIndex;
|
||||||
|
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||||
|
import com.google.gerrit.server.index.change.ChangeIndexDefinition;
|
||||||
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.ProvisionException;
|
import com.google.inject.ProvisionException;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@ -45,7 +46,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -55,13 +55,13 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
|
|
||||||
static final String CHANGES_PREFIX = "changes_";
|
static final String CHANGES_PREFIX = "changes_";
|
||||||
|
|
||||||
private static class Version<V> {
|
private static class Version {
|
||||||
private final Schema<V> schema;
|
private final Schema<ChangeData> schema;
|
||||||
private final int version;
|
private final int version;
|
||||||
private final boolean exists;
|
private final boolean exists;
|
||||||
private final boolean ready;
|
private final boolean ready;
|
||||||
|
|
||||||
private Version(Schema<V> schema, int version, boolean exists,
|
private Version(Schema<ChangeData> schema, int version, boolean exists,
|
||||||
boolean ready) {
|
boolean ready) {
|
||||||
checkArgument(schema == null || schema.getVersion() == version);
|
checkArgument(schema == null || schema.getVersion() == version);
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
@ -94,32 +94,33 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final SitePaths sitePaths;
|
private final SitePaths sitePaths;
|
||||||
private final Map<String, IndexDefinition<?, ?, ?>> defs;
|
private final LuceneChangeIndex.Factory indexFactory;
|
||||||
private final Map<String, OnlineReindexer<?, ?, ?>> reindexers;
|
private final ChangeIndexCollection indexes;
|
||||||
|
private final ChangeIndexDefinition changeDef;
|
||||||
private final boolean onlineUpgrade;
|
private final boolean onlineUpgrade;
|
||||||
private final String runReindexMsg;
|
private OnlineReindexer<Change.Id, ChangeData, ChangeIndex> reindexer;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LuceneVersionManager(
|
LuceneVersionManager(
|
||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
SitePaths sitePaths,
|
SitePaths sitePaths,
|
||||||
Collection<IndexDefinition<?, ?, ?>> defs) {
|
LuceneChangeIndex.Factory indexFactory,
|
||||||
|
ChangeIndexCollection indexes,
|
||||||
|
ChangeIndexDefinition changeDef) {
|
||||||
this.sitePaths = sitePaths;
|
this.sitePaths = sitePaths;
|
||||||
this.defs = Maps.newHashMapWithExpectedSize(defs.size());
|
this.indexFactory = indexFactory;
|
||||||
for (IndexDefinition<?, ?, ?> def : defs) {
|
this.indexes = indexes;
|
||||||
this.defs.put(def.getName(), def);
|
this.changeDef = changeDef;
|
||||||
}
|
this.onlineUpgrade = cfg.getBoolean("index", null, "onlineUpgrade", true);
|
||||||
|
|
||||||
reindexers = Maps.newHashMapWithExpectedSize(defs.size());
|
|
||||||
onlineUpgrade = cfg.getBoolean("index", null, "onlineUpgrade", true);
|
|
||||||
runReindexMsg =
|
|
||||||
"No index versions ready; run java -jar " +
|
|
||||||
sitePaths.gerrit_war.toAbsolutePath() +
|
|
||||||
" reindex";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
String runReindex =
|
||||||
|
"No index versions ready; run java -jar " +
|
||||||
|
sitePaths.gerrit_war.toAbsolutePath() +
|
||||||
|
" reindex";
|
||||||
|
|
||||||
FileBasedConfig cfg;
|
FileBasedConfig cfg;
|
||||||
try {
|
try {
|
||||||
cfg = loadGerritIndexConfig(sitePaths);
|
cfg = loadGerritIndexConfig(sitePaths);
|
||||||
@ -128,25 +129,18 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Files.exists(sitePaths.index_dir)) {
|
if (!Files.exists(sitePaths.index_dir)) {
|
||||||
throw new ProvisionException(runReindexMsg);
|
throw new ProvisionException(runReindex);
|
||||||
} else if (!Files.exists(sitePaths.index_dir)) {
|
} else if (!Files.exists(sitePaths.index_dir)) {
|
||||||
log.warn("Not a directory: %s", sitePaths.index_dir.toAbsolutePath());
|
log.warn("Not a directory: %s", sitePaths.index_dir.toAbsolutePath());
|
||||||
throw new ProvisionException(runReindexMsg);
|
throw new ProvisionException(runReindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IndexDefinition<?, ?, ?> def : defs.values()) {
|
TreeMap<Integer, Version> versions = scanVersions(cfg);
|
||||||
initIndex(def, cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private <K, V, I extends Index<K, V>> void initIndex(
|
|
||||||
IndexDefinition<K, V, I> def, FileBasedConfig cfg) {
|
|
||||||
TreeMap<Integer, Version<V>> versions = scanVersions(def, cfg);
|
|
||||||
// Search from the most recent ready version.
|
// Search from the most recent ready version.
|
||||||
// Write to the most recent ready version and the most recent version.
|
// Write to the most recent ready version and the most recent version.
|
||||||
Version<V> search = null;
|
Version search = null;
|
||||||
List<Version<V>> write = Lists.newArrayListWithCapacity(2);
|
List<Version> write = Lists.newArrayListWithCapacity(2);
|
||||||
for (Version<V> v : versions.descendingMap().values()) {
|
for (Version v : versions.descendingMap().values()) {
|
||||||
if (v.schema == null) {
|
if (v.schema == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -162,35 +156,27 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (search == null) {
|
if (search == null) {
|
||||||
throw new ProvisionException(runReindexMsg);
|
throw new ProvisionException(runReindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexFactory<K, V, I> factory = def.getIndexFactory();
|
markNotReady(cfg, versions.values(), write);
|
||||||
I searchIndex = factory.create(search.schema);
|
LuceneChangeIndex searchIndex =
|
||||||
IndexCollection<K, V, I> indexes = def.getIndexCollection();
|
(LuceneChangeIndex) indexFactory.create(search.schema);
|
||||||
indexes.setSearchIndex(searchIndex);
|
indexes.setSearchIndex(searchIndex);
|
||||||
for (Version<V> v : write) {
|
for (Version v : write) {
|
||||||
if (v.schema != null) {
|
if (v.schema != null) {
|
||||||
if (v.version != search.version) {
|
if (v.version != search.version) {
|
||||||
indexes.addWriteIndex(factory.create(v.schema));
|
indexes.addWriteIndex(indexFactory.create(v.schema));
|
||||||
|
} else {
|
||||||
|
indexes.addWriteIndex(searchIndex);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
indexes.addWriteIndex(searchIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: include index name.
|
|
||||||
markNotReady(cfg, versions.values(), write);
|
|
||||||
|
|
||||||
int latest = write.get(0).version;
|
int latest = write.get(0).version;
|
||||||
if (onlineUpgrade && latest != search.version) {
|
if (onlineUpgrade && latest != search.version) {
|
||||||
OnlineReindexer<K, V, I> reindexer = new OnlineReindexer<>(def, latest);
|
reindexer = new OnlineReindexer<>(changeDef, latest);
|
||||||
synchronized (this) {
|
reindexer.start();
|
||||||
if (!reindexers.containsKey(def.getName())) {
|
|
||||||
reindexers.put(def.getName(), reindexer);
|
|
||||||
reindexer.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +186,10 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
* @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()
|
||||||
throws ReindexerAlreadyRunningException {
|
throws ReindexerAlreadyRunningException {
|
||||||
OnlineReindexer<?, ?, ?> reindexer = reindexers.get(name);
|
validateReindexerNotRunning();
|
||||||
validateReindexerNotRunning(reindexer);
|
if (!isCurrentIndexVersionLatest()) {
|
||||||
if (!isCurrentIndexVersionLatest(name, reindexer)) {
|
|
||||||
reindexer.start();
|
reindexer.start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -217,56 +202,49 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
* @return true if index was activate, otherwise false.
|
* @return true if index was activate, otherwise false.
|
||||||
* @throws ReindexerAlreadyRunningException
|
* @throws ReindexerAlreadyRunningException
|
||||||
*/
|
*/
|
||||||
public synchronized boolean activateLatestIndex(String name)
|
public synchronized boolean activateLatestIndex()
|
||||||
throws ReindexerAlreadyRunningException {
|
throws ReindexerAlreadyRunningException {
|
||||||
OnlineReindexer<?, ?, ?> reindexer = reindexers.get(name);
|
validateReindexerNotRunning();
|
||||||
validateReindexerNotRunning(reindexer);
|
if (!isCurrentIndexVersionLatest()) {
|
||||||
if (!isCurrentIndexVersionLatest(name, reindexer)) {
|
|
||||||
reindexer.activateIndex();
|
reindexer.activateIndex();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCurrentIndexVersionLatest(
|
private boolean isCurrentIndexVersionLatest() {
|
||||||
String name, OnlineReindexer<?, ?, ?> reindexer) {
|
|
||||||
int readVersion = defs.get(name).getIndexCollection().getSearchIndex()
|
|
||||||
.getSchema().getVersion();
|
|
||||||
return reindexer == null
|
return reindexer == null
|
||||||
|| reindexer.getVersion() == readVersion;
|
|| reindexer.getVersion() == indexes.getSearchIndex().getSchema()
|
||||||
|
.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateReindexerNotRunning(
|
private void validateReindexerNotRunning()
|
||||||
OnlineReindexer<?, ?, ?> reindexer)
|
|
||||||
throws ReindexerAlreadyRunningException {
|
throws ReindexerAlreadyRunningException {
|
||||||
if (reindexer != null && reindexer.isRunning()) {
|
if (reindexer != null && reindexer.isRunning()) {
|
||||||
throw new ReindexerAlreadyRunningException();
|
throw new ReindexerAlreadyRunningException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <K, V, I extends Index<K, V>> TreeMap<Integer, Version<V>>
|
private TreeMap<Integer, Version> scanVersions(Config cfg) {
|
||||||
scanVersions(IndexDefinition<K, V, I> def, Config cfg) {
|
TreeMap<Integer, Version> versions = Maps.newTreeMap();
|
||||||
TreeMap<Integer, Version<V>> versions = Maps.newTreeMap();
|
for (Schema<ChangeData> schema : changeDef.getSchemas().values()) {
|
||||||
for (Schema<V> schema : def.getSchemas().values()) {
|
Path p = getDir(sitePaths, CHANGES_PREFIX, schema);
|
||||||
// This part is Lucene-specific.
|
|
||||||
Path p = getDir(sitePaths, def.getName(), schema);
|
|
||||||
boolean isDir = Files.isDirectory(p);
|
boolean isDir = Files.isDirectory(p);
|
||||||
if (Files.exists(p) && !isDir) {
|
if (Files.exists(p) && !isDir) {
|
||||||
log.warn("Not a directory: %s", p.toAbsolutePath());
|
log.warn("Not a directory: %s", p.toAbsolutePath());
|
||||||
}
|
}
|
||||||
int v = schema.getVersion();
|
int v = schema.getVersion();
|
||||||
versions.put(v, new Version<>(schema, v, isDir, getReady(cfg, v)));
|
versions.put(v, new Version(schema, v, isDir, getReady(cfg, v)));
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = def.getName() + "_";
|
|
||||||
try (DirectoryStream<Path> paths =
|
try (DirectoryStream<Path> paths =
|
||||||
Files.newDirectoryStream(sitePaths.index_dir)) {
|
Files.newDirectoryStream(sitePaths.index_dir)) {
|
||||||
for (Path p : paths) {
|
for (Path p : paths) {
|
||||||
String n = p.getFileName().toString();
|
String n = p.getFileName().toString();
|
||||||
if (!n.startsWith(prefix)) {
|
if (!n.startsWith(CHANGES_PREFIX)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String versionStr = n.substring(prefix.length());
|
String versionStr = n.substring(CHANGES_PREFIX.length());
|
||||||
Integer v = Ints.tryParse(versionStr);
|
Integer v = Ints.tryParse(versionStr);
|
||||||
if (v == null || versionStr.length() != 4) {
|
if (v == null || versionStr.length() != 4) {
|
||||||
log.warn("Unrecognized version in index directory: {}",
|
log.warn("Unrecognized version in index directory: {}",
|
||||||
@ -274,7 +252,7 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!versions.containsKey(v)) {
|
if (!versions.containsKey(v)) {
|
||||||
versions.put(v, new Version<V>(null, v, true, getReady(cfg, v)));
|
versions.put(v, new Version(null, v, true, getReady(cfg, v)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -283,10 +261,10 @@ public class LuceneVersionManager implements LifecycleListener {
|
|||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <V> void markNotReady(FileBasedConfig cfg, Iterable<Version<V>> versions,
|
private void markNotReady(FileBasedConfig cfg, Iterable<Version> versions,
|
||||||
Collection<Version<V>> inUse) {
|
Collection<Version> inUse) {
|
||||||
boolean dirty = false;
|
boolean dirty = false;
|
||||||
for (Version<V> v : versions) {
|
for (Version v : versions) {
|
||||||
if (!inUse.contains(v) && v.exists) {
|
if (!inUse.contains(v) && v.exists) {
|
||||||
setReady(cfg, v.version, false);
|
setReady(cfg, v.version, false);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -24,25 +24,19 @@ import com.google.gerrit.sshd.CommandMetaData;
|
|||||||
import com.google.gerrit.sshd.SshCommand;
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Argument;
|
|
||||||
|
|
||||||
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||||
@CommandMetaData(name = "activate",
|
@CommandMetaData(name = "activate",
|
||||||
description = "Activate the latest index version available",
|
description = "Activate the latest index version available",
|
||||||
runsAt = MASTER)
|
runsAt = MASTER)
|
||||||
public class IndexActivateCommand extends SshCommand {
|
public class IndexActivateCommand extends SshCommand {
|
||||||
|
|
||||||
@Argument(index = 0, required = true, metaVar = "INDEX",
|
|
||||||
usage = "index name to activate")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LuceneVersionManager luceneVersionManager;
|
private LuceneVersionManager luceneVersionManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws UnloggedFailure {
|
protected void run() throws UnloggedFailure {
|
||||||
try {
|
try {
|
||||||
if (luceneVersionManager.activateLatestIndex(name)) {
|
if (luceneVersionManager.activateLatestIndex()) {
|
||||||
stdout.println("Activated latest index version");
|
stdout.println("Activated latest index version");
|
||||||
} else {
|
} else {
|
||||||
stdout.println("Not activating index, already using latest version");
|
stdout.println("Not activating index, already using latest version");
|
||||||
|
@ -24,24 +24,18 @@ import com.google.gerrit.sshd.CommandMetaData;
|
|||||||
import com.google.gerrit.sshd.SshCommand;
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Argument;
|
|
||||||
|
|
||||||
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||||
@CommandMetaData(name = "start", description = "Start the online reindexer",
|
@CommandMetaData(name = "start", description = "Start the online reindexer",
|
||||||
runsAt = MASTER)
|
runsAt = MASTER)
|
||||||
public class IndexStartCommand extends SshCommand {
|
public class IndexStartCommand extends SshCommand {
|
||||||
|
|
||||||
@Argument(index = 0, required = true, metaVar = "INDEX",
|
|
||||||
usage = "index name to activate")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LuceneVersionManager luceneVersionManager;
|
private LuceneVersionManager luceneVersionManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws UnloggedFailure {
|
protected void run() throws UnloggedFailure {
|
||||||
try {
|
try {
|
||||||
if (luceneVersionManager.startReindexer(name)) {
|
if (luceneVersionManager.startReindexer()) {
|
||||||
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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user