Skip to content

Commit

Permalink
kv: fix GenerateForcedRetryableError to return a bumped epoch
Browse files Browse the repository at this point in the history
This is needed for PR #74563, where we change how txn is reset.
Without this change GenerateForcedRetryableError returns an
error with an inner txn that has an epoch 0. With this change
the epoch is copied from the original txn.

Release note: None
  • Loading branch information
lidorcarmel committed Jan 19, 2022
1 parent 419167d commit 304c548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 16 additions & 0 deletions pkg/kv/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
12 changes: 1 addition & 11 deletions pkg/kv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 304c548

Please sign in to comment.