Skip to content

Commit

Permalink
region_request: tiny refactor - init function failpointSendReqResult (#…
Browse files Browse the repository at this point in the history
…1523)

 

Signed-off-by: AndreMouche <[email protected]>
  • Loading branch information
AndreMouche authored Jan 2, 2025
1 parent 743aec1 commit f2025c1
Showing 1 changed file with 59 additions and 37 deletions.
96 changes: 59 additions & 37 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,43 +752,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 @@ -1907,3 +1872,60 @@ 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,
) {
if val, e := util.EvalFailpoint("tikvStoreSendReqResult"); e == nil {
failpointCfg, ok := val.(string)
if !ok {
return
}
switch failpointCfg {
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
}

0 comments on commit f2025c1

Please sign in to comment.