Skip to content

Commit

Permalink
Bump the number of retries in transaction failures
Browse files Browse the repository at this point in the history
This can potentially help even more with serializable transaction
failures (optimistic locking exceptions, which are expected to occur
somewhat frequently).

With six attempts, we will sleep at most five times, for
100+200+400+800+1600 ms each, for a total of at most 3.1 seconds (much
less than the EPP maximum which I believe (?) to be 30 seconds.
  • Loading branch information
gbrodman committed Mar 4, 2025
1 parent 8896fb9 commit d86ce33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
public class JpaTransactionManagerImpl implements JpaTransactionManager {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final Retrier retrier = new Retrier(new SystemSleeper(), 3);
private static final Retrier retrier = new Retrier(new SystemSleeper(), 6);
private static final String NESTED_TRANSACTION_MESSAGE =
"Nested transaction detected. Try refactoring to avoid nested transactions. If unachievable,"
+ " use reTransact() in nested transactions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ void transact_retriesOptimisticLockExceptions() {
assertThrows(
OptimisticLockException.class,
() -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
verify(spyJpaTm, times(3)).delete(theEntityKey);
verify(spyJpaTm, times(6)).delete(theEntityKey);
assertThrows(
OptimisticLockException.class,
() -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
verify(spyJpaTm, times(6)).delete(theEntityKey);
verify(spyJpaTm, times(12)).delete(theEntityKey);
}

@Test
Expand Down Expand Up @@ -355,10 +355,10 @@ void transact_retriesNestedOptimisticLockExceptions() {
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class, () -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
verify(spyJpaTm, times(3)).delete(theEntityKey);
verify(spyJpaTm, times(6)).delete(theEntityKey);
assertThrows(
RuntimeException.class, () -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
verify(spyJpaTm, times(6)).delete(theEntityKey);
verify(spyJpaTm, times(12)).delete(theEntityKey);
}

@Test
Expand Down Expand Up @@ -759,11 +759,11 @@ void innerTransactions_noRetry() {
spyJpaTm.transact(
() -> {
spyJpaTm.exists(theEntity);
spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey));
spyJpaTm.delete(theEntityKey);
}));

verify(spyJpaTm, times(3)).exists(theEntity);
verify(spyJpaTm, times(3)).delete(theEntityKey);
verify(spyJpaTm, times(6)).exists(theEntity);
verify(spyJpaTm, times(6)).delete(theEntityKey);
}

private static void insertPerson(int age) {
Expand Down

0 comments on commit d86ce33

Please sign in to comment.