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

helper: request another PD if one of them is unavailable #35750

Merged
merged 4 commits into from
Jun 28, 2022
Merged
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions store/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,23 +851,29 @@ func (h *Helper) requestPD(apiName, method, uri string, body io.Reader, res inte
}

func requestPDForOneHost(host, apiName, method, uri string, body io.Reader, res interface{}) error {
logutil.BgLogger().Debug("RequestPD URL", zap.String("url", util.InternalHTTPSchema()+"://"+host+uri))
req, err := http.NewRequest(method, util.InternalHTTPSchema()+"://"+host+uri, body)
urlVar := fmt.Sprintf("%s://%s%s", util.InternalHTTPSchema(), host, uri)
logutil.BgLogger().Debug("RequestPD URL", zap.String("url", urlVar))
req, err := http.NewRequest(method, urlVar, body)
if err != nil {
logutil.BgLogger().Warn("requestPDForOneHost new request",
tangenta marked this conversation as resolved.
Show resolved Hide resolved
zap.String("url", urlVar), zap.Error(err))
return errors.Trace(err)
}
start := time.Now()
resp, err := util.InternalHTTPClient().Do(req)
if err != nil {
metrics.PDAPIRequestCounter.WithLabelValues(apiName, "network error").Inc()
logutil.BgLogger().Warn("requestPDForOneHost do request",
tangenta marked this conversation as resolved.
Show resolved Hide resolved
zap.String("url", urlVar), zap.Error(err))
return errors.Trace(err)
}
metrics.PDAPIExecutionHistogram.WithLabelValues(apiName).Observe(time.Since(start).Seconds())
metrics.PDAPIRequestCounter.WithLabelValues(apiName, resp.Status).Inc()
defer func() {
err = resp.Body.Close()
if err != nil {
logutil.BgLogger().Error("close body failed", zap.Error(err))
logutil.BgLogger().Warn("requestPDForOneHost close body",
tangenta marked this conversation as resolved.
Show resolved Hide resolved
zap.String("url", urlVar), zap.Error(err))
}
}()
err = json.NewDecoder(resp.Body).Decode(res)
Expand Down