Add ChangeCache implementation to scan changes from git
The purpose of ChangeCache is to resolve a project name to a list of changes. This is a natural location for the scanChanges implementation we added to SiteIndexer. However, most users in a running server will still just want use the secondary index lookup, as it's faster. So we extract an interface and provide two implementations. Change-Id: I66c24b337cdc6aa787f450f8e0b2dfa17b0cdf97
This commit is contained in:
@@ -28,6 +28,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.ScanningChangeCacheImpl;
|
||||
import com.google.gerrit.server.index.ChangeIndex;
|
||||
import com.google.gerrit.server.index.ChangeSchemas;
|
||||
import com.google.gerrit.server.index.IndexCollection;
|
||||
@@ -68,15 +69,19 @@ public class Reindex extends SiteProgram {
|
||||
|
||||
private Injector dbInjector;
|
||||
private Injector sysInjector;
|
||||
private Config globalConfig;
|
||||
private ChangeIndex index;
|
||||
|
||||
@Override
|
||||
public int run() throws Exception {
|
||||
mustHaveValidSite();
|
||||
dbInjector = createDbInjector(MULTI_USER);
|
||||
globalConfig =
|
||||
dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
threads = ThreadLimiter.limitThreads(dbInjector, threads);
|
||||
checkNotSlaveMode();
|
||||
disableLuceneAutomaticCommit();
|
||||
disableChangeCache();
|
||||
if (version == null) {
|
||||
version = ChangeSchemas.getLatest().getVersion();
|
||||
}
|
||||
@@ -105,9 +110,7 @@ public class Reindex extends SiteProgram {
|
||||
}
|
||||
|
||||
private void checkNotSlaveMode() throws Die {
|
||||
Config cfg = dbInjector.getInstance(
|
||||
Key.get(Config.class, GerritServerConfig.class));
|
||||
if (cfg.getBoolean("container", "slave", false)) {
|
||||
if (globalConfig.getBoolean("container", "slave", false)) {
|
||||
throw die("Cannot run reindex in slave mode");
|
||||
}
|
||||
}
|
||||
@@ -126,20 +129,25 @@ public class Reindex extends SiteProgram {
|
||||
throw new IllegalStateException("unsupported index.type");
|
||||
}
|
||||
modules.add(changeIndexModule);
|
||||
// Scan changes from git instead of relying on the secondary index, as we
|
||||
// will have just deleted the old (possibly corrupt) index.
|
||||
modules.add(ScanningChangeCacheImpl.module());
|
||||
modules.add(dbInjector.getInstance(BatchProgramModule.class));
|
||||
|
||||
return dbInjector.createChildInjector(modules);
|
||||
}
|
||||
|
||||
private void disableLuceneAutomaticCommit() {
|
||||
Config cfg =
|
||||
dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
if (IndexModule.getIndexType(dbInjector) == IndexType.LUCENE) {
|
||||
cfg.setLong("index", "changes_open", "commitWithin", -1);
|
||||
cfg.setLong("index", "changes_closed", "commitWithin", -1);
|
||||
globalConfig.setLong("index", "changes_open", "commitWithin", -1);
|
||||
globalConfig.setLong("index", "changes_closed", "commitWithin", -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void disableChangeCache() {
|
||||
globalConfig.setLong("cache", "changes", "maximumWeight", 0);
|
||||
}
|
||||
|
||||
private int indexAll() throws Exception {
|
||||
ReviewDb db = sysInjector.getInstance(ReviewDb.class);
|
||||
ProgressMonitor pm = new TextProgressMonitor();
|
||||
|
Reference in New Issue
Block a user