Adapt to changes of the RetryHelper API
Change Iecdfa5b15 added a fluent API for executing action with retrying.
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I655604f58bd1ff1aeec2c55c12d1bbd6b396d0f4
diff --git a/java/com/google/gerrit/plugins/checks/CheckerQuery.java b/java/com/google/gerrit/plugins/checks/CheckerQuery.java
index 332cf63..77cd4b0 100644
--- a/java/com/google/gerrit/plugins/checks/CheckerQuery.java
+++ b/java/com/google/gerrit/plugins/checks/CheckerQuery.java
@@ -44,7 +44,6 @@
import com.google.gerrit.server.query.change.ChangeStatusPredicate;
import com.google.gerrit.server.query.change.ProjectPredicate;
import com.google.gerrit.server.update.RetryHelper;
-import com.google.gerrit.server.update.RetryHelper.ActionType;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.ArrayList;
@@ -246,7 +245,7 @@
predicateList.add(
createQueryPredicate(checker.getUuid(), checker.getRepository(), checker.getQuery()));
}
- return executeIndexQueryWithRetry(qp -> {}, predicateList);
+ return executeIndexQueryWithRetry("queryMatchingChangesForCheckers", qp -> {}, predicateList);
} catch (QueryParseException e) {
throw new ConfigInvalidException(
String.format(
@@ -269,7 +268,9 @@
throws ConfigInvalidException, StorageException {
try {
return executeIndexQueryWithRetry(
- queryProcessorSetup, createQueryPredicate(checkerUuid, repository, optionalQuery));
+ "queryMatchingChangesForChecker",
+ queryProcessorSetup,
+ createQueryPredicate(checkerUuid, repository, optionalQuery));
} catch (QueryParseException e) {
throw invalidQueryException(checkerUuid, optionalQuery, e);
}
@@ -319,25 +320,32 @@
// TODO(ekempin): Retrying the query should be done by ChangeQueryProcessor.
private ImmutableList<ChangeData> executeIndexQueryWithRetry(
- Consumer<ChangeQueryProcessor> queryProcessorSetup, Predicate<ChangeData> predicate)
+ String actionName,
+ Consumer<ChangeQueryProcessor> queryProcessorSetup,
+ Predicate<ChangeData> predicate)
throws StorageException, QueryParseException {
- return executeIndexQueryWithRetry(queryProcessorSetup, ImmutableList.of(predicate)).get(0);
+ return executeIndexQueryWithRetry(actionName, queryProcessorSetup, ImmutableList.of(predicate))
+ .get(0);
}
private ImmutableList<ImmutableList<ChangeData>> executeIndexQueryWithRetry(
- Consumer<ChangeQueryProcessor> queryProcessorSetup, List<Predicate<ChangeData>> predicateList)
+ String actionName,
+ Consumer<ChangeQueryProcessor> queryProcessorSetup,
+ List<Predicate<ChangeData>> predicateList)
throws StorageException, QueryParseException {
try {
- return retryHelper.execute(
- ActionType.INDEX_QUERY,
- () -> {
- ChangeQueryProcessor qp = changeQueryProcessorProvider.get();
- queryProcessorSetup.accept(qp);
- return qp.query(predicateList).stream()
- .map(predicate -> predicate.entities())
- .collect(toImmutableList());
- },
- StorageException.class::isInstance);
+ return retryHelper
+ .indexQuery(
+ actionName,
+ () -> {
+ ChangeQueryProcessor qp = changeQueryProcessorProvider.get();
+ queryProcessorSetup.accept(qp);
+ return qp.query(predicateList).stream()
+ .map(predicate -> predicate.entities())
+ .collect(toImmutableList());
+ })
+ .retryOn(StorageException.class::isInstance)
+ .call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
Throwables.throwIfInstanceOf(e, QueryParseException.class);
diff --git a/java/com/google/gerrit/plugins/checks/db/NoteDbCheckersUpdate.java b/java/com/google/gerrit/plugins/checks/db/NoteDbCheckersUpdate.java
index 0e1d875..19ae2a5 100644
--- a/java/com/google/gerrit/plugins/checks/db/NoteDbCheckersUpdate.java
+++ b/java/com/google/gerrit/plugins/checks/db/NoteDbCheckersUpdate.java
@@ -33,7 +33,6 @@
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.meta.MetaDataUpdate;
import com.google.gerrit.server.update.RetryHelper;
-import com.google.gerrit.server.update.RetryHelper.ActionType;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import java.io.IOException;
@@ -137,10 +136,11 @@
public Checker createChecker(CheckerCreation checkerCreation, CheckerUpdate checkerUpdate)
throws DuplicateKeyException, IOException, ConfigInvalidException {
try {
- return retryHelper.execute(
- RetryHelper.ActionType.PLUGIN_UPDATE,
- () -> createCheckerInNoteDb(checkerCreation, checkerUpdate),
- LockFailureException.class::isInstance);
+ return retryHelper
+ .pluginUpdate(
+ "createChecker", () -> createCheckerInNoteDb(checkerCreation, checkerUpdate))
+ .retryOn(LockFailureException.class::isInstance)
+ .call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
Throwables.throwIfInstanceOf(e, DuplicateKeyException.class);
@@ -231,10 +231,10 @@
private Checker updateCheckerWithRetry(CheckerUuid checkerUuid, CheckerUpdate checkerUpdate)
throws NoSuchCheckerException, IOException, ConfigInvalidException {
try {
- return retryHelper.execute(
- ActionType.PLUGIN_UPDATE,
- () -> updateCheckerInNoteDb(checkerUuid, checkerUpdate),
- LockFailureException.class::isInstance);
+ return retryHelper
+ .pluginUpdate("updateChecker", () -> updateCheckerInNoteDb(checkerUuid, checkerUpdate))
+ .retryOn(LockFailureException.class::isInstance)
+ .call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
Throwables.throwIfInstanceOf(e, IOException.class);
diff --git a/java/com/google/gerrit/plugins/checks/db/NoteDbChecksUpdate.java b/java/com/google/gerrit/plugins/checks/db/NoteDbChecksUpdate.java
index 467a7bd..05ad0dc 100644
--- a/java/com/google/gerrit/plugins/checks/db/NoteDbChecksUpdate.java
+++ b/java/com/google/gerrit/plugins/checks/db/NoteDbChecksUpdate.java
@@ -141,10 +141,11 @@
public Check createCheck(CheckKey checkKey, CheckUpdate checkUpdate)
throws DuplicateKeyException, IOException {
try {
- return retryHelper.execute(
- RetryHelper.ActionType.PLUGIN_UPDATE,
- () -> upsertCheckInNoteDb(checkKey, checkUpdate, Operation.CREATE),
- LockFailureException.class::isInstance);
+ return retryHelper
+ .pluginUpdate(
+ "createCheck", () -> upsertCheckInNoteDb(checkKey, checkUpdate, Operation.CREATE))
+ .retryOn(LockFailureException.class::isInstance)
+ .call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
Throwables.throwIfInstanceOf(e, DuplicateKeyException.class);
@@ -156,10 +157,11 @@
@Override
public Check updateCheck(CheckKey checkKey, CheckUpdate checkUpdate) throws IOException {
try {
- return retryHelper.execute(
- RetryHelper.ActionType.PLUGIN_UPDATE,
- () -> upsertCheckInNoteDb(checkKey, checkUpdate, Operation.UPDATE),
- LockFailureException.class::isInstance);
+ return retryHelper
+ .pluginUpdate(
+ "updateCheck", () -> upsertCheckInNoteDb(checkKey, checkUpdate, Operation.UPDATE))
+ .retryOn(LockFailureException.class::isInstance)
+ .call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
Throwables.throwIfInstanceOf(e, IOException.class);