Committed by
Gerrit Code Review
Fast path in transaction manager for single update scenarios
Change-Id: Ia0ad61aabf5c35fbfadc5b127662edb497bcc9c0
Showing
1 changed file
with
6 additions
and
0 deletions
... | @@ -50,6 +50,12 @@ public class TransactionManager { | ... | @@ -50,6 +50,12 @@ public class TransactionManager { |
50 | * @return transaction commit result | 50 | * @return transaction commit result |
51 | */ | 51 | */ |
52 | public CompletableFuture<CommitResult> execute(Transaction transaction) { | 52 | public CompletableFuture<CommitResult> execute(Transaction transaction) { |
53 | + // short-circuit if there is only a single update | ||
54 | + if (transaction.updates().size() <= 1) { | ||
55 | + return database.prepareAndCommit(transaction) | ||
56 | + .thenApply(response -> response.success() | ||
57 | + ? CommitResult.OK : CommitResult.FAILURE_DURING_COMMIT); | ||
58 | + } | ||
53 | // clean up if this transaction in already in a terminal state. | 59 | // clean up if this transaction in already in a terminal state. |
54 | if (transaction.state() == COMMITTED || transaction.state() == ROLLEDBACK) { | 60 | if (transaction.state() == COMMITTED || transaction.state() == ROLLEDBACK) { |
55 | return transactions.remove(transaction.id()).thenApply(v -> CommitResult.OK); | 61 | return transactions.remove(transaction.id()).thenApply(v -> CommitResult.OK); | ... | ... |
-
Please register or login to post a comment