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

region_request: tiny refactor - init function failpointSendReqResult #1523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
98 changes: 61 additions & 37 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,43 +730,8 @@ func (s *RegionRequestSender) SendReqCtx(
bo.SetCtx(opentracing.ContextWithSpan(bo.GetCtx(), span1))
}

if val, err := util.EvalFailpoint("tikvStoreSendReqResult"); err == nil {
if s, ok := val.(string); ok {
switch s {
case "timeout":
return nil, nil, 0, errors.New("timeout")
case "GCNotLeader":
if req.Type == tikvrpc.CmdGC {
return &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{NotLeader: &errorpb.NotLeader{}}},
}, nil, 0, nil
}
case "PessimisticLockNotLeader":
if req.Type == tikvrpc.CmdPessimisticLock {
return &tikvrpc.Response{
Resp: &kvrpcpb.PessimisticLockResponse{RegionError: &errorpb.Error{NotLeader: &errorpb.NotLeader{}}},
}, nil, 0, nil
}
case "GCServerIsBusy":
if req.Type == tikvrpc.CmdGC {
return &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}},
}, nil, 0, nil
}
case "busy":
return &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}},
}, nil, 0, nil
case "requestTiDBStoreError":
if et == tikvrpc.TiDB {
return nil, nil, 0, errors.WithStack(tikverr.ErrTiKVServerTimeout)
}
case "requestTiFlashError":
if et == tikvrpc.TiFlash {
return nil, nil, 0, errors.WithStack(tikverr.ErrTiFlashServerTimeout)
}
}
}
if resp, err = failpointSendReqResult(req, et); err != nil || resp != nil {
return
}

if err = s.validateReadTS(bo.GetCtx(), req); err != nil {
Expand Down Expand Up @@ -1929,3 +1894,62 @@ func (s *baseReplicaSelector) backoffOnNoCandidate(bo *retry.Backoffer) error {
}
return bo.Backoff(args.cfg, args.err)
}

// failpointSendReqResult is used to process the failpoint For tikvStoreSendReqResult.
func failpointSendReqResult(req *tikvrpc.Request, et tikvrpc.EndpointType) (
resp *tikvrpc.Response,
err error,
) {
val, e := util.EvalFailpoint("tikvStoreSendReqResult")
if e != nil {
return
}
errMsg, ok := val.(string)
if !ok {
return
}
Comment on lines +1903 to +1910
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to just follow the original pattern if val, err := util.EvalFailpoint("tikvStoreSendReqResult"); err == nil { ..., instead of reformatting it. It's actually the expanded version of the failpoint.Inject pattern.

switch errMsg {
case "timeout":
{
err = errors.New("timeout")
return
}
case "GCNotLeader":
if req.Type == tikvrpc.CmdGC {
resp = &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{NotLeader: &errorpb.NotLeader{}}},
}
return
}
case "PessimisticLockNotLeader":
if req.Type == tikvrpc.CmdPessimisticLock {
resp = &tikvrpc.Response{
Resp: &kvrpcpb.PessimisticLockResponse{RegionError: &errorpb.Error{NotLeader: &errorpb.NotLeader{}}},
}
return
}
case "GCServerIsBusy":
if req.Type == tikvrpc.CmdGC {
resp = &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}},
}
return
}
case "busy":
resp = &tikvrpc.Response{
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}},
}
return
case "requestTiDBStoreError":
if et == tikvrpc.TiDB {
err = errors.WithStack(tikverr.ErrTiKVServerTimeout)
return
}
case "requestTiFlashError":
if et == tikvrpc.TiFlash {
err = errors.WithStack(tikverr.ErrTiFlashServerTimeout)
return
}
}
return
}
Loading