From e46211abe87d9f71a6db15ab2428b160595b1000 Mon Sep 17 00:00:00 2001 From: you06 Date: Wed, 21 Aug 2024 12:45:52 +0900 Subject: [PATCH] region_request: remove backoff for stale read (#1423) (#1429) * region_request: remove backoff for stale read (#1423) * remove stale read backoff Signed-off-by: you06 * sort imports Signed-off-by: you06 --------- Signed-off-by: you06 * add comment Signed-off-by: you06 --------- Signed-off-by: you06 --- internal/locate/region_request.go | 8 +------- internal/retry/backoff_test.go | 6 +++--- internal/retry/config.go | 1 - 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index ebbf17997..f5dfc5030 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -2142,13 +2142,7 @@ func (s *RegionRequestSender) onRegionError( 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 } diff --git a/internal/retry/backoff_test.go b/internal/retry/backoff_test.go index 468306fbb..4b71ed558 100644 --- a/internal/retry/backoff_test.go +++ b/internal/retry/backoff_test.go @@ -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 @@ -87,7 +87,7 @@ 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() @@ -95,6 +95,6 @@ func TestBackoffDeepCopy(t *testing.T) { 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) } } diff --git a/internal/retry/config.go b/internal/retry/config.go index 9c062cc75..011a1f3d6 100644 --- a/internal/retry/config.go +++ b/internal/retry/config.go @@ -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) BoIsWitness = NewConfig("isWitness", &metrics.BackoffHistogramIsWitness, NewBackoffFnCfg(1000, 10000, EqualJitter), tikverr.ErrIsWitness) // TxnLockFast's `base` load from vars.BackoffLockFast when create BackoffFn.