Merge "Add config option to reindex all groups on slave startup"
This commit is contained in:
@@ -2777,6 +2777,16 @@ reindex] must be performed.
|
|||||||
This section is only used if Gerrit runs in slave mode, otherwise it is
|
This section is only used if Gerrit runs in slave mode, otherwise it is
|
||||||
ignored.
|
ignored.
|
||||||
|
|
||||||
|
[[index.scheduledIndexer.runOnStartup]]index.scheduledIndexer.runOnStartup::
|
||||||
|
+
|
||||||
|
Whether the scheduled indexer should run once immediately on startup.
|
||||||
|
If set to `true` the slave startup is blocked until all stale groups
|
||||||
|
were reindexed. Enabling this allows to prevent that slaves that were
|
||||||
|
offline for a longer period of time run with outdated group information
|
||||||
|
until the first scheduled indexing is done.
|
||||||
|
+
|
||||||
|
Defaults to `true`.
|
||||||
|
|
||||||
[[index.scheduledIndexer.enabled]]index.scheduledIndexer.enabled::
|
[[index.scheduledIndexer.enabled]]index.scheduledIndexer.enabled::
|
||||||
+
|
+
|
||||||
Whether the scheduled indexer is enabled. If the scheduled indexer is
|
Whether the scheduled indexer is enabled. If the scheduled indexer is
|
||||||
|
|||||||
@@ -343,9 +343,6 @@ public abstract class AbstractDaemonTest {
|
|||||||
server.getTestInjector().injectMembers(resetter);
|
server.getTestInjector().injectMembers(resetter);
|
||||||
}
|
}
|
||||||
initSsh();
|
initSsh();
|
||||||
// The server restart threw away all indices. Only reindex all groups as we only have the group
|
|
||||||
// index in slave mode.
|
|
||||||
reindexAllGroups();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reindexAllGroups() throws OrmException, IOException, ConfigInvalidException {
|
private void reindexAllGroups() throws OrmException, IOException, ConfigInvalidException {
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ public class PeriodicGroupIndexer implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
boolean runOnStartup = cfg.getBoolean("index", "scheduledIndexer", "runOnStartup", true);
|
||||||
|
if (runOnStartup) {
|
||||||
|
runner.run();
|
||||||
|
}
|
||||||
|
|
||||||
boolean isEnabled = cfg.getBoolean("index", "scheduledIndexer", "enabled", true);
|
boolean isEnabled = cfg.getBoolean("index", "scheduledIndexer", "enabled", true);
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
log.warn("index.scheduledIndexer is disabled");
|
log.warn("index.scheduledIndexer is disabled");
|
||||||
|
|||||||
@@ -1262,14 +1262,15 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
groups.getAllGroupReferences(db).map(GroupReference::getUUID).collect(toList());
|
groups.getAllGroupReferences(db).map(GroupReference::getUUID).collect(toList());
|
||||||
assertThat(expectedGroups.size()).isAtLeast(2);
|
assertThat(expectedGroups.size()).isAtLeast(2);
|
||||||
|
|
||||||
|
// Restart the server as slave, on startup of the slave all groups are indexed.
|
||||||
restartAsSlave();
|
restartAsSlave();
|
||||||
|
|
||||||
GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
|
GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
|
||||||
RegistrationHandle groupIndexEventCounterHandle =
|
RegistrationHandle groupIndexEventCounterHandle =
|
||||||
groupIndexedListeners.add(groupIndexedCounter);
|
groupIndexedListeners.add(groupIndexedCounter);
|
||||||
try {
|
try {
|
||||||
// On startup of the slave the test framework ensures that the group index is up-to-date.
|
// Running the reindexer right after startup should not need to reindex any group since
|
||||||
// Hence running the reindexer doesn't need to reindex any group.
|
// reindexing was already done on startup.
|
||||||
slaveGroupIndexer.run();
|
slaveGroupIndexer.run();
|
||||||
groupIndexedCounter.assertNoReindex();
|
groupIndexedCounter.assertNoReindex();
|
||||||
|
|
||||||
@@ -1308,6 +1309,33 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Sandboxed
|
||||||
|
@GerritConfig(name = "index.scheduledIndexer.runOnStartup", value = "false")
|
||||||
|
@GerritConfig(name = "index.scheduledIndexer.enabled", value = "false")
|
||||||
|
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
||||||
|
@IgnoreGroupInconsistencies
|
||||||
|
public void disabledReindexGroupsOnStartupSlaveMode() throws Exception {
|
||||||
|
assume().that(readGroupsFromNoteDb()).isTrue();
|
||||||
|
|
||||||
|
List<AccountGroup.UUID> expectedGroups =
|
||||||
|
groups.getAllGroupReferences(db).map(GroupReference::getUUID).collect(toList());
|
||||||
|
assertThat(expectedGroups.size()).isAtLeast(2);
|
||||||
|
|
||||||
|
restartAsSlave();
|
||||||
|
|
||||||
|
GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
|
||||||
|
RegistrationHandle groupIndexEventCounterHandle =
|
||||||
|
groupIndexedListeners.add(groupIndexedCounter);
|
||||||
|
try {
|
||||||
|
// No group indexing happened on startup. All groups should be reindexed now.
|
||||||
|
slaveGroupIndexer.run();
|
||||||
|
groupIndexedCounter.assertReindexOf(expectedGroups);
|
||||||
|
} finally {
|
||||||
|
groupIndexEventCounterHandle.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertStaleGroupAndReindex(AccountGroup.UUID groupUuid) throws IOException {
|
private void assertStaleGroupAndReindex(AccountGroup.UUID groupUuid) throws IOException {
|
||||||
// Evict group from cache to be sure that we use the index state for staleness checks.
|
// Evict group from cache to be sure that we use the index state for staleness checks.
|
||||||
groupCache.evict(groupUuid);
|
groupCache.evict(groupUuid);
|
||||||
|
|||||||
Reference in New Issue
Block a user