RetryHelper: Let callers care about exception handling
When retrying actions it is specific to the caller which exceptions should be rethrown and which exceptions should be wrapped. At the moment RetryHelper has 2 kinds of execute methods that are suitable for change updates and account updates. These execute methods do not fit for all cases, e.g. ReceiveCommits uses RetryHelper to retry change queries, but the execute method requires handling of ConfigInvalidException which cannot occur during index queries. Instead of adding more specific execute methods to RetryHelper, just let the execute method throw Exception and let the caller take care about the exception handling. The execute method that is specific for change updates is kept in RetryHelper because it has many callers. All other exception handling is currently unique for one caller, hence it's not needed to keep a specialized execute method for these cases in RetryHelper. We can add more specifc execute methods to RetryHelper once the same exception handling is required by multiple callers to share the exception handling code. Change-Id: I7cf2b92fb228d2d6dddd89df5c338e53a2f8f526 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Runnables;
|
||||
@@ -37,6 +38,7 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.index.change.ReindexAfterRefUpdate;
|
||||
import com.google.gerrit.server.update.RefUpdateUtil;
|
||||
import com.google.gerrit.server.update.RetryHelper;
|
||||
import com.google.gerrit.server.update.RetryHelper.Action;
|
||||
import com.google.gerrit.server.update.RetryHelper.ActionType;
|
||||
import com.google.gwtorm.server.OrmDuplicateKeyException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -498,8 +500,7 @@ public class AccountsUpdate {
|
||||
|
||||
private Optional<AccountState> updateAccount(AccountUpdate accountUpdate)
|
||||
throws IOException, ConfigInvalidException, OrmException {
|
||||
return retryHelper.execute(
|
||||
ActionType.ACCOUNT_UPDATE,
|
||||
return executeAccountUpdate(
|
||||
() -> {
|
||||
try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
|
||||
UpdatedAccount updatedAccount = accountUpdate.update(allUsersRepo);
|
||||
@@ -513,6 +514,20 @@ public class AccountsUpdate {
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<AccountState> executeAccountUpdate(Action<Optional<AccountState>> action)
|
||||
throws IOException, ConfigInvalidException, OrmException {
|
||||
try {
|
||||
return retryHelper.execute(
|
||||
ActionType.ACCOUNT_UPDATE, action, LockFailureException.class::isInstance);
|
||||
} catch (Exception e) {
|
||||
Throwables.throwIfUnchecked(e);
|
||||
Throwables.throwIfInstanceOf(e, IOException.class);
|
||||
Throwables.throwIfInstanceOf(e, ConfigInvalidException.class);
|
||||
Throwables.throwIfInstanceOf(e, OrmException.class);
|
||||
throw new OrmException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ExternalIdNotes createExternalIdNotes(
|
||||
Repository allUsersRepo,
|
||||
Optional<ObjectId> rev,
|
||||
|
Reference in New Issue
Block a user