Skip to content

workload/ycsb: Use StmtContext instead of Stmt #39525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/workload/ycsb/ycsb.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ func (yw *ycsbWorker) readModifyWriteRow(ctx context.Context) error {
fieldIdx := yw.rng.Intn(numTableFields)
var args [2]interface{}
args[0] = key
return crdb.ExecuteTx(ctx, yw.db, nil, func(tx *gosql.Tx) error {
err := crdb.ExecuteTx(ctx, yw.db, nil, func(tx *gosql.Tx) error {
var oldValue []byte
if err := yw.readFieldStmts[fieldIdx].QueryRowContext(ctx, key).Scan(&oldValue); err != nil {
if err := tx.StmtContext(ctx, yw.readFieldStmts[fieldIdx]).QueryRowContext(ctx, key).Scan(&oldValue); err != nil {
return err
}
var updateStmt *gosql.Stmt
Expand All @@ -585,9 +585,17 @@ func (yw *ycsbWorker) readModifyWriteRow(ctx context.Context) error {
updateStmt = yw.updateStmts[fieldIdx]
args[1] = newValue
}
_, err := tx.Stmt(updateStmt).ExecContext(ctx, args[:]...)
_, err := tx.StmtContext(ctx, updateStmt).ExecContext(ctx, args[:]...)
return err
})
if err == gosql.ErrNoRows && ctx.Err() != nil {
// Sometimes a context cancellation during a transaction can result in
// sql.ErrNoRows instead of the appropriate context.DeadlineExceeded. In
// this case, we just return ctx.Err(). See
// https://github.com/lib/pq/issues/874.
return ctx.Err()
}
return err
}

// Choose an operation in proportion to the frequencies.
Expand Down