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

[store/tikv] avoid too many times of backoff when we retry for batch cop #18999

Merged
merged 6 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion store/tikv/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ func (c *RegionCache) GetTiFlashRPCContext(bo *Backoffer, id RegionVerID) (*RPCC
logutil.BgLogger().Info("invalidate current region, because others failed on same store",
zap.Uint64("region", id.GetID()),
zap.String("store", store.addr))
return nil, nil
// TiFlash will always try to find out a valid peer, avoiding to retry too many times.
continue
}
return &RPCContext{
Region: id,
Expand Down
19 changes: 10 additions & 9 deletions store/tikv/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ func (ss *RegionBatchRequestSender) sendStreamReqToAddr(bo *Backoffer, ctxs []co
if err != nil {
cancel()
ss.rpcError = err
for _, failedCtx := range ctxs {
e := ss.onSendFail(bo, failedCtx.ctx, err)
if e != nil {
return nil, false, func() {}, errors.Trace(e)
}
e := ss.onSendFail(bo, ctxs, err)
if e != nil {
return nil, false, func() {}, errors.Trace(e)
}
return nil, true, func() {}, nil
}
Expand All @@ -127,23 +125,26 @@ func recordRegionRequestRuntimeStats(stats map[tikvrpc.CmdType]*RegionRequestRun
stat.consume += int64(d)
}

func (ss *RegionBatchRequestSender) onSendFail(bo *Backoffer, ctx *RPCContext, err error) error {
func (ss *RegionBatchRequestSender) onSendFail(bo *Backoffer, ctxs []copTaskAndRPCContext, err error) error {
// If it failed because the context is cancelled by ourself, don't retry.
if errors.Cause(err) == context.Canceled || status.Code(errors.Cause(err)) == codes.Canceled {
return errors.Trace(err)
} else if atomic.LoadUint32(&ShuttingDown) > 0 {
return errTiDBShuttingDown
}

if ctx.Meta != nil {
ss.regionCache.OnSendFail(bo, ctx, ss.needReloadRegion(ctx), err)
for _, failedCtx := range ctxs {
ctx := failedCtx.ctx
if ctx.Meta != nil {
ss.regionCache.OnSendFail(bo, ctx, ss.needReloadRegion(ctx), err)
}
}

// Retry on send request failure when it's not canceled.
// When a store is not available, the leader of related region should be elected quickly.
// TODO: the number of retry time should be limited:since region may be unavailable
// when some unrecoverable disaster happened.
err = bo.Backoff(boTiKVRPC, errors.Errorf("send tikv request error: %v, ctx: %v, try next peer later", err, ctx))
err = bo.Backoff(boTiKVRPC, errors.Errorf("send tikv request error: %v, ctxs: %v, try next peer later", err, ctxs))
return errors.Trace(err)
}

Expand Down