Skip to content

Commit 59f92fe

Browse files
committed
batcheval: add some logging for EndTxn evaluation
Fixes #148523 Epic: none Release note: None
1 parent 95ad271 commit 59f92fe

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

pkg/kv/kvserver/batcheval/cmd_end_transaction.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ func EndTxn(
273273

274274
// Fetch existing transaction.
275275
var existingTxn roachpb.Transaction
276+
log.VEventf(
277+
ctx, 2, "checking to see if transaction record already exists for txn: %s", h.Txn,
278+
)
276279
recordAlreadyExisted, err := storage.MVCCGetProto(
277280
ctx, readWriter, key, hlc.Timestamp{}, &existingTxn, storage.MVCCGetOptions{
278281
ReadCategory: fs.BatchEvalReadCategory,
@@ -281,6 +284,7 @@ func EndTxn(
281284
if err != nil {
282285
return result.Result{}, err
283286
} else if !recordAlreadyExisted {
287+
log.VEvent(ctx, 2, "no existing txn record found")
284288
// No existing transaction record was found - create one by writing it
285289
// below in updateFinalizedTxn.
286290
reply.Txn = h.Txn.Clone()
@@ -290,10 +294,12 @@ func EndTxn(
290294
// an aborted txn record.
291295
if args.Commit {
292296
if err := CanCreateTxnRecord(ctx, cArgs.EvalCtx, reply.Txn); err != nil {
297+
log.VEventf(ctx, 2, "cannot create transaction record: %v", err)
293298
return result.Result{}, err
294299
}
295300
}
296301
} else {
302+
log.VEventf(ctx, 2, "existing transaction record found: %s", existingTxn)
297303
// We're using existingTxn on the reply, although it can be stale
298304
// compared to the Transaction in the request (e.g. the Sequence,
299305
// and various timestamps). We must be careful to update it with the
@@ -317,8 +323,11 @@ func EndTxn(
317323
"already committed")
318324

319325
case roachpb.ABORTED:
326+
// The transaction has already been aborted by someone else.
327+
log.VEventf(
328+
ctx, 2, "transaction %s found to have be already aborted (by someone else)", reply.Txn,
329+
)
320330
if !args.Commit {
321-
// The transaction has already been aborted by other.
322331
// Do not return TransactionAbortedError since the client anyway
323332
// wanted to abort the transaction.
324333
resolvedLocks, _, externalLocks, err := resolveLocalLocks(ctx, readWriter, cArgs.EvalCtx, ms, args, reply.Txn)
@@ -379,6 +388,7 @@ func EndTxn(
379388
// not consider the transaction to be performing a parallel commit and
380389
// potentially already implicitly committed because we know that the
381390
// transaction restarted since entering the STAGING state.
391+
log.VEventf(ctx, 2, "request with newer epoch %d than STAGING txn record; parallel commit must have failed", h.Txn.Epoch)
382392
reply.Txn.Status = roachpb.PENDING
383393
default:
384394
panic("unreachable")
@@ -543,13 +553,20 @@ func EndTxn(
543553
txnResult.Local.ResolvedLocks = resolvedLocks
544554

545555
if reply.Txn.Status == roachpb.COMMITTED {
546-
// Return whether replicated {shared, exclusive} locks were released by
547-
// the committing transaction. If such locks were released, we still
548-
// need to make sure other transactions can't write underneath the
549-
// transaction's commit timestamp to the key spans previously protected
550-
// by the locks. We return the spans on the response and update the
551-
// timestamp cache a few layers above to ensure this.
552-
reply.ReplicatedLocksReleasedOnCommit = releasedReplLocks
556+
if len(releasedReplLocks) != 0 {
557+
// Return that local replicated {shared, exclusive} locks were released by
558+
// the committing transaction. If such locks were released, we still need
559+
// to make sure other transactions can't write underneath the
560+
// transaction's commit timestamp to the key spans previously protected by
561+
// the locks. We return the spans on the response and update the timestamp
562+
// cache a few layers above to ensure this.
563+
//
564+
// TODO(arul): rename this to include the word local in it.
565+
reply.ReplicatedLocksReleasedOnCommit = releasedReplLocks
566+
log.VEventf(
567+
ctx, 2, "committed transaction released local replicated shared/exclusive locks",
568+
)
569+
}
553570

554571
// Run the commit triggers if successfully committed.
555572
triggerResult, err := RunCommitTrigger(

0 commit comments

Comments
 (0)