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

tikvclient: reduce wait backoff time when lock has be expired #10006

Merged
merged 4 commits into from
May 17, 2019
Merged

tikvclient: reduce wait backoff time when lock has be expired #10006

merged 4 commits into from
May 17, 2019

Conversation

lysu
Copy link
Contributor

@lysu lysu commented Apr 2, 2019

What problem does this PR solve?

we can precal lock expired time from kv response, then:

  • we still backoff retry start with small init interval, because we don't know when other tx finish and cleanup lock
  • but backoff should not over TTL, e.g. lock will be expired in 3s, we should never backoff over then 3s.

this PR maybe work better if tikv's tikv/tikv#4589 be merged(that decrease TTL)

What is changed and how it works?

calculate wait time by UntilExpired and force sleep not more than that.

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • N/A

Side effects

  • Increased code complexity

Related changes

  • N/A

This change is Reviewable

@lysu lysu changed the title tikvclient: more accurate backoff for resolve lock tikvclient: more accurate backoff time to resolve lock Apr 2, 2019
@lysu
Copy link
Contributor Author

lysu commented Apr 2, 2019

/run-all-tests

@lysu
Copy link
Contributor Author

lysu commented Apr 2, 2019

@tiancaiamao PTAL can we do this? thx

@tiancaiamao
Copy link
Contributor

I like this idea @lysu

@tiancaiamao
Copy link
Contributor

You may remove the WIP label if it's ready for review

@codecov
Copy link

codecov bot commented May 13, 2019

Codecov Report

Merging #10006 into master will increase coverage by 0.0166%.
The diff coverage is 77.2727%.

@@               Coverage Diff                @@
##             master     #10006        +/-   ##
================================================
+ Coverage   77.2589%   77.2756%   +0.0166%     
================================================
  Files           413        413                
  Lines         86931      86964        +33     
================================================
+ Hits          67162      67202        +40     
+ Misses        14602      14599         -3     
+ Partials       5167       5163         -4

@lysu lysu marked this pull request as ready for review May 13, 2019 06:50
@lysu
Copy link
Contributor Author

lysu commented May 13, 2019

/run-all-tests

@lysu lysu changed the title tikvclient: more accurate backoff time to resolve lock tikvclient: reduce wait backoff time when lock has be expired May 13, 2019
@lysu lysu removed the status/WIP label May 13, 2019
@lysu
Copy link
Contributor Author

lysu commented May 13, 2019

/rebuild

@lysu
Copy link
Contributor Author

lysu commented May 13, 2019

/run-all-tests

@@ -265,47 +266,59 @@ func (lr *LockResolver) BatchResolveLocks(bo *Backoffer, locks []*Lock, loc Regi
// commit status.
// 3) Send `ResolveLock` cmd to the lock's region to resolve all locks belong to
// the same transaction.
func (lr *LockResolver) ResolveLocks(bo *Backoffer, locks []*Lock) (ok bool, err error) {
func (lr *LockResolver) ResolveLocks(bo *Backoffer, locks []*Lock) (msBeforeTxnExpired int64, 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.

msBeforeTxnExpired stands for "milliseconds before transaction expired"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems yes.

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label May 13, 2019
@tiancaiamao
Copy link
Contributor

PTAL @disksing @zhangjinpeng1987

@@ -102,8 +102,13 @@ func NewBackoffFn(base, cap, jitter int) func(ctx context.Context) int {
logutil.Logger(context.Background()).Debug("backoff",
zap.Int("base", base),
zap.Int("sleep", sleep))

realSleep := sleep
if maxSleepMs >= 0 && realSleep > maxSleepMs {
Copy link
Contributor

Choose a reason for hiding this comment

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

When the maxSleepMs will be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maxSleepMs never should be 0 in current usage, but backoff is a common function and we add new maxSleepMs Param, so we should take care about it and in logic "force sleep zero" is useful.

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@jackysp jackysp added the status/LGT2 Indicates that a PR has LGTM 2. label May 15, 2019
@jackysp jackysp removed the status/LGT1 Indicates that a PR has LGTM 1. label May 15, 2019
Copy link
Contributor

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhangjinpeng87
Copy link
Contributor

/run-all-tests

@lysu
Copy link
Contributor Author

lysu commented May 16, 2019

/run-unit-test

@lysu
Copy link
Contributor Author

lysu commented May 17, 2019

/run-all-tests

@lysu lysu merged commit 0130831 into pingcap:master May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tikv status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants