Skip to content

Commit

Permalink
storage: use hlc.ParseTimestamp in TestMVCCHistories
Browse files Browse the repository at this point in the history
Adapted from cockroachdb#57077.

Also switch over TestIntentInterleavingIter and TestIntentDemuxWriter.

No need to re-write the parsing logic again. We'll also want this to use
flags in the next commit.

This causes a large diff because all nanos are now considered seconds.
This doesn't actually change any behavior in the tests themselves.
  • Loading branch information
nvanbenschoten committed Jan 5, 2021
1 parent 4c9bb63 commit 77832cd
Show file tree
Hide file tree
Showing 39 changed files with 1,340 additions and 1,289 deletions.
41 changes: 27 additions & 14 deletions pkg/storage/intent_interleaving_iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ func makePrintableKey(k MVCCKey) MVCCKey {
func scanSeekKey(t *testing.T, td *datadriven.TestData) MVCCKey {
key := MVCCKey{Key: scanRoachKey(t, td, "k")}
if td.HasArg("ts") {
var ts int
td.ScanArgs(t, "ts", &ts)
key.Timestamp.WallTime = int64(ts)
var tsS string
td.ScanArgs(t, "ts", &tsS)
ts, err := hlc.ParseTimestamp(tsS)
if err != nil {
t.Fatalf("%v", err)
}
key.Timestamp = ts
}
return key
}
Expand Down Expand Up @@ -139,13 +143,13 @@ func checkAndOutputIter(iter MVCCIterator, b *strings.Builder) {
if uuid.Hi != 0 {
hiStr = fmt.Sprintf("%d,", uuid.Hi)
}
fmt.Fprintf(b, "output: meta k=%s ts=%d txn=%s%d\n",
string(k1.Key), meta.Timestamp.WallTime, hiStr, uuid.Lo)
fmt.Fprintf(b, "output: meta k=%s ts=%s txn=%s%d\n",
string(k1.Key), meta.Timestamp, hiStr, uuid.Lo)
}
return
}
fmt.Fprintf(b, "output: value k=%s ts=%d v=%s\n",
string(k1.Key), k1.Timestamp.WallTime, string(v1))
fmt.Fprintf(b, "output: value k=%s ts=%s v=%s\n",
string(k1.Key), k1.Timestamp, string(v1))
}

// TestIntentInterleavingIter is a datadriven test consisting of two commands:
Expand Down Expand Up @@ -223,9 +227,14 @@ func TestIntentInterleavingIter(t *testing.T) {
var meta enginepb.MVCCMetadata
var txnUUID uuid.UUID
if locksSection || d.HasArg("ts") {
var ts, txn int
d.ScanArgs(t, "ts", &ts)
meta.Timestamp.WallTime = int64(ts)
var tsS string
d.ScanArgs(t, "ts", &tsS)
ts, err := hlc.ParseTimestamp(tsS)
if err != nil {
t.Fatalf("%v", err)
}
meta.Timestamp = ts.ToLegacyTimestamp()
var txn int
d.ScanArgs(t, "txn", &txn)
txnUUID = uuid.FromUint128(uint128.FromInts(0, uint64(txn)))
meta.Txn = &enginepb.TxnMeta{ID: txnUUID}
Expand All @@ -252,11 +261,15 @@ func TestIntentInterleavingIter(t *testing.T) {
t.Fatalf("%s: value in locks section", d.Pos)
}
key := scanRoachKey(t, d, "k")
var ts int
d.ScanArgs(t, "ts", &ts)
var tsS string
d.ScanArgs(t, "ts", &tsS)
ts, err := hlc.ParseTimestamp(tsS)
if err != nil {
t.Fatalf("%v", err)
}
var value string
d.ScanArgs(t, "v", &value)
mvccKey := MVCCKey{Key: key, Timestamp: hlc.Timestamp{WallTime: int64(ts)}}
mvccKey := MVCCKey{Key: key, Timestamp: ts}
if err := batch.PutMVCC(mvccKey, []byte(value)); err != nil {
return err.Error()
}
Expand Down Expand Up @@ -442,7 +455,7 @@ func generateIterOps(rng *rand.Rand, mvcckv []MVCCKeyValue) []string {
fwdDirection = false
}
if useTimestamp {
op = fmt.Sprintf("%s k=%s ts=%d", op, string(seekKey.Key), seekKey.Timestamp.WallTime)
op = fmt.Sprintf("%s k=%s ts=%s", op, string(seekKey.Key), seekKey.Timestamp)
} else {
op = fmt.Sprintf("%s k=%s", op, string(seekKey.Key))
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/storage/intent_reader_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/uint128"
Expand Down Expand Up @@ -217,9 +218,14 @@ func TestIntentDemuxWriter(t *testing.T) {
key := scanRoachKey(t, d, "k")
// We don't bother populating most fields in the proto.
var meta enginepb.MVCCMetadata
var ts, txn int
d.ScanArgs(t, "ts", &ts)
meta.Timestamp.WallTime = int64(ts)
var tsS string
d.ScanArgs(t, "ts", &tsS)
ts, err := hlc.ParseTimestamp(tsS)
if err != nil {
t.Fatalf("%v", err)
}
meta.Timestamp = ts.ToLegacyTimestamp()
var txn int
d.ScanArgs(t, "txn", &txn)
txnUUID := uuid.FromUint128(uint128.FromInts(0, uint64(txn)))
meta.Txn = &enginepb.TxnMeta{ID: txnUUID}
Expand Down
16 changes: 1 addition & 15 deletions pkg/storage/mvcc_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,24 +880,10 @@ func (e *evalCtx) getTsWithName(txn *roachpb.Transaction, name string) hlc.Times
}
var tsS string
e.scanArg(name, &tsS)
parts := strings.Split(tsS, ",")

// Find the wall time part.
tsW, err := strconv.ParseInt(parts[0], 10, 64)
ts, err := hlc.ParseTimestamp(tsS)
if err != nil {
e.Fatalf("%v", err)
}
ts.WallTime = tsW

// Find the logical part, if there is one.
var tsL int64
if len(parts) > 1 {
tsL, err = strconv.ParseInt(parts[1], 10, 32)
if err != nil {
e.Fatalf("%v", err)
}
}
ts.Logical = int32(tsL)
return ts
}

Expand Down
Loading

0 comments on commit 77832cd

Please sign in to comment.