-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add support for context.Context #608
Merged
julienschmidt
merged 18 commits into
go-sql-driver:master
from
shogo82148:context-support
Jun 9, 2017
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7e64321
Add supports to context.Context
shogo82148 54ef181
add authors related context.Context support
shogo82148 66fa137
fix comment of mysqlContext.
shogo82148 06b17e6
closed is now just bool flag.
shogo82148 1705550
drop read-only transactions support
shogo82148 41940ff
remove unused methods from mysqlContext interface.
shogo82148 fd8a559
moved checking canceled logic into method of connection.
shogo82148 a464739
add a section about context.Context to the README.
shogo82148 1fdad70
use atomic variable for closed.
shogo82148 f96feaa
short circuit for context.Background()
shogo82148 4ce2087
fix illegal watching state
shogo82148 208cb44
set rows.finish directly.
shogo82148 31a7266
move namedValueToValue to utils_go18.go
shogo82148 09fbdfa
move static interface implementation checks to the top of the file
shogo82148 c4f9ae6
add the new section about `context.Context` to the table of contents,…
shogo82148 87ba95a
mark unsupported features with TODO comments
shogo82148 85f33dd
rename watcher to starter.
shogo82148 80f3f6f
use mc.error() instead of duplicated logics.
shogo82148 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package | ||
// | ||
// Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// +build go1.8 | ||
|
||
package mysql | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func benchmarkQueryContext(b *testing.B, db *sql.DB, p int) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
db.SetMaxIdleConns(p * runtime.GOMAXPROCS(0)) | ||
|
||
tb := (*TB)(b) | ||
stmt := tb.checkStmt(db.PrepareContext(ctx, "SELECT val FROM foo WHERE id=?")) | ||
defer stmt.Close() | ||
|
||
b.SetParallelism(p) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
b.RunParallel(func(pb *testing.PB) { | ||
var got string | ||
for pb.Next() { | ||
tb.check(stmt.QueryRow(1).Scan(&got)) | ||
if got != "one" { | ||
b.Fatalf("query = %q; want one", got) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkQueryContext(b *testing.B) { | ||
db := initDB(b, | ||
"DROP TABLE IF EXISTS foo", | ||
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))", | ||
`INSERT INTO foo VALUES (1, "one")`, | ||
`INSERT INTO foo VALUES (2, "two")`, | ||
) | ||
defer db.Close() | ||
for _, p := range []int{1, 2, 3, 4} { | ||
b.Run(fmt.Sprintf("%d", p), func(b *testing.B) { | ||
benchmarkQueryContext(b, db, p) | ||
}) | ||
} | ||
} | ||
|
||
func benchmarkExecContext(b *testing.B, db *sql.DB, p int) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
db.SetMaxIdleConns(p * runtime.GOMAXPROCS(0)) | ||
|
||
tb := (*TB)(b) | ||
stmt := tb.checkStmt(db.PrepareContext(ctx, "DO 1")) | ||
defer stmt.Close() | ||
|
||
b.SetParallelism(p) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
if _, err := stmt.ExecContext(ctx); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkExecContext(b *testing.B) { | ||
db := initDB(b, | ||
"DROP TABLE IF EXISTS foo", | ||
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))", | ||
`INSERT INTO foo VALUES (1, "one")`, | ||
`INSERT INTO foo VALUES (2, "two")`, | ||
) | ||
defer db.Close() | ||
for _, p := range []int{1, 2, 3, 4} { | ||
b.Run(fmt.Sprintf("%d", p), func(b *testing.B) { | ||
benchmarkQueryContext(b, db, p) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add the new section to the table of contents