Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

pd: Add pd request retry logic #1088

Merged
merged 24 commits into from
May 10, 2021
Merged

pd: Add pd request retry logic #1088

merged 24 commits into from
May 10, 2021

Conversation

ZipFast
Copy link
Contributor

@ZipFast ZipFast commented May 7, 2021

What problem does this PR solve?

When client send a request to pd failed due to some recoverable server faults or network issues, it is better to retry than to return error.

What is changed and how it works?

Add pd request retry logic on pdRequest function in pkg/pdutil/pd.go file.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Release Note

  • No Release Note

pkg/pdutil/pd.go Outdated
time.Sleep(time.Duration(i) * time.Second)
continue
}
defer resp.Body.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove defer 🤔️

pkg/pdutil/pd.go Outdated
resp, reqErr = cli.Do(req)
if err != nil {
log.Warn("pd request fail, retry", zap.Int("retry time", i), zap.Error(reqErr))
time.Sleep(time.Duration(i) * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think just sleep 1 second is better. then if there is something wrong with PD. we can wait at most 10 seconds.

@ZipFast ZipFast marked this pull request as ready for review May 8, 2021 02:20
pkg/pdutil/pd.go Outdated Show resolved Hide resolved
pkg/pdutil/pd.go Outdated
if resp.StatusCode != http.StatusOK {
if resp.StatusCode >= 500 {
log.Warn("pd request fail, retry", zap.Int("retry time", i), zap.String("State", resp.Status))
time.Sleep(time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems after the retry, the old response won't be closed? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@CLAassistant
Copy link

CLAassistant commented May 10, 2021

CLA assistant check
All committers have signed the CLA.

pkg/pdutil/pd.go Outdated Show resolved Hide resolved
@ZipFast
Copy link
Contributor Author

ZipFast commented May 10, 2021

/run-integration-tests

@3pointer
Copy link
Collaborator

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 LGTM1 label May 10, 2021
@glorv
Copy link
Collaborator

glorv commented May 10, 2021

/lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • 3pointer
  • glorv

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 LGTM2 and removed status/LGT1 LGTM1 labels May 10, 2021
@glorv
Copy link
Collaborator

glorv commented May 10, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: dc897dc

@ti-chi-bot ti-chi-bot merged commit 7c98ff0 into pingcap:master May 10, 2021
ti-chi-bot pushed a commit to ti-chi-bot/br that referenced this pull request May 10, 2021
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #1092.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request could not be created: failed to create pull request against pingcap/br#release-4.0 from head ti-chi-bot:cherry-pick-1088-to-release-4.0: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-1088-to-release-4.0."}],"documentation_url":"https://docs.github.com/rest/reference/pulls#create-a-pull-request"}

ti-chi-bot pushed a commit to ti-chi-bot/br that referenced this pull request May 10, 2021
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #1093.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request could not be created: failed to create pull request against pingcap/br#release-5.0 from head ti-chi-bot:cherry-pick-1088-to-release-5.0: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-1088-to-release-5.0."}],"documentation_url":"https://docs.github.com/rest/reference/pulls#create-a-pull-request"}

ti-chi-bot pushed a commit that referenced this pull request May 12, 2021
3pointer pushed a commit to 3pointer/br that referenced this pull request Jun 4, 2021
3pointer pushed a commit to 3pointer/br that referenced this pull request Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants