Skip to content

Commit

Permalink
cherry pick tikv#1108 (tikv#1336)
Browse files Browse the repository at this point in the history
Signed-off-by: xufei <[email protected]>
  • Loading branch information
windtalker authored May 10, 2024
1 parent 8e2aa47 commit 19a4b78
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tikvrpc/tikvrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,24 @@ type getRegionError interface {
GetRegionError() *errorpb.Error
}

func isResponseOKToNotImplGetRegionError(resp interface{}) bool {
switch resp.(type) {
case *MPPStreamResponse, *mpp.CancelTaskResponse, *mpp.IsAliveResponse,
*mpp.DispatchTaskResponse, *BatchCopStreamResponse, *tikvpb.BatchCommandsEmptyResponse:
return true
default:
return false
}
}

// GetRegionError returns the RegionError of the underlying concrete response.
func (resp *Response) GetRegionError() (*errorpb.Error, error) {
if resp.Resp == nil {
return nil, nil
}
err, ok := resp.Resp.(getRegionError)
if !ok {
if _, isEmpty := resp.Resp.(*tikvpb.BatchCommandsEmptyResponse); isEmpty {
if isResponseOKToNotImplGetRegionError(resp.Resp) {
return nil, nil
}
return nil, errors.Errorf("invalid response type %v", resp)
Expand Down

0 comments on commit 19a4b78

Please sign in to comment.