-
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 supports to context.Context #551
Conversation
Thank you for your efforts. Before reviewing,
|
@methane I know how to use build tag to make the code adapted to different operating systems automatically, but cannot figure out how to use build tag for adaption to different go compiler versions. The ideal state is that, developers just import the package into their code (with different go compiler versions), and don't need to do any extra work. Do you have any good idea for this? |
Use two files: one for versions pre 1.8 and one for version 1.8 and later. The required build tags are:
in the pre 1.8 file, and
for the 1.8+ file. |
@julienschmidt Thank you. Build tag @methane About spliting the pull request into small ones, perhaps the job is not necessary, because the major code changes lies in |
@oscarzhao I don't like |
@methane The introduction of Since the beginning of this pull request, I've been thinking about how to reuse existing code(for previous versions of golang), how to keep code's readability and maintainability. I've tried to reuse existing code as much as possible, which results to very bad readability, the logic becomes confusing and difficult to understand. That's why I keep all the existing code as it is for golang pre 1.8. In this way, I think the build tag PS: An alternative solution is that we implements the cancel mechanism via COM_PROCESS_KILL command, and then add context support in the way similar to Postgres driver. I will try this solution asap. |
OK, I'll start review in this week. |
|
||
/****************************************************************************** | ||
* Initialisation Process * | ||
******************************************************************************/ |
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.
Don't decorate.
https://golang.org/doc/effective_go.html#commentary
Comments do not need extra formatting such as banners of stars.
if err == nil { | ||
// Read Result | ||
var resLen int | ||
resLen, err = mc.readResultSetHeaderPacket() |
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.
Waiting response should be cancellable.
IMHO: PR contains a lot of code duplication, it will be hard to manage this code in future, because it will require to update each thing in 2 places. |
I have done POC, you can found results here https://github.com/bgaifullin/mysql/tree/support_context I cannot avoid file connection_go18.go, because driver.TxOptions, driver.NamedValue was introduced in go1.8. but I avoid code duplication and just reuse the same function like it has done in lib/pg |
@bgaifullin Thanks. |
We're now at Go 1.8. I think supporting the 3 most recent Go versions should be sufficient, but we should discuss this in a separate issue then. Edit: It seems like only the 2 most recent Go versions receive official support: https://golang.org/dl/ |
And the current amount of code duplication in this PR is definitely not acceptable |
@julienschmidt How about adding new experimental "context" branch which supports only Go 1.7+?
|
copy-paste from issue:
func (mc *mysqlConn) cancel() {
mc.netConn.SetDeadline(time.Now())
}
|
I am not a go expert and try to make use of the Context with a deadline. My code is doing..
And then I run a "broken" MySQL server using:
the operation does not time out. Is there any way to get PingContext to honor the Deadline set? This was tried with master and this pull request. |
That's actually a pretty good idea for a test we should add! |
That would be great! After reading the code and the SQL package definition I wonder:
In the case of this driver Open will open a TCP connection to the driver and issue a blocking(?) call to mc.readInitPacket(). As Open doesn't take a context maybe this code should be moved to Ping/PingContext? |
I've created PR #586 with basically the same code (credit given) that manages to get rid of the code duplication. Please take a look and see if perhaps it's a little more palatable. |
Closed in favor of #608. Please provide your feedback there. |
Description
driver.ConnBeginTx
,driver.QueryerContext
,driver.ExecerContext
,driver.ConnBeginTx
interfacedriver.Pinger
interfacedriver.StmtQueryContext
,driver.StmtExecContext
interfacerefer to issue 496
Checklist
Build tag
go1.8
is used to adapt to both version pre 1.8 and 1.8+, previous code is kept as it was to support go1.2~go1.7.