Skip to content

Commit

Permalink
Add terminating state
Browse files Browse the repository at this point in the history
Signed-off-by: David Piegza <[email protected]>
  • Loading branch information
davidpiegza committed Sep 13, 2023
1 parent 9f9b77f commit 97da4a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ 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 {
ctx := context.Background()

if terminating {
return vterrors.New(vtrpcpb.Code_ABORTED, "Terminating vtgate")
}

var cancel context.CancelFunc
if *mysqlQueryTimeout != 0 {
ctx, cancel = context.WithTimeout(ctx, *mysqlQueryTimeout)
Expand Down
8 changes: 8 additions & 0 deletions go/vt/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var (
// healthCheckTimeout is the timeout on the RPC call to tablets
healthCheckTimeout = time.Minute

terminating bool

// System settings related flags
sysVarSetEnabled = true
setVarEnabled = true
Expand Down Expand Up @@ -328,6 +330,8 @@ func Init(
}
})
servenv.OnTerm(func() {
terminating = true

if st != nil && enableSchemaChangeSignal {
st.Stop()
}
Expand Down Expand Up @@ -405,6 +409,10 @@ func (vtg *VTGate) registerDebugHealthHandler() {
// IsHealthy returns nil if server is healthy.
// Otherwise, it returns an error indicating the reason.
func (vtg *VTGate) IsHealthy() error {
if terminating {
return errors.New("Terminating")
}

return nil
}

Expand Down

0 comments on commit 97da4a3

Please sign in to comment.