Skip to content

Commit

Permalink
roachpb: ignore error timestamp when restarting aborted txn
Browse files Browse the repository at this point in the history
The local hlc should have been advanced to at least the error's
timestamp by the time PrepareTransactionForRetry is called.

Release note: None
  • Loading branch information
nvanbenschoten committed Jan 7, 2019
1 parent ab4dffb commit 7472973
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pkg/kv/txn_coord_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 4 additions & 7 deletions pkg/roachpb/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7472973

Please sign in to comment.