diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index 48c993bdc58b0..ceecdc5a5884d 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -44,15 +44,14 @@ const ( ) var ( - tikvBackoffHistogramRPC = metrics.TiKVBackoffHistogram.WithLabelValues("tikvRPC") - tikvBackoffHistogramLock = metrics.TiKVBackoffHistogram.WithLabelValues("txnLock") - tikvBackoffHistogramLockFast = metrics.TiKVBackoffHistogram.WithLabelValues("tikvLockFast") - tikvBackoffHistogramPD = metrics.TiKVBackoffHistogram.WithLabelValues("pdRPC") - tikvBackoffHistogramRegionMiss = metrics.TiKVBackoffHistogram.WithLabelValues("regionMiss") - tikvBackoffHistogramUpdateLeader = metrics.TiKVBackoffHistogram.WithLabelValues("updateLeader") - tikvBackoffHistogramServerBusy = metrics.TiKVBackoffHistogram.WithLabelValues("serverBusy") - tikvBackoffHistogramStaleCmd = metrics.TiKVBackoffHistogram.WithLabelValues("staleCommand") - tikvBackoffHistogramEmpty = metrics.TiKVBackoffHistogram.WithLabelValues("") + tikvBackoffHistogramRPC = metrics.TiKVBackoffHistogram.WithLabelValues("tikvRPC") + tikvBackoffHistogramLock = metrics.TiKVBackoffHistogram.WithLabelValues("txnLock") + tikvBackoffHistogramLockFast = metrics.TiKVBackoffHistogram.WithLabelValues("tikvLockFast") + tikvBackoffHistogramPD = metrics.TiKVBackoffHistogram.WithLabelValues("pdRPC") + tikvBackoffHistogramRegionMiss = metrics.TiKVBackoffHistogram.WithLabelValues("regionMiss") + tikvBackoffHistogramServerBusy = metrics.TiKVBackoffHistogram.WithLabelValues("serverBusy") + tikvBackoffHistogramStaleCmd = metrics.TiKVBackoffHistogram.WithLabelValues("staleCommand") + tikvBackoffHistogramEmpty = metrics.TiKVBackoffHistogram.WithLabelValues("") ) func (t backoffType) metric() prometheus.Observer { @@ -67,8 +66,6 @@ func (t backoffType) metric() prometheus.Observer { return tikvBackoffHistogramPD case BoRegionMiss: return tikvBackoffHistogramRegionMiss - case BoUpdateLeader: - return tikvBackoffHistogramUpdateLeader case boServerBusy: return tikvBackoffHistogramServerBusy case boStaleCmd: @@ -134,7 +131,6 @@ const ( boTxnLockFast BoPDRPC BoRegionMiss - BoUpdateLeader boServerBusy boTxnNotFound boStaleCmd @@ -158,8 +154,6 @@ func (t backoffType) createFn(vars *kv.Variables) func(context.Context, int) int return NewBackoffFn(2, 500, NoJitter) case boTxnNotFound: return NewBackoffFn(2, 500, NoJitter) - case BoUpdateLeader: - return NewBackoffFn(1, 10, NoJitter) case boServerBusy: return NewBackoffFn(2000, 10000, EqualJitter) case boStaleCmd: @@ -180,8 +174,6 @@ func (t backoffType) String() string { return "pdRPC" case BoRegionMiss: return "regionMiss" - case BoUpdateLeader: - return "updateLeader" case boServerBusy: return "serverBusy" case boStaleCmd: @@ -200,7 +192,7 @@ func (t backoffType) TError() error { return ErrResolveLockTimeout case BoPDRPC: return ErrPDServerTimeout - case BoRegionMiss, BoUpdateLeader: + case BoRegionMiss: return ErrRegionUnavailable case boServerBusy: return ErrTiKVServerBusy diff --git a/store/tikv/region_request.go b/store/tikv/region_request.go index 7c60908c0e9ee..89ea74a582bd1 100644 --- a/store/tikv/region_request.go +++ b/store/tikv/region_request.go @@ -351,17 +351,14 @@ func (s *RegionRequestSender) onRegionError(bo *Backoffer, ctx *RPCContext, seed logutil.BgLogger().Debug("tikv reports `NotLeader` retry later", zap.String("notLeader", notLeader.String()), zap.String("ctx", ctx.String())) - s.regionCache.UpdateLeader(ctx.Region, notLeader.GetLeader().GetStoreId(), ctx.PeerIdx) - var boType backoffType - if notLeader.GetLeader() != nil { - boType = BoUpdateLeader + if notLeader.GetLeader() == nil { + if err = bo.Backoff(BoRegionMiss, errors.Errorf("not leader: %v, ctx: %v", notLeader, ctx)); err != nil { + return false, errors.Trace(err) + } } else { - boType = BoRegionMiss - } - - if err = bo.Backoff(boType, errors.Errorf("not leader: %v, ctx: %v", notLeader, ctx)); err != nil { - return false, errors.Trace(err) + // don't backoff if a new leader is returned. + s.regionCache.UpdateLeader(ctx.Region, notLeader.GetLeader().GetStoreId(), ctx.PeerIdx) } return true, nil