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:
parent
fb1a919506
commit
a3d0ed721a
|
@ -25,4 +25,12 @@ public interface AccountIndexer {
|
|||
* @param id account id to index.
|
||||
*/
|
||||
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.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
|
@ -102,6 +101,15 @@ public class AccountIndexerImpl implements AccountIndexer {
|
|||
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) {
|
||||
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
||||
}
|
||||
|
@ -110,7 +118,7 @@ public class AccountIndexerImpl implements AccountIndexer {
|
|||
if (autoReindexIfStale) {
|
||||
// Don't retry indefinitely; if this fails the account will be stale.
|
||||
@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.
|
||||
*/
|
||||
@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) {
|
||||
Callable<Boolean> task =
|
||||
() -> {
|
||||
if (stalenessChecker.isStale(id)) {
|
||||
index(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return Futures.makeChecked(
|
||||
Futures.nonCancellationPropagating(batchExecutor.submit(task)), IndexUtils.MAPPER);
|
||||
Futures.nonCancellationPropagating(batchExecutor.submit(() -> reindexIfStale(id))),
|
||||
IndexUtils.MAPPER);
|
||||
}
|
||||
|
||||
private void fireAccountIndexedEvent(int id) {
|
||||
|
|
|
@ -25,4 +25,12 @@ public interface GroupIndexer {
|
|||
* @param uuid group UUID to index.
|
||||
*/
|
||||
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.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
|
@ -102,6 +101,15 @@ public class GroupIndexerImpl implements GroupIndexer {
|
|||
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) {
|
||||
return cfg.getBoolean("index", null, "autoReindexIfStale", true);
|
||||
}
|
||||
|
@ -110,7 +118,7 @@ public class GroupIndexerImpl implements GroupIndexer {
|
|||
if (autoReindexIfStale) {
|
||||
// Don't retry indefinitely; if this fails the group will be stale.
|
||||
@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.
|
||||
*/
|
||||
@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) {
|
||||
Callable<Boolean> task =
|
||||
() -> {
|
||||
if (stalenessChecker.isStale(uuid)) {
|
||||
index(uuid);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return Futures.makeChecked(
|
||||
Futures.nonCancellationPropagating(batchExecutor.submit(task)), IndexUtils.MAPPER);
|
||||
Futures.nonCancellationPropagating(batchExecutor.submit(() -> reindexIfStale(uuid))),
|
||||
IndexUtils.MAPPER);
|
||||
}
|
||||
|
||||
private void fireGroupIndexedEvent(String uuid) {
|
||||
|
|
Loading…
Reference in New Issue