Avoid blocking calls in async account updates
This commit is contained in:
parent
521900c048
commit
07c04006df
|
@ -807,14 +807,17 @@ public class Accounts extends AbstractDynamoDbStore {
|
||||||
account.setVersion(AttributeValues.getInt(response.attributes(), "V", account.getVersion() + 1));
|
account.setVersion(AttributeValues.getInt(response.attributes(), "V", account.getVersion() + 1));
|
||||||
return (Void) null;
|
return (Void) null;
|
||||||
})
|
})
|
||||||
.exceptionally(throwable -> {
|
.exceptionallyCompose(throwable -> {
|
||||||
final Throwable unwrapped = ExceptionUtils.unwrap(throwable);
|
final Throwable unwrapped = ExceptionUtils.unwrap(throwable);
|
||||||
if (unwrapped instanceof TransactionConflictException) {
|
if (unwrapped instanceof TransactionConflictException) {
|
||||||
throw new ContestedOptimisticLockException();
|
throw new ContestedOptimisticLockException();
|
||||||
} else if (unwrapped instanceof ConditionalCheckFailedException e) {
|
} else if (unwrapped instanceof ConditionalCheckFailedException e) {
|
||||||
// the exception doesn't give details about which condition failed,
|
// the exception doesn't give details about which condition failed,
|
||||||
// but we can infer it was an optimistic locking failure if the UUID is known
|
// but we can infer it was an optimistic locking failure if the UUID is known
|
||||||
throw getByAccountIdentifier(account.getUuid()).isPresent() ? new ContestedOptimisticLockException() : e;
|
return getByAccountIdentifierAsync(account.getUuid())
|
||||||
|
.thenAccept(refreshedAccount -> {
|
||||||
|
throw refreshedAccount.isPresent() ? new ContestedOptimisticLockException() : e;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// rethrow
|
// rethrow
|
||||||
throw CompletableFutureUtils.errorAsCompletionException(throwable);
|
throw CompletableFutureUtils.errorAsCompletionException(throwable);
|
||||||
|
|
Loading…
Reference in New Issue