Disable auto-reindexing if stale during online reindex

This option exists to handle a race condition that can only occur when
there are concurrent writes to the same document. This doesn't apply
during offline reindex, and turning it off will speed things up.

It is not especially feasible to pass this option into ChangeIndexer in
code, so we have to use a config value for it. Remove the "test" prefix
from the config name, and document it.

Change-Id: Iecc12c3ab0f068f24063c358ce50a40b25362511
This commit is contained in:
Dave Borowitz
2017-06-23 14:29:31 -04:00
committed by David Pursehouse
parent 16c2da79c3
commit 3747f0f7d4
5 changed files with 19 additions and 8 deletions

View File

@@ -2653,6 +2653,15 @@ are the same.
+
Defaults to 1024.
[[index.autoReindexIfStale]]index.autoReindexIfStale::
+
Whether to automatically check if a document became stale in the index
immediately after indexing it. If false, there is a race condition during two
simultaneous writes that may cause one of the writes to not be reflected in the
index. The check to avoid this does consume some resources.
+
Defaults to true.
==== Lucene configuration
Open and closed changes are indexed in separate indexes named

View File

@@ -517,7 +517,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
}
@Test
@GerritConfig(name = "index.testAutoReindexIfStale", value = "false")
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
public void getRelatedForStaleChange() throws Exception {
RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();

View File

@@ -120,7 +120,7 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
// unintentional auto-rebuilding of the change in NoteDb during the read
// path of the reindex-if-stale check. For the purposes of this test, we
// want precise control over when auto-rebuilding happens.
cfg.setBoolean("index", null, "testAutoReindexIfStale", false);
cfg.setBoolean("index", null, "autoReindexIfStale", false);
return cfg;
}

View File

@@ -84,8 +84,7 @@ public class Reindex extends SiteProgram {
globalConfig = dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
threads = ThreadLimiter.limitThreads(dbInjector, threads);
checkNotSlaveMode();
disableLuceneAutomaticCommit();
disableChangeCache();
overrideConfig();
LifecycleManager dbManager = new LifecycleManager();
dbManager.add(dbInjector);
dbManager.start();
@@ -177,15 +176,18 @@ public class Reindex extends SiteProgram {
return dbInjector.createChildInjector(modules);
}
private void disableLuceneAutomaticCommit() {
private void overrideConfig() {
// Disable auto-commit for speed; committing will happen at the end of the process.
if (IndexModule.getIndexType(dbInjector) == IndexType.LUCENE) {
globalConfig.setLong("index", "changes_open", "commitWithin", -1);
globalConfig.setLong("index", "changes_closed", "commitWithin", -1);
}
}
private void disableChangeCache() {
// Disable change cache.
globalConfig.setLong("cache", "changes", "maximumWeight", 0);
// Disable auto-reindexing if stale, since there are no concurrent writes to race with.
globalConfig.setBoolean("index", null, "autoReindexIfStale", false);
}
private <K, V, I extends Index<K, V>> boolean reindex(IndexDefinition<K, V, I> def)

View File

@@ -164,7 +164,7 @@ public class ChangeIndexer {
}
private static boolean autoReindexIfStale(Config cfg) {
return cfg.getBoolean("index", null, "testAutoReindexIfStale", true);
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
}
/**