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

server: return error on ping when in graceful shutdown #58008

Merged
merged 4 commits into from
Dec 14, 2024
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
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,11 @@ error = '''
Access denied for user '%-.48s'@'%-.255s' (using password: %s)
'''

["server:1053"]
error = '''
Server shutdown in progress
'''

["server:1148"]
error = '''
The used command is not allowed with this MySQL version
Expand Down
5 changes: 4 additions & 1 deletion pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,10 @@ func (cc *clientConn) dispatch(ctx context.Context, data []byte) error {
return cc.writeStats(ctx)
// ComProcessInfo, ComConnect, ComProcessKill, ComDebug
case mysql.ComPing:
return cc.writeOK(ctx)
if cc.server.health.Load() {
return cc.writeOK(ctx)
}
return servererr.ErrServerShutdown
case mysql.ComChangeUser:
return cc.handleChangeUser(ctx, data)
// ComBinlogDump, ComTableDump, ComConnectOut, ComRegisterSlave
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ func testDispatch(t *testing.T, inputs []dispatchInput, capability uint32) {
cfg.Status.ReportStatus = false
server, err := NewServer(cfg, tidbdrv)
require.NoError(t, err)

// Set healthy. This is used by graceful shutdown
// and is used in the response for ComPing and the
// /status HTTP endpoint
server.health.Store(true)
defer server.Close()

cc := &clientConn{
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/err/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ var (
ErrNetPacketTooLarge = dbterror.ClassServer.NewStd(errno.ErrNetPacketTooLarge)
// ErrMustChangePassword is returned when the user must change the password.
ErrMustChangePassword = dbterror.ClassServer.NewStd(errno.ErrMustChangePassword)
// ErrServerShutdown is returned when the server is shutting down.
ErrServerShutdown = dbterror.ClassServer.NewStd(errno.ErrServerShutdown)
)