Skip to content
Merged
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
32 changes: 20 additions & 12 deletions go/vt/vttablet/tabletserver/tabletserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,19 +557,27 @@ func (tsv *TabletServer) setTimeBomb() chan struct{} {
return done
}

// IsHealthy returns nil if the query service is healthy (able to
// connect to the database and serving traffic) or an error explaining
// IsHealthy returns nil for non-serving types or if the query service is healthy (able to
// connect to the database and serving traffic), or an error explaining
// the unhealthiness otherwise.
func (tsv *TabletServer) IsHealthy() error {
_, err := tsv.Execute(
tabletenv.LocalContext(),
nil,
"select 1 from dual",
nil,
0,
nil,
)
return err
tsv.mu.Lock()
tabletType := tsv.target.TabletType
tsv.mu.Unlock()
switch tabletType {
case topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_BATCH, topodatapb.TabletType_EXPERIMENTAL:
_, err := tsv.Execute(
tabletenv.LocalContext(),
nil,
"/* health */ select 1 from dual",
nil,
0,
nil,
)
return err
default:
return nil
}
}

// CheckMySQL initiates a check to see if MySQL is reachable.
Expand Down Expand Up @@ -1738,7 +1746,7 @@ func (tsv *TabletServer) registerDebugHealthHandler() {
}
w.Header().Set("Content-Type", "text/plain")
if err := tsv.IsHealthy(); err != nil {
w.Write([]byte("not ok"))
http.Error(w, fmt.Sprintf("not ok: %v", err), http.StatusInternalServerError)
return
}
w.Write([]byte("ok"))
Expand Down