Allow to reindex groups and accounts if they are stale
Being able to reindex a group only if it is stale can save effort on startup of Gerrit slaves (see follow-up change). Change-Id: I66d5bb09e49a4dfcd9d20db12c4ab818c94fd399 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -25,4 +25,12 @@ public interface AccountIndexer {
|
|||||||
* @param id account id to index.
|
* @param id account id to index.
|
||||||
*/
|
*/
|
||||||
void index(Account.Id id) throws IOException;
|
void index(Account.Id id) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously reindex an account if it is stale.
|
||||||
|
*
|
||||||
|
* @param id account id to index.
|
||||||
|
* @return whether the account was reindexed
|
||||||
|
*/
|
||||||
|
boolean reindexIfStale(Account.Id id) throws IOException;
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,6 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
|
|
||||||
@@ -102,6 +101,15 @@ public class AccountIndexerImpl implements AccountIndexer {
|
|||||||
autoReindexIfStale(id);
|
autoReindexIfStale(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean reindexIfStale(Account.Id id) throws IOException {
|
||||||
|
if (stalenessChecker.isStale(id)) {
|
||||||
|
index(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean autoReindexIfStale(Config cfg) {
|
private static boolean autoReindexIfStale(Config cfg) {
|
||||||
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
||||||
}
|
}
|
||||||
@@ -110,7 +118,7 @@ public class AccountIndexerImpl implements AccountIndexer {
|
|||||||
if (autoReindexIfStale) {
|
if (autoReindexIfStale) {
|
||||||
// Don't retry indefinitely; if this fails the account will be stale.
|
// Don't retry indefinitely; if this fails the account will be stale.
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Future<?> possiblyIgnoredError = reindexIfStale(id);
|
Future<?> possiblyIgnoredError = reindexIfStaleAsync(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,19 +132,11 @@ public class AccountIndexerImpl implements AccountIndexer {
|
|||||||
* @return future for reindexing the account; returns true if the account was stale.
|
* @return future for reindexing the account; returns true if the account was stale.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public com.google.common.util.concurrent.CheckedFuture<Boolean, IOException> reindexIfStale(
|
private com.google.common.util.concurrent.CheckedFuture<Boolean, IOException> reindexIfStaleAsync(
|
||||||
Account.Id id) {
|
Account.Id id) {
|
||||||
Callable<Boolean> task =
|
|
||||||
() -> {
|
|
||||||
if (stalenessChecker.isStale(id)) {
|
|
||||||
index(id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Futures.makeChecked(
|
return Futures.makeChecked(
|
||||||
Futures.nonCancellationPropagating(batchExecutor.submit(task)), IndexUtils.MAPPER);
|
Futures.nonCancellationPropagating(batchExecutor.submit(() -> reindexIfStale(id))),
|
||||||
|
IndexUtils.MAPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireAccountIndexedEvent(int id) {
|
private void fireAccountIndexedEvent(int id) {
|
||||||
|
@@ -25,4 +25,12 @@ public interface GroupIndexer {
|
|||||||
* @param uuid group UUID to index.
|
* @param uuid group UUID to index.
|
||||||
*/
|
*/
|
||||||
void index(AccountGroup.UUID uuid) throws IOException;
|
void index(AccountGroup.UUID uuid) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously reindex a group if it is stale.
|
||||||
|
*
|
||||||
|
* @param uuid group UUID to index.
|
||||||
|
* @return whether the group was reindexed
|
||||||
|
*/
|
||||||
|
boolean reindexIfStale(AccountGroup.UUID uuid) throws IOException;
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,6 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
|
|
||||||
@@ -102,6 +101,15 @@ public class GroupIndexerImpl implements GroupIndexer {
|
|||||||
autoReindexIfStale(uuid);
|
autoReindexIfStale(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean reindexIfStale(AccountGroup.UUID uuid) throws IOException {
|
||||||
|
if (stalenessChecker.isStale(uuid)) {
|
||||||
|
index(uuid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean autoReindexIfStale(Config cfg) {
|
private static boolean autoReindexIfStale(Config cfg) {
|
||||||
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
||||||
}
|
}
|
||||||
@@ -110,7 +118,7 @@ public class GroupIndexerImpl implements GroupIndexer {
|
|||||||
if (autoReindexIfStale) {
|
if (autoReindexIfStale) {
|
||||||
// Don't retry indefinitely; if this fails the group will be stale.
|
// Don't retry indefinitely; if this fails the group will be stale.
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Future<?> possiblyIgnoredError = reindexIfStale(uuid);
|
Future<?> possiblyIgnoredError = reindexIfStaleAsync(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,19 +132,11 @@ public class GroupIndexerImpl implements GroupIndexer {
|
|||||||
* @return future for reindexing the group; returns true if the group was stale.
|
* @return future for reindexing the group; returns true if the group was stale.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public com.google.common.util.concurrent.CheckedFuture<Boolean, IOException> reindexIfStale(
|
private com.google.common.util.concurrent.CheckedFuture<Boolean, IOException> reindexIfStaleAsync(
|
||||||
AccountGroup.UUID uuid) {
|
AccountGroup.UUID uuid) {
|
||||||
Callable<Boolean> task =
|
|
||||||
() -> {
|
|
||||||
if (stalenessChecker.isStale(uuid)) {
|
|
||||||
index(uuid);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Futures.makeChecked(
|
return Futures.makeChecked(
|
||||||
Futures.nonCancellationPropagating(batchExecutor.submit(task)), IndexUtils.MAPPER);
|
Futures.nonCancellationPropagating(batchExecutor.submit(() -> reindexIfStale(uuid))),
|
||||||
|
IndexUtils.MAPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireGroupIndexedEvent(String uuid) {
|
private void fireGroupIndexedEvent(String uuid) {
|
||||||
|
Reference in New Issue
Block a user