Skip to content

Commit

Permalink
tikv: remove the update leader backoff (#17541) (#19764)
Browse files Browse the repository at this point in the history
* cherry pick #17541 to release-3.0

Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
ti-srebot authored Sep 21, 2020
1 parent 65f1801 commit 7f2b135
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
43 changes: 17 additions & 26 deletions store/tikv/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,22 @@ const (
)

var (
tikvBackoffCounterRPC = metrics.TiKVBackoffCounter.WithLabelValues("tikvRPC")
tikvBackoffCounterLock = metrics.TiKVBackoffCounter.WithLabelValues("txnLock")
tikvBackoffCounterLockFast = metrics.TiKVBackoffCounter.WithLabelValues("tikvLockFast")
tikvBackoffCounterPD = metrics.TiKVBackoffCounter.WithLabelValues("pdRPC")
tikvBackoffCounterRegionMiss = metrics.TiKVBackoffCounter.WithLabelValues("regionMiss")
tikvBackoffCounterUpdateLeader = metrics.TiKVBackoffCounter.WithLabelValues("updateLeader")
tikvBackoffCounterServerBusy = metrics.TiKVBackoffCounter.WithLabelValues("serverBusy")
tikvBackoffCounterStaleCmd = metrics.TiKVBackoffCounter.WithLabelValues("staleCommand")
tikvBackoffCounterEmpty = metrics.TiKVBackoffCounter.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")
tikvBackoffHistogramUpdateLeader = metrics.TiKVBackoffHistogram.WithLabelValues("updateLeader")
tikvBackoffHistogramServerBusy = metrics.TiKVBackoffHistogram.WithLabelValues("serverBusy")
tikvBackoffHistogramStaleCmd = metrics.TiKVBackoffHistogram.WithLabelValues("staleCommand")
tikvBackoffHistogramEmpty = metrics.TiKVBackoffHistogram.WithLabelValues("")
tikvBackoffCounterRPC = metrics.TiKVBackoffCounter.WithLabelValues("tikvRPC")
tikvBackoffCounterLock = metrics.TiKVBackoffCounter.WithLabelValues("txnLock")
tikvBackoffCounterLockFast = metrics.TiKVBackoffCounter.WithLabelValues("tikvLockFast")
tikvBackoffCounterPD = metrics.TiKVBackoffCounter.WithLabelValues("pdRPC")
tikvBackoffCounterRegionMiss = metrics.TiKVBackoffCounter.WithLabelValues("regionMiss")
tikvBackoffCounterServerBusy = metrics.TiKVBackoffCounter.WithLabelValues("serverBusy")
tikvBackoffCounterStaleCmd = metrics.TiKVBackoffCounter.WithLabelValues("staleCommand")
tikvBackoffCounterEmpty = metrics.TiKVBackoffCounter.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.Counter, prometheus.Observer) {
Expand All @@ -78,8 +76,6 @@ func (t backoffType) metric() (prometheus.Counter, prometheus.Observer) {
return tikvBackoffCounterPD, tikvBackoffHistogramPD
case BoRegionMiss:
return tikvBackoffCounterRegionMiss, tikvBackoffHistogramRegionMiss
case BoUpdateLeader:
return tikvBackoffCounterUpdateLeader, tikvBackoffHistogramUpdateLeader
case boServerBusy:
return tikvBackoffCounterServerBusy, tikvBackoffHistogramServerBusy
case boStaleCmd:
Expand Down Expand Up @@ -145,7 +141,6 @@ const (
boTxnLockFast
BoPDRPC
BoRegionMiss
BoUpdateLeader
boServerBusy
boStaleCmd
)
Expand All @@ -166,8 +161,6 @@ func (t backoffType) createFn(vars *kv.Variables) func(context.Context, int) int
case BoRegionMiss:
// change base time to 2ms, because it may recover soon.
return NewBackoffFn(2, 500, NoJitter)
case BoUpdateLeader:
return NewBackoffFn(1, 10, NoJitter)
case boServerBusy:
return NewBackoffFn(2000, 10000, EqualJitter)
case boStaleCmd:
Expand All @@ -188,8 +181,6 @@ func (t backoffType) String() string {
return "pdRPC"
case BoRegionMiss:
return "regionMiss"
case BoUpdateLeader:
return "updateLeader"
case boServerBusy:
return "serverBusy"
case boStaleCmd:
Expand All @@ -206,7 +197,7 @@ func (t backoffType) TError() error {
return ErrResolveLockTimeout
case BoPDRPC:
return ErrPDServerTimeout
case BoRegionMiss, BoUpdateLeader:
case BoRegionMiss:
return ErrRegionUnavailable
case boServerBusy:
return ErrTiKVServerBusy
Expand Down
16 changes: 7 additions & 9 deletions store/tikv/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,19 @@ func (s *RegionRequestSender) onRegionError(bo *Backoffer, ctx *RPCContext, regi
logutil.Logger(context.Background()).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
} else {
if notLeader.GetLeader() == nil {
// The peer doesn't know who is the current leader. Generally it's because
// the Raft group is in an election, but it's possible that the peer is
// isolated and removed from the Raft group. So it's necessary to reload
// the region from PD.
s.regionCache.InvalidateCachedRegion(ctx.Region)
boType = BoRegionMiss
}
if err = bo.Backoff(boType, errors.Errorf("not leader: %v, ctx: %v", notLeader, ctx)); err != nil {
return false, errors.Trace(err)
if err = bo.Backoff(BoRegionMiss, errors.Errorf("not leader: %v, ctx: %v", notLeader, ctx)); err != nil {
return false, errors.Trace(err)
}
} else {
// don't backoff if a new leader is returned.
s.regionCache.UpdateLeader(ctx.Region, notLeader.GetLeader().GetStoreId(), ctx.PeerIdx)
}

return true, nil
Expand Down

0 comments on commit 7f2b135

Please sign in to comment.