diff --git a/pkg/kv/db_test.go b/pkg/kv/db_test.go index b7f34cc08a34..ea9d845f3497 100644 --- a/pkg/kv/db_test.go +++ b/pkg/kv/db_test.go @@ -699,3 +699,19 @@ func TestDBDecommissionedOperations(t *testing.T) { }) } } + +// TestGenerateForcedRetryableError verifies that GenerateForcedRetryableError +// returns an error with a transaction that had the epoch bumped (and not epoch 0). +func TestGenerateForcedRetryableError(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + ctx := context.Background() + s, db := setup(t) + defer s.Stopper().Stop(context.Background()) + txn := db.NewTxn(ctx, "test: TestGenerateForcedRetryableError") + require.Equal(t, 0, int(txn.Epoch())) + err := txn.GenerateForcedRetryableError(ctx, "testing TestGenerateForcedRetryableError") + var retryErr *roachpb.TransactionRetryWithProtoRefreshError + require.True(t, errors.As(err, &retryErr)) + require.Equal(t, 1, int(retryErr.Transaction.Epoch)) +} diff --git a/pkg/kv/txn.go b/pkg/kv/txn.go index 012c9131e3b8..4c9d80c49da1 100644 --- a/pkg/kv/txn.go +++ b/pkg/kv/txn.go @@ -1468,17 +1468,7 @@ func (txn *Txn) GenerateForcedRetryableError(ctx context.Context, msg string) er now := txn.db.clock.NowAsClockTimestamp() txn.mu.sender.ManualRestart(ctx, txn.mu.userPriority, now.ToTimestamp()) txn.resetDeadlineLocked() - return roachpb.NewTransactionRetryWithProtoRefreshError( - msg, - txn.mu.ID, - roachpb.MakeTransaction( - txn.debugNameLocked(), - nil, // baseKey - txn.mu.userPriority, - now.ToTimestamp(), - txn.db.clock.MaxOffset().Nanoseconds(), - int32(txn.db.ctx.NodeID.SQLInstanceID())), - ) + return txn.mu.sender.PrepareRetryableError(ctx, msg) } // PrepareRetryableError returns a