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

Add VTGate drain flag #15953

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions go/flags/endtoend/vtgate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Flags:
--mysql_ldap_auth_config_string string JSON representation of LDAP server config.
--mysql_ldap_auth_method string client-side authentication method to use. Supported values: mysql_clear_password, dialog. (default "mysql_clear_password")
--mysql_server_bind_address string Binds on this address when listening to MySQL binary protocol. Useful to restrict listening to 'localhost' only for instance.
--mysql_server_drain_onterm If set, the server waits for --onterm_timeout for connected clients to drain
--mysql_server_flush_delay duration Delay after which buffered response will be flushed to the client. (default 100ms)
--mysql_server_port int If set, also listen for MySQL binary protocol connections on this port. (default -1)
--mysql_server_query_timeout duration mysql query timeout
Expand Down
2 changes: 1 addition & 1 deletion go/vt/servenv/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func Run(bindAddress string, port int) {
signal.Notify(ExitChan, syscall.SIGTERM, syscall.SIGINT)
// Wait for signal
<-ExitChan
l.Close()

startTime := time.Now()
log.Infof("Entering lameduck mode for at least %v", timeouts.LameduckPeriod)
Expand All @@ -71,6 +70,7 @@ func Run(bindAddress string, port int) {
log.Infof("Sleeping an extra %v after OnTermSync to finish lameduck period", remain)
time.Sleep(remain)
}
l.Close()

log.Info("Shutting down gracefully")
fireOnCloseHooks(timeouts.OnCloseTimeout)
Expand Down
22 changes: 22 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var (

mysqlDefaultWorkloadName = "OLTP"
mysqlDefaultWorkload int32
mysqlDrainOnTerm bool

mysqlServerFlushDelay = 100 * time.Millisecond
)
Expand Down Expand Up @@ -102,6 +103,7 @@ func registerPluginFlags(fs *pflag.FlagSet) {
fs.DurationVar(&mysqlKeepAlivePeriod, "mysql-server-keepalive-period", mysqlKeepAlivePeriod, "TCP period between keep-alives")
fs.DurationVar(&mysqlServerFlushDelay, "mysql_server_flush_delay", mysqlServerFlushDelay, "Delay after which buffered response will be flushed to the client.")
fs.StringVar(&mysqlDefaultWorkloadName, "mysql_default_workload", mysqlDefaultWorkloadName, "Default session workload (OLTP, OLAP, DBA)")
fs.BoolVar(&mysqlDrainOnTerm, "mysql_server_drain_onterm", mysqlDrainOnTerm, "If set, the server waits for --onterm_timeout for connected clients to drain")
}

// vtgateHandler implements the Listener interface.
Expand Down Expand Up @@ -633,6 +635,26 @@ func (srv *mysqlServer) shutdownMysqlProtocolAndDrain() {
signal.Stop(srv.sigChan)
}

if mysqlDrainOnTerm {
// We wait for connected clients to drain, instead of just
// active (in transaction) clients
if srv.vtgateHandle == nil {
// server never started properly?
return
}

log.Infof("Starting drain loop, waiting for all clients to disconnect")
reported := time.Now()
for srv.vtgateHandle.numConnections() > 0 {
if time.Since(reported) > 5*time.Second {
log.Infof("Still waiting for client connections to drain (%d connected)...", srv.vtgateHandle.numConnections())
reported = time.Now()
}
time.Sleep(1000 * time.Millisecond)
}
return
}
Comment on lines +646 to +656
Copy link
Member

Choose a reason for hiding this comment

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

With Application side connection pooling this will most likely not change and VTGate can remain in the same state before being shut down.


if busy := srv.vtgateHandle.busyConnections.Load(); busy > 0 {
log.Infof("Waiting for all client connections to be idle (%d active)...", busy)
start := time.Now()
Expand Down
Loading