Skip to content

Commit ba89df8

Browse files
committed
kvserver: better obs in TestTxnReadWithinUncertaintyIntervalAfterRangeMerge
This is a complex test with a rare failure mode. Trace all of the relevant operations so that we can meaningfully engage with it. Epic: none Release note: none
1 parent 7322878 commit ba89df8

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

pkg/kv/kvserver/client_replica_test.go

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,21 +1011,52 @@ func TestTxnReadWithinUncertaintyIntervalAfterRangeMerge(t *testing.T) {
10111011
// writing.
10121012
manuals[2].Increment(2000)
10131013

1014+
defer func() {
1015+
if !t.Failed() {
1016+
return
1017+
}
1018+
t.Logf("maxNanos=%d", maxNanos)
1019+
t.Logf("manuals[2]=%d", manuals[2].UnixNano())
1020+
}()
1021+
10141022
// Write the data from a different transaction to establish the time for the
10151023
// key as 10 ns in the future.
1016-
_, pErr := kv.SendWrapped(ctx, tc.Servers[2].DistSenderI().(kv.Sender), putArgs(keyC, []byte("value")))
1017-
require.Nil(t, pErr)
1024+
{
1025+
ctx, fagrs := tracing.ContextWithRecordingSpan(ctx, tc.Servers[0].Tracer(), "keyC-write")
1026+
resp, pErr := kv.SendWrapped(ctx, tc.Servers[2].DistSenderI().(kv.Sender), putArgs(keyC, []byte("value")))
1027+
rec := fagrs()
1028+
require.Nil(t, pErr, "%v", rec)
1029+
defer func() {
1030+
if !t.Failed() {
1031+
return
1032+
}
1033+
t.Logf("keyC-write: %+v", resp)
1034+
t.Logf("keyC-write: %s", rec)
1035+
}()
1036+
}
10181037

10191038
// Create two identical transactions. The first one will perform a read to a
10201039
// store before the merge, the second will only read after the merge.
10211040
txn := roachpb.MakeTransaction("txn1", keyA, isolation.Serializable, 1, now, maxOffset, instanceId, 0, false /* omitInRangefeeds */)
10221041
txn2 := roachpb.MakeTransaction("txn2", keyA, isolation.Serializable, 1, now, maxOffset, instanceId, 0, false /* omitInRangefeeds */)
10231042

1024-
// Simulate a read which will cause the observed time to be set to now
1025-
resp, pErr := kv.SendWrappedWith(ctx, tc.Servers[1].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn}, getArgs(keyA))
1026-
require.Nil(t, pErr)
1027-
// The client needs to update its transaction to the returned transaction which has observed timestamps in it
1028-
txn = *resp.Header().Txn
1043+
// Simulate a read which will cause the observed time to be set to now.
1044+
{
1045+
ctx, fagrs := tracing.ContextWithRecordingSpan(ctx, tc.Servers[0].Tracer(), "txn1-keyA-get")
1046+
resp, pErr := kv.SendWrappedWith(ctx, tc.Servers[1].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn}, getArgs(keyA))
1047+
rec := fagrs()
1048+
require.Nil(t, pErr, "%v", rec)
1049+
// The client needs to update its transaction to the returned transaction which has observed timestamps in it
1050+
txn = *resp.Header().Txn
1051+
defer func() {
1052+
if !t.Failed() {
1053+
return
1054+
}
1055+
t.Logf("txn1-keyA-get: %+v", resp)
1056+
t.Logf("txn1-keyA-get: %s", rec)
1057+
t.Logf("txn1-keyA-get resp txn: %s", txn)
1058+
}()
1059+
}
10291060

10301061
// Now move the ranges, being careful not to move either leaseholder
10311062
// C: 3 (RHS - replica) => 0 (LHS leaseholder)
@@ -1048,8 +1079,13 @@ func TestTxnReadWithinUncertaintyIntervalAfterRangeMerge(t *testing.T) {
10481079

10491080
// Try and read the transaction from the context of a new transaction. This
10501081
// will fail as expected as the observed timestamp will not be set.
1051-
_, pErr = kv.SendWrappedWith(ctx, tc.Servers[0].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn2}, getArgs(keyC))
1052-
require.IsType(t, &kvpb.ReadWithinUncertaintyIntervalError{}, pErr.GetDetail())
1082+
{
1083+
ctx, fagrs := tracing.ContextWithRecordingSpan(ctx, tc.Servers[0].Tracer(), "txn2get-should-rwue")
1084+
_, pErr := kv.SendWrappedWith(ctx, tc.Servers[0].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn2},
1085+
getArgs(keyC))
1086+
rec := fagrs()
1087+
require.IsType(t, &kvpb.ReadWithinUncertaintyIntervalError{}, pErr.GetDetail(), "%s", rec)
1088+
}
10531089

10541090
// Try and read the key from the existing transaction. This should fail the
10551091
// same way.
@@ -1058,8 +1094,12 @@ func TestTxnReadWithinUncertaintyIntervalAfterRangeMerge(t *testing.T) {
10581094
// - Other error (Bad) - We expect an uncertainty error so the client can choose a new timestamp and retry.
10591095
// - Not found (Bad) - Error because the data was written before us.
10601096
// - Found (Bad) - The write HLC timestamp is after our timestamp.
1061-
_, pErr = kv.SendWrappedWith(ctx, tc.Servers[0].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn}, getArgs(keyC))
1062-
require.IsType(t, &kvpb.ReadWithinUncertaintyIntervalError{}, pErr.GetDetail())
1097+
{
1098+
ctx, fagrs := tracing.ContextWithRecordingSpan(ctx, tc.Servers[0].Tracer(), "txn1get-should-rwue")
1099+
_, pErr := kv.SendWrappedWith(ctx, tc.Servers[0].DistSenderI().(kv.Sender), kvpb.Header{Txn: &txn}, getArgs(keyC))
1100+
rec := fagrs()
1101+
require.IsType(t, &kvpb.ReadWithinUncertaintyIntervalError{}, pErr.GetDetail(), "%s", rec)
1102+
}
10631103
}
10641104

10651105
testutils.RunTrueAndFalse(t, "alignLeaseholders", func(t *testing.T, alignLeaseholders bool) {

0 commit comments

Comments
 (0)