Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
84652: workload/kv: randomly choose the start key for limited scans r=arulajmani a=arulajmani

The `span-limit` (in conjunction with `span-percent`) is used to
configure the kv workload to perform limited scans. Previously, we
would always perform these scans at the start of the keyspace. With this
patch, we now start the scan at a random start key instead. The key is
selected randomly based on the key generator specified for regular
read/write ops (uniform, sequential, or zipfian).

The behaviour of `span-limit` 0 is left unchanged.

Release note: None

Co-authored-by: Arul Ajmani <[email protected]>
  • Loading branch information
craig[bot] and arulajmani committed Jul 28, 2022
2 parents 3ed3138 + ac3a640 commit 9b5a2b7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/workload/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ func (w *kv) Ops(
buf.Reset()
buf.WriteString(`SELECT count(v) FROM [SELECT v FROM kv`)
if w.spanLimit > 0 {
fmt.Fprintf(&buf, ` ORDER BY k LIMIT %d`, w.spanLimit)
// Span statements without a limit query all ranges. However, if there's
// a span limit specified, we want to randomly choose the range from which
// the limited scan starts at. We do this by introducing the k >= $1
// predicate.
fmt.Fprintf(&buf, ` WHERE k >= $1 ORDER BY k LIMIT %d`, w.spanLimit)
}
buf.WriteString(`]`)
spanStmtStr := buf.String()
Expand Down Expand Up @@ -411,7 +415,13 @@ func (o *kvOp) run(ctx context.Context) (retErr error) {
statementProbability -= o.config.readPercent
if statementProbability < o.config.spanPercent {
start := timeutil.Now()
_, err := o.spanStmt.Exec(ctx)
var err error
if o.config.spanLimit > 0 {
arg := o.g.readKey()
_, err = o.spanStmt.Exec(ctx, arg)
} else {
_, err = o.spanStmt.Exec(ctx)
}
elapsed := timeutil.Since(start)
o.hists.Get(`span`).Record(elapsed)
return err
Expand Down

0 comments on commit 9b5a2b7

Please sign in to comment.