diff --git a/pkg/storage/batcheval/cmd_end_transaction.go b/pkg/storage/batcheval/cmd_end_transaction.go index 60717a7cc842..f11de1eaea4d 100644 --- a/pkg/storage/batcheval/cmd_end_transaction.go +++ b/pkg/storage/batcheval/cmd_end_transaction.go @@ -519,13 +519,12 @@ func resolveLocalIntents( return nil, errors.Wrapf(err, "resolving intent at %s on end transaction [%s]", span, txn.Status) } } - // If the poison arg is set, make sure to set the abort span entry. - if args.Poison && txn.Status == roachpb.ABORTED { - if err := SetAbortSpan(ctx, evalCtx, batch, ms, txn.TxnMeta, true /* poison */); err != nil { + + if WriteAbortSpanOnResolve(txn.Status) { + if err := SetAbortSpan(ctx, evalCtx, batch, ms, txn.TxnMeta, args.Poison); err != nil { return nil, err } } - return externalIntents, nil } diff --git a/pkg/storage/batcheval/cmd_end_transaction_test.go b/pkg/storage/batcheval/cmd_end_transaction_test.go index ecddae31d447..3f8b5d462a28 100644 --- a/pkg/storage/batcheval/cmd_end_transaction_test.go +++ b/pkg/storage/batcheval/cmd_end_transaction_test.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" + "github.com/cockroachdb/cockroach/pkg/storage/abortspan" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -37,6 +38,7 @@ func TestEndTxnUpdatesTransactionRecord(t *testing.T) { StartKey: roachpb.RKey(startKey), EndKey: roachpb.RKey(endKey), } + as := abortspan.New(desc.RangeID) k, k2 := roachpb.Key("a"), roachpb.Key("b") ts, ts2, ts3 := hlc.Timestamp{WallTime: 1}, hlc.Timestamp{WallTime: 2}, hlc.Timestamp{WallTime: 3} @@ -1012,7 +1014,8 @@ func TestEndTxnUpdatesTransactionRecord(t *testing.T) { var resp roachpb.EndTxnResponse _, err := EndTxn(ctx, batch, CommandArgs{ EvalCtx: &mockEvalCtx{ - desc: &desc, + desc: &desc, + abortSpan: as, canCreateTxnFn: func() (bool, hlc.Timestamp, roachpb.TransactionAbortedReason) { require.NotNil(t, c.canCreateTxn, "CanCreateTxnRecord unexpectedly called") if can, minTS := c.canCreateTxn(); can { diff --git a/pkg/storage/batcheval/transaction_test.go b/pkg/storage/batcheval/transaction_test.go index 9e8592d973fa..40cece41682c 100644 --- a/pkg/storage/batcheval/transaction_test.go +++ b/pkg/storage/batcheval/transaction_test.go @@ -158,9 +158,8 @@ func TestSetAbortSpan(t *testing.T) { run: func(b engine.ReadWriter, rec EvalContext) error { return endTxn(b, rec, false /* commit */, false /* poison */) }, - // Not poisoning, should clean up abort span entry. However, it currently - // doesn't! See https://github.com/cockroachdb/cockroach/issues/29128. - exp: &prevTxnAbortSpanEntry, + // Not poisoning, should clean up abort span entry. + exp: nil, }, { name: "end txn, rollback, poison, abort span missing",