Fix observed mismatches by swapping in original UUID

This commit is contained in:
Chris Eager 2021-05-17 11:26:28 -05:00 committed by Chris Eager
parent 282f39141e
commit 30b2c2b5ad
1 changed files with 34 additions and 15 deletions

View File

@ -118,12 +118,25 @@ public class AccountsManager {
public boolean create(Account account) {
try (Timer.Context ignored = createTimer.time()) {
final UUID originalUuid = account.getUuid();
boolean freshUser = databaseCreate(account);
redisSet(account);
// databaseCreate() sometimes updates the UUID, if there was a number conflict.
// for metrics, we want dynamo to run with the same original UUID
final UUID actualUuid = account.getUuid();
try {
if (dynamoWriteEnabled()) {
account.setUuid(originalUuid);
runSafelyAndRecordMetrics(() -> dynamoCreate(account), Optional.of(account.getUuid()), freshUser,
(databaseResult, dynamoResult) -> {
if (!account.getUuid().equals(actualUuid)) {
logger.warn("dynamoCreate() did not return correct UUID");
}
if (databaseResult.equals(dynamoResult)) {
return Optional.empty();
}
@ -136,6 +149,12 @@ public class AccountsManager {
},
"create");
}
} finally {
account.setUuid(actualUuid);
}
redisSet(account);
return freshUser;
}
}