Skip to content

Commit a776965

Browse files
committed
workload: use same key sequence during KV --insert-count
When inserting an initial --insert-count keys, use the configured key schema to insert the keys. This ensures that a subsequent call passing an appropriate --write-seq flag will read the keys inserted through --insert-count. Fix #107874. Epic: none Release note: none
1 parent 1041bf0 commit a776965

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pkg/workload/kv/kv.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,6 @@ func splitFinder(i, splits int, r keyRange, k keyTransformer) interface{} {
389389
return k.getKey(splitPoint)
390390
}
391391

392-
func insertCountKey(idx, count int64, kr keyRange) int64 {
393-
stride := kr.max/(count+1) - kr.min/(count+1)
394-
key := kr.min + (idx+1)*stride
395-
return key
396-
}
397-
398392
// Tables implements the Generator interface.
399393
func (w *kv) Tables() []workload.Table {
400394
// Tables should only run on initialized workload, safe to call create without
@@ -436,6 +430,9 @@ func (w *kv) Tables() []workload.Table {
436430
// INSERT ... ON CONFLICT DO NOTHING statements.
437431
MayContainDuplicates: !w.sequential,
438432
FillBatch: func(batchIdx int, cb coldata.Batch, a *bufalloc.ByteAllocator) {
433+
// Grab a new state for each batch, under the assumption that
434+
// FillBatch may be called concurrently.
435+
ks := kg.newState()
439436
rowBegin, rowEnd := batchIdx*batchSize, (batchIdx+1)*batchSize
440437
if rowEnd > w.insertCount {
441438
rowEnd = w.insertCount
@@ -451,11 +448,11 @@ func (w *kv) Tables() []workload.Table {
451448
{
452449
seq := rowBegin
453450
kg.transformer.fillColumnBatch(cb, a, func() (s int64, ok bool) {
454-
if seq < rowEnd {
455-
seq++
456-
return insertCountKey(int64(seq-1), int64(w.insertCount), kg.kr), true
451+
if seq >= rowEnd {
452+
return 0, false
457453
}
458-
return 0, false
454+
seq++
455+
return ks.mapKey.mapKey(int64(seq)), true
459456
})
460457
}
461458

0 commit comments

Comments
 (0)