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

client: support configuring backoff #8679

Merged
merged 8 commits into from
Dec 2, 2024

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Oct 9, 2024

What problem does this PR solve?

Issue Number: Close #8047

What is changed and how does it work?

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 9, 2024
@rleungx rleungx force-pushed the introduce-backoffer branch from 17e8dd3 to 34b0620 Compare October 9, 2024 07:55
@rleungx rleungx requested a review from JmPotato October 9, 2024 08:16
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 83.72093% with 7 lines in your changes missing coverage. Please review.

Project coverage is 76.16%. Comparing base (a86f3dd) to head (6e6ecb3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8679      +/-   ##
==========================================
- Coverage   76.17%   76.16%   -0.01%     
==========================================
  Files         458      458              
  Lines       70167    70208      +41     
==========================================
+ Hits        53447    53474      +27     
- Misses      13365    13385      +20     
+ Partials     3355     3349       -6     
Flag Coverage Δ
unittests 76.16% <83.72%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

ti-chi-bot bot commented Oct 18, 2024

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 18, 2024
@@ -109,6 +109,57 @@ func (bo *Backoffer) Exec(
return err
}

// ExecWithResult is a helper function to exec backoff with result.
func (bo *Backoffer) ExecWithResult(
Copy link
Member

Choose a reason for hiding this comment

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

we can wrap exec to this
image

And export Exec and ExecWithResult separately

client/client.go Outdated
}
return handleRegionResponse(resp), nil
}
if c.option.bo == nil {
Copy link
Member

Choose a reason for hiding this comment

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

How about using client interceptor to do backoff? We can delivery backoff option by context?

return &pdpb.GetMinTSResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, err.Error()),
}, nil
return nil, status.Error(codes.ResourceExhausted, err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can split these updates to another pr, and merge it firstly. It is simple

Signed-off-by: Ryan Leung <[email protected]>
@rleungx rleungx force-pushed the introduce-backoffer branch from 41384b9 to 741f0e8 Compare November 27, 2024 04:21
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 27, 2024
Signed-off-by: Ryan Leung <[email protected]>
@rleungx rleungx removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 27, 2024
@rleungx rleungx requested a review from okJiang November 27, 2024 05:04
Signed-off-by: Ryan Leung <[email protected]>
@rleungx
Copy link
Member Author

rleungx commented Nov 28, 2024

/retest

@@ -41,6 +42,53 @@ const (
FollowerHandleMetadataKey = "pd-allow-follower-handle"
)

// Add retry related CallOption
type retryCallOption struct {
grpc.EmptyCallOption
Copy link
Contributor

Choose a reason for hiding this comment

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

why need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise, we need to implement before and after interfaces.

// Record the start time
start := time.Now()

ctx = retry.WithBackoffer(ctx, bo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the user need to specify it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we also can provide a default one if needed.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Nov 29, 2024
type boCtxKey struct{}

// Key used to store backoffer
var backofferKey = boCtxKey{}
Copy link
Member

Choose a reason for hiding this comment

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

Why using struct{}, not string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to use struct{}

Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
@rleungx rleungx requested a review from okJiang November 29, 2024 09:44
// Calculate the elapsed time
elapsed := time.Since(start)
// Verify that some backoff occurred by checking if the elapsed time is greater than the base backoff
re.Greater(elapsed, base, "Expected some backoff to have occurred")
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to compare total?

Signed-off-by: Ryan Leung <[email protected]>
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 2, 2024
Copy link
Contributor

ti-chi-bot bot commented Dec 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nolouch, okJiang

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

ti-chi-bot bot commented Dec 2, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-29 08:44:29.044208854 +0000 UTC m=+798856.663863394: ☑️ agreed by nolouch.
  • 2024-12-02 06:32:06.649962598 +0000 UTC m=+1050114.269617114: ☑️ agreed by okJiang.

@rleungx
Copy link
Member Author

rleungx commented Dec 2, 2024

/retest

@ti-chi-bot ti-chi-bot bot merged commit 29dfaf9 into tikv:master Dec 2, 2024
25 checks passed
@rleungx rleungx deleted the introduce-backoffer branch December 2, 2024 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce the backoff mechanism for gRPC client
3 participants