Skip to content

Commit

Permalink
chore(spanner): mutation only aborted case
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta committed Jan 23, 2025
1 parent cb62224 commit c9842c9
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public void removeListener(Runnable listener) {

private final Map<SpannerRpc.Option, ?> channelHint;

// This field indicates whether the read-write transaction contains only mutation operations.
boolean mutationsOnlyTransaction = false;

private TransactionContextImpl(Builder builder) {
super(builder);
this.transactionId = builder.transactionId;
Expand Down Expand Up @@ -402,6 +405,11 @@ ApiFuture<CommitResponse> commitAsync() {
synchronized (lock) {
if (transactionIdFuture == null && transactionId == null && runningAsyncOperations == 0) {
finishOps = SettableApiFuture.create();
// At this point, it is ensured that the transaction contains only mutations. Adding a
// safeguard to apply this only for multiplexed sessions.
if (session.getIsMultiplexed()) {
mutationsOnlyTransaction = true;
}
createTxnAsync(finishOps, randomMutation);
} else {
finishOps = finishedAsyncOperations;
Expand Down Expand Up @@ -1229,7 +1237,7 @@ private <T> T runInternal(final TransactionCallable<T> txCallable) {
if (attempt.get() > 0) {
// Do not inline the BeginTransaction during a retry if the initial attempt did not
// actually start a transaction.
useInlinedBegin = txn.transactionId != null;
useInlinedBegin = txn.mutationsOnlyTransaction || txn.transactionId != null;

// Determine the latest transactionId when using a multiplexed session.
ByteString multiplexedSessionPreviousTransactionId = ByteString.EMPTY;
Expand Down

0 comments on commit c9842c9

Please sign in to comment.