Skip to content

Commit

Permalink
kv: remove unnecessary use of Timestamp.WithSynthetic in tests
Browse files Browse the repository at this point in the history
Informs #101938.

These tests were using the Timestamp.WithSynthetic method even when
doing so was not necessary.

Release note: None
  • Loading branch information
nvanbenschoten committed Dec 27, 2023
1 parent 3325d32 commit 44af225
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 199 deletions.
8 changes: 3 additions & 5 deletions pkg/kv/kvclient/kvcoord/txn_coord_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ func TestTxnCoordSenderTxnUpdatedOnError(t *testing.T) {
func testTxnCoordSenderTxnUpdatedOnError(t *testing.T, isoLevel isolation.Level) {
ctx := context.Background()
origTS := makeTS(123, 0)
plus10 := origTS.Add(10, 10).WithSynthetic(false)
plus20 := origTS.Add(20, 0).WithSynthetic(false)
plus10 := origTS.Add(10, 10)
plus20 := origTS.Add(20, 0)
testCases := []struct {
// The test's name.
name string
Expand Down Expand Up @@ -1526,9 +1526,7 @@ func TestTxnCommitWait(t *testing.T) {
// transaction is read-write, it will need to bump its write
// timestamp above the other value.
if futureTime {
ts := txn.TestingCloneTxn().WriteTimestamp.
Add(futureOffset.Nanoseconds(), 0).
WithSynthetic(true)
ts := txn.TestingCloneTxn().WriteTimestamp.Add(futureOffset.Nanoseconds(), 0)
h := kvpb.Header{Timestamp: ts}
put := kvpb.NewPut(key, roachpb.Value{})
if _, pErr := kv.SendWrappedWith(ctx, s.DB.NonTransactionalSender(), h, put); pErr != nil {
Expand Down
9 changes: 2 additions & 7 deletions pkg/kv/kvserver/batcheval/cmd_end_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,13 +1301,8 @@ func TestCommitWaitBeforeIntentResolutionIfCommitTrigger(t *testing.T) {
expError: false,
},
{
name: "past-syn",
commitTS: func(now hlc.Timestamp) hlc.Timestamp { return now.WithSynthetic(true) },
expError: false,
},
{
name: "future-syn",
commitTS: func(now hlc.Timestamp) hlc.Timestamp { return now.Add(100, 0).WithSynthetic(true) },
name: "future",
commitTS: func(now hlc.Timestamp) hlc.Timestamp { return now.Add(100, 0) },
// If the EndTxn carried a commit trigger and its transaction will need
// to commit-wait because the transaction has a future-time commit
// timestamp, evaluating the request should return an error.
Expand Down
3 changes: 1 addition & 2 deletions pkg/kv/kvserver/client_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func TestStoreLeaseTransferTimestampCacheRead(t *testing.T) {
// Determine when to read.
readTS := tc.Servers[0].Clock().Now()
if futureRead {
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0).WithSynthetic(true)
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0)
}

// Read the key at readTS.
Expand Down Expand Up @@ -651,7 +651,6 @@ func TestStoreLeaseTransferTimestampCacheRead(t *testing.T) {
require.Nil(t, pErr)
require.NotEqual(t, readTS, br.Timestamp)
require.True(t, readTS.Less(br.Timestamp))
require.Equal(t, readTS.Synthetic, br.Timestamp.Synthetic)
})
}

Expand Down
12 changes: 3 additions & 9 deletions pkg/kv/kvserver/client_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func mergeWithData(t *testing.T, retries int64) {
//
// - futureRead: configures whether or not the reads performed on the RHS range
// before the merge is initiated are performed in the future of present
// time using synthetic timestamps.
// time.
func TestStoreRangeMergeTimestampCache(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand Down Expand Up @@ -565,7 +565,7 @@ func mergeCheckingTimestampCaches(

readTS := tc.Servers[0].Clock().Now()
if futureRead {
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0).WithSynthetic(true)
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0)
}

// Simulate a read on the RHS from a node with a newer clock.
Expand Down Expand Up @@ -1178,14 +1178,8 @@ func TestStoreRangeMergeTxnRefresh(t *testing.T) {
// Detect the range merge's deletion of the local range descriptor
// and use it as an opportunity to bump the merge transaction's
// write timestamp. This will necessitate a refresh.
//
// Also mark as synthetic, while we're here, to simulate the
// behavior of a range merge across two ranges with the
// LEAD_FOR_GLOBAL_READS closed timestamp policy.
if !v.Value.IsPresent() && bytes.HasSuffix(v.Key, keys.LocalRangeDescriptorSuffix) {
br.Txn.WriteTimestamp = br.Txn.WriteTimestamp.
Add(100*time.Millisecond.Nanoseconds(), 0).
WithSynthetic(true)
br.Txn.WriteTimestamp = br.Txn.WriteTimestamp.Add(100*time.Millisecond.Nanoseconds(), 0)
}
case *kvpb.RefreshRequest:
if bytes.HasSuffix(v.Key, keys.LocalRangeDescriptorSuffix) {
Expand Down
16 changes: 6 additions & 10 deletions pkg/kv/kvserver/client_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func TestReplicaClockUpdates(t *testing.T) {
clock.Pause()
}
// Pick a timestamp in the future of all nodes by less than the
// MaxOffset. Set the synthetic flag according to the test case.
reqTS := clocks[0].Now().Add(clocks[0].MaxOffset().Nanoseconds()/2, 0).WithSynthetic(synthetic)
// MaxOffset.
reqTS := clocks[0].Now().Add(clocks[0].MaxOffset().Nanoseconds()/2, 0)
h := kvpb.Header{Timestamp: reqTS}
if !reqTS.Synthetic {
if !synthetic {
h.Now = hlc.ClockTimestamp(reqTS)
}

Expand Down Expand Up @@ -1922,17 +1922,14 @@ func TestLeaseExpirationBelowFutureTimeRequest(t *testing.T) {
now := l.tc.Servers[1].Clock().Now()

// Construct a future-time request timestamp past the current lease's
// expiration. Remember to set the synthetic bit so that it is not used
// to update the store's clock. See Replica.checkRequestTimeRLocked for
// the exact determination of whether a request timestamp is too far in
// the future or not.
// expiration. See Replica.checkRequestTimeRLocked for the determination
// of whether a request timestamp is too far in the future or not.
leaseRenewal := l.tc.Servers[1].RaftConfig().RangeLeaseRenewalDuration()
leaseRenewalMinusStasis := leaseRenewal - l.tc.Servers[1].Clock().MaxOffset()
reqTime := now.Add(leaseRenewalMinusStasis.Nanoseconds()-10, 0)
if tooFarInFuture {
reqTime = reqTime.Add(20, 0)
}
reqTime = reqTime.WithSynthetic(true)

// Issue a get with the request timestamp.
args := getArgs(l.leftKey)
Expand Down Expand Up @@ -2834,7 +2831,7 @@ func TestLeaseTransferInSnapshotUpdatesTimestampCache(t *testing.T) {
// Determine when to read.
readTS := tc.Servers[0].Clock().Now()
if futureRead {
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0).WithSynthetic(true)
readTS = readTS.Add(500*time.Millisecond.Nanoseconds(), 0)
}

// Read the key at readTS.
Expand Down Expand Up @@ -2911,7 +2908,6 @@ func TestLeaseTransferInSnapshotUpdatesTimestampCache(t *testing.T) {
require.Nil(t, pErr)
require.NotEqual(t, readTS, br.Timestamp)
require.True(t, readTS.Less(br.Timestamp))
require.Equal(t, readTS.Synthetic, br.Timestamp.Synthetic)
})
}

Expand Down
Loading

0 comments on commit 44af225

Please sign in to comment.