Skip to content

Commit

Permalink
Add shutdown state in MySQL server plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpiegza committed Sep 25, 2023
1 parent 6b8851d commit 76a647c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type vtgateHandler struct {

vtg *VTGate
connections map[*mysql.Conn]bool

shutdown atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (ers_prs_newfeatures_heavy)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_throttler_custom_config)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_gen4)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (13)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (schemadiff_vrepl) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtorc) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema_tracker)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_tablegc) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_partial_keyspace)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_general_heavy)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_migrate_vdiff2_convert_tz)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_across_db_versions)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vindex_heavy)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vttablet_prscomplex)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (21)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_unsharded)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vstream_failover)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_basic)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_cellalias)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtctlbackup_sharded_clustertest_heavy)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress_suite)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_readafterwrite)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_revert)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_ghost) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_backup)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_singleton) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_suite)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_queries)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Local example using etcd on ubuntu-latest

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtbackup_transform)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Region Sharding example using etcd on ubuntu-latest

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql80)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (18)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_recovery) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (schemadiff_vrepl)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_godriver)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Local example using k8s on ubuntu-latest

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vstream_stoponreshard_false)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (topo_connection_cache)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtorc)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vschema)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Local example using consul on ubuntu-latest

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo_etcd)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_multicell)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_ghost)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (22)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Unit Test (Race)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_revertible)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_declarative) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_declarative)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_concurrentdml)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (15)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_tablet_healthcheck_cache)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo_consul)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_consul)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_throttler)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (12)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_reservedconn)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress_suite) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_revertible) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_v2)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_recovery)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_revert) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_singleton)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql_server_vault)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_backup) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vstream_with_keyspaces_to_watch)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_suite) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_transaction)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / test

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vstream_stoponreshard_true)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / test

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler) mysql57

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_tablegc)

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / test

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

Bool not declared by package atomic (typecheck)

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

undefined: atomic.Bool

Check failure on line 95 in go/vt/vtgate/plugin_mysql_server.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

undefined: atomic.Bool
}

func newVtgateHandler(vtg *VTGate) *vtgateHandler {
Expand Down Expand Up @@ -147,6 +149,14 @@ func (vh *vtgateHandler) ConnectionClosed(c *mysql.Conn) {
_ = vh.vtg.CloseSession(ctx, session)
}

func (vh *vtgateHandler) Shutdown() bool {
return vh.shutdown.CompareAndSwap(false, true)
}

func (vh *vtgateHandler) IsShutdown() bool {
return vh.shutdown.Load()
}

// Regexp to extract parent span id over the sql query
var r = regexp.MustCompile(`/\*VT_SPAN_CONTEXT=(.*)\*/`)

Expand Down Expand Up @@ -182,6 +192,13 @@ func startSpan(ctx context.Context, query, label string) (trace.Span, context.Co
}

func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
session := vh.session(c)
if vh.IsShutdown() {
if !session.InTransaction {
return mysql.NewSQLError(mysql.ERServerShutdown, mysql.SSNetError, "VTGate shutdown in progress")
}
}

ctx := context.Background()
var cancel context.CancelFunc
if *mysqlQueryTimeout != 0 {
Expand Down Expand Up @@ -209,7 +226,6 @@ func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sq
"VTGate MySQL Connector" /* subcomponent: part of the client */)
ctx = callerid.NewContext(ctx, ef, im)

session := vh.session(c)
if !session.InTransaction {
atomic.AddInt32(&busyConnections, 1)
}
Expand Down Expand Up @@ -535,12 +551,14 @@ func newMysqlUnixSocket(address string, authServer mysql.AuthServer, handler mys
}

func shutdownMysqlProtocolAndDrain() {
vtgateHandle.Shutdown()

if mysqlListener != nil {
mysqlListener.Close()
mysqlListener.Shutdown()
mysqlListener = nil
}
if mysqlUnixListener != nil {
mysqlUnixListener.Close()
mysqlUnixListener.Shutdown()
mysqlUnixListener = nil
}
if sigChan != nil {
Expand Down

0 comments on commit 76a647c

Please sign in to comment.