Skip to content
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

vttablet: don't shutdown on too many connections #7039

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions go/mysql/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package mysql

import "strings"

const (
// MaxPacketSize is the maximum payload length of a packet
// the server supports.
Expand Down Expand Up @@ -602,13 +604,26 @@ func IsNum(typ uint8) bool {

// IsConnErr returns true if the error is a connection error.
func IsConnErr(err error) bool {
if IsTooManyConnectionsErr(err) {
return false
}
if sqlErr, ok := err.(*SQLError); ok {
num := sqlErr.Number()
return (num >= CRUnknownError && num <= CRNamedPipeStateError) || num == ERQueryInterrupted
}
return false
}

// IsTooManyConnectionsErr returns true if the error is due to too many connections.
func IsTooManyConnectionsErr(err error) bool {
if sqlErr, ok := err.(*SQLError); ok {
if sqlErr.Number() == CRServerHandshakeErr && strings.Contains(sqlErr.Message, "Too many connections") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: string literal should be made into a constant.

return true
}
}
return false
}

// IsSchemaApplyError returns true when given error is a MySQL error applying schema change
func IsSchemaApplyError(err error) bool {
merr, isSQLErr := err.(*SQLError)
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vttablet/tabletserver/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/cache"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/stats"
"vitess.io/vitess/go/streamlog"
"vitess.io/vitess/go/sync2"
Expand Down Expand Up @@ -372,6 +373,9 @@ func (qe *QueryEngine) ClearQueryPlanCache() {
func (qe *QueryEngine) IsMySQLReachable() error {
conn, err := dbconnpool.NewDBConnection(context.TODO(), qe.env.Config().DB.AppWithDB())
if err != nil {
if mysql.IsTooManyConnectionsErr(err) {
return nil
}
return err
}
conn.Close()
Expand Down