Skip to content

Commit

Permalink
region_request: remove backoff for stale read (#1423) (#1430)
Browse files Browse the repository at this point in the history
* region_request: remove backoff for stale read (#1423)

* remove stale read backoff

Signed-off-by: you06 <[email protected]>

* sort imports

Signed-off-by: you06 <[email protected]>

---------

Signed-off-by: you06 <[email protected]>

* add comment

Signed-off-by: you06 <[email protected]>

---------

Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 authored Aug 21, 2024
1 parent 02a6a91 commit 48c3e31
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
8 changes: 1 addition & 7 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -1843,13 +1843,7 @@ func (s *RegionRequestSender) onRegionError(bo *retry.Backoffer, ctx *RPCContext
zap.Uint64("safe-ts", regionErr.GetDataIsNotReady().GetSafeTs()),
zap.Stringer("ctx", ctx),
)
if !req.IsGlobalStaleRead() {
// only backoff local stale reads as global should retry immediately against the leader as a normal read
err = bo.Backoff(retry.BoMaxDataNotReady, errors.New("data is not ready"))
if err != nil {
return false, err
}
}
// do not backoff data-is-not-ready as we always retry with normal snapshot read.
return true, nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/retry/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestBackoffErrorType(t *testing.T) {
assert.Nil(t, err)
// 6ms sleep at most in total
for i := 0; i < 2; i++ {
err = b.Backoff(BoMaxDataNotReady, errors.New("data not ready"))
err = b.Backoff(BoMaxRegionNotInitialized, errors.New("region not initialized"))
assert.Nil(t, err)
}
// 100ms sleep at most in total
Expand All @@ -84,14 +84,14 @@ func TestBackoffDeepCopy(t *testing.T) {
b := NewBackofferWithVars(context.TODO(), 4, nil)
// 700 ms sleep in total and the backoffer will return an error next time.
for i := 0; i < 3; i++ {
err = b.Backoff(BoMaxDataNotReady, errors.New("data not ready"))
err = b.Backoff(BoMaxRegionNotInitialized, errors.New("region not initialized"))
assert.Nil(t, err)
}
bForked, cancel := b.Fork()
defer cancel()
bCloned := b.Clone()
for _, b := range []*Backoffer{bForked, bCloned} {
err = b.Backoff(BoTiKVRPC, errors.New("tikv rpc"))
assert.ErrorIs(t, err, BoMaxDataNotReady.err)
assert.ErrorIs(t, err, BoMaxRegionNotInitialized.err)
}
}
1 change: 0 additions & 1 deletion internal/retry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ var (
BoTxnNotFound = NewConfig("txnNotFound", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrResolveLockTimeout)
BoStaleCmd = NewConfig("staleCommand", &metrics.BackoffHistogramStaleCmd, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrTiKVStaleCommand)
BoMaxTsNotSynced = NewConfig("maxTsNotSynced", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrTiKVMaxTimestampNotSynced)
BoMaxDataNotReady = NewConfig("dataNotReady", &metrics.BackoffHistogramDataNotReady, NewBackoffFnCfg(2, 2000, NoJitter), tikverr.ErrRegionDataNotReady)
BoMaxRegionNotInitialized = NewConfig("regionNotInitialized", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrRegionNotInitialized)
// TxnLockFast's `base` load from vars.BackoffLockFast when create BackoffFn.
BoTxnLockFast = NewConfig(txnLockFastName, &metrics.BackoffHistogramLockFast, NewBackoffFnCfg(2, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
Expand Down

0 comments on commit 48c3e31

Please sign in to comment.