-
Notifications
You must be signed in to change notification settings - Fork 998
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
make sure mysql is healthy when start proxy #701
Conversation
Given that I personally don't use this connection pooling, this seems a fair change: ultimately this would return an error when a connection to the mysql backend could not be set up, ór when the handshake would fail. |
I don't think this is a right enhancement. Pools are usually lazy initialized, for example. sql.Open will not check if it can dail the MySQL. And users may want to implement their own checking logic, for example, start the proxy in advance, backoff and retry to see if the connection become ready. |
Maybe I don't quite agree whit that. sql.Open() return DB object and did not do any dailing work, when I use db.Ping(),it reminds me connect error.But when I use pool.GetConn(), it will be blocked if mysql server is down. And when I do NewPool(),it has dialed mysql server ,so it has responsibility to return the result of dialing |
I insist on my point and thanks for your response anyway. |
I'm not sure about this, maybe you are refering Line 121 in 62e8407
I think this is expecpted of DB.Conn, "Conn will block until either a connection is returned or ctx is canceled."
You still can use it. |
if minAlive > 0,it will dial mysql server Immediately,check line 123 |
Sorry I didn't notice this line. Now I think this PR is reasonable, will review soon. |
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.
I think we should make it clear about the definition of minAlive
. As the behaviour and the comment of NewPool, "minAlive specifies the minimum number of open connections that the pool will try to maintain", "try to maintain" does not mean "must maintain", in other words does not mean it should return error when fails to maintain.
If you think the definition is "must maintain", take this as an example. After the server starts it has maintained 10 connections, now we call GetConn and for idle connection we do a ping, find that the network is bad and we can't dial new connection. "must maintain" means the whole server should be stopped at the moment.
Also since this PR will change the interface and break compatibility, I'd reject it if there's no strong reason.
pool.startNewConnections(needSpanNew) | ||
if err := pool.startNewConnections(needSpanNew); err != nil { | ||
pool.logFunc(`Pool: Setup startNewConnections failed,err : %v`, err) | ||
return false |
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.
here we should return true? because for false caller will try to close redundant connections, but if we go here we are lack of connections.
don't confuse starting and runtime,you have dailing action during starting,but you don't care the result.As you said,you just dail and it is not your business if it succeed or not.All a develop can do is using context.WithTimeout(),but can not know why failed because you did not handle the dialing error.your another opinion between |
Maybe you can add a MustNewPoolWithConns or (*Pool).MustConns so the old interface is not changed. If other user see minAlive parameter, he/she may think it's used to reduce the warmup cost when GetConn, not a "must maintain". It's still about the definition. If you still insist to change the behaviour of
|
Maybe it is better adding a new method than changing the behaviour of |
Hello. I'll carefully read your discussion today and will write what I think. At first glance, MustNewPoolWithConns looks like a good choice. It's ok for you? P.S.And sorry for so late response :) |
I think |
func NewPool(...) return no error when mysql server is down, adding an error return when dialing mysql failed
close #700