Skip to content

Commit

Permalink
Merge #83373
Browse files Browse the repository at this point in the history
83373: batcheval: fix key ordering in `TestRandomKeyAndTimestampExport` r=nicktrav a=erikgrinaker

`TestRandomKeyAndTimestampExport` was supposed to generate a set of
ordered random keys by prefixing the random byte string with a
text-formatted sequence number. However, the sequence number was not
padded, so e.g. `#314` could precede `#1000`. This led it to generate
bogus iterator bounds, where the lower bound was ordered after the upper
bound, triggering iterator assertion failures.

This patch correctly left-pads the number with `0` to maintain correct
lexicographic ordering.

Resolves #83370.

Release note: None

Co-authored-by: Erik Grinaker <[email protected]>
  • Loading branch information
craig[bot] and erikgrinaker committed Jun 25, 2022
2 parents 8fef727 + a7afafa commit a9c3b6d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/kv/kvserver/batcheval/cmd_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"math"
"math/rand"
"sort"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -706,20 +707,18 @@ func TestRandomKeyAndTimestampExport(t *testing.T) {
var keys []roachpb.Key
var timestamps []hlc.Timestamp

var curWallTime = 0
var curLogical = 0

numDigits := len(strconv.Itoa(numKeys))
batch := e.NewBatch()
for i := 0; i < numKeys; i++ {
// Ensure walltime and logical are monotonically increasing.
curWallTime = randutil.RandIntInRange(rnd, 0, math.MaxInt64-1)
curLogical = randutil.RandIntInRange(rnd, 0, math.MaxInt32-1)
curWallTime := randutil.RandIntInRange(rnd, 0, math.MaxInt64-1)
curLogical := randutil.RandIntInRange(rnd, 0, math.MaxInt32-1)
ts := hlc.Timestamp{WallTime: int64(curWallTime), Logical: int32(curLogical)}
timestamps = append(timestamps, ts)

// Make keys unique and ensure they are monotonically increasing.
key := roachpb.Key(randutil.RandBytes(rnd, keySize))
key = append([]byte(fmt.Sprintf("#%d", i)), key...)
key = append([]byte(fmt.Sprintf("#%0"+strconv.Itoa(numDigits)+"d", i)), key...)
keys = append(keys, key)

averageValueSize := bytesPerValue - keySize
Expand Down

0 comments on commit a9c3b6d

Please sign in to comment.