diff --git a/pkg/kv/txn_coord_sender_test.go b/pkg/kv/txn_coord_sender_test.go index 9350099a9ff7..75e899976460 100644 --- a/pkg/kv/txn_coord_sender_test.go +++ b/pkg/kv/txn_coord_sender_test.go @@ -676,7 +676,7 @@ func TestTxnCoordSenderTxnUpdatedOnError(t *testing.T) { ctx := context.Background() origTS := makeTS(123, 0) plus10 := origTS.Add(10, 10) - plus20 := plus10.Add(10, 0) + plus20 := origTS.Add(20, 0) testCases := []struct { // The test's name. name string @@ -778,6 +778,10 @@ func TestTxnCoordSenderTxnUpdatedOnError(t *testing.T) { if pErr == nil { reply = ba.CreateReply() reply.Txn = ba.Txn + } else if txn := pErr.GetTxn(); txn != nil { + // Update the manual clock to simulate an + // error updating a local hlc clock. + manual.Set(txn.Timestamp.WallTime) } return reply, pErr } diff --git a/pkg/roachpb/data.go b/pkg/roachpb/data.go index 6a66225626f8..567559a9002e 100644 --- a/pkg/roachpb/data.go +++ b/pkg/roachpb/data.go @@ -1153,20 +1153,17 @@ func PrepareTransactionForRetry( // TODO(andrei): Should we preserve the ObservedTimestamps across the // restart? errTxnPri := txn.Priority - // The OrigTimestamp of the new transaction is going to be the greater of - // two the current clock and the timestamp received in the error. - // TODO(andrei): Can we just use the clock since it has already been - // advanced to at least the error's timestamp? + // Start the new transaction at the current time from the local clock. + // The local hlc should have been advanced to at least the error's + // timestamp already. now := clock.Now() - newTxnTimestamp := now - newTxnTimestamp.Forward(txn.Timestamp) txn = MakeTransaction( txn.Name, nil, // baseKey // We have errTxnPri, but this wants a UserPriority. So we're going to // overwrite the priority below. NormalUserPriority, - newTxnTimestamp, + now, clock.MaxOffset().Nanoseconds(), ) // Use the priority communicated back by the server.