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

tikv: remove the update leader backoff when known real leader (#17541) #17681

Merged
merged 2 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions store/tikv/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -134,7 +131,6 @@ const (
boTxnLockFast
BoPDRPC
BoRegionMiss
BoUpdateLeader
boServerBusy
boTxnNotFound
boStaleCmd
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions store/tikv/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down