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/mocktikv: rpc handler should put error in response instead of return it #4723

Merged
merged 1 commit into from
Oct 9, 2017
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
20 changes: 13 additions & 7 deletions store/tikv/mock-tikv/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,33 @@ import (
"github.com/pingcap/tipb/go-tipb"
)

func (h *rpcHandler) handleCopAnalyzeRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
func (h *rpcHandler) handleCopAnalyzeRequest(req *coprocessor.Request) *coprocessor.Response {
resp := &coprocessor.Response{}
if len(req.Ranges) == 0 {
return resp, nil
return resp
}
if req.GetTp() != kv.ReqTypeAnalyze {
return resp, nil
return resp
}
if err := h.checkRequestContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
return resp
}
analyzeReq := new(tipb.AnalyzeReq)
err := proto.Unmarshal(req.Data, analyzeReq)
if err != nil {
return nil, errors.Trace(err)
resp.OtherError = err.Error()
return resp
}
if analyzeReq.Tp == tipb.AnalyzeType_TypeIndex {
return h.handleAnalyzeIndexReq(req, analyzeReq)
resp, err = h.handleAnalyzeIndexReq(req, analyzeReq)
} else {
resp, err = h.handleAnalyzeColumnsReq(req, analyzeReq)
}
if err != nil {
resp.OtherError = err.Error()
}
return h.handleAnalyzeColumnsReq(req, analyzeReq)
return resp
}

func (h *rpcHandler) handleAnalyzeIndexReq(req *coprocessor.Request, analyzeReq *tipb.AnalyzeReq) (*coprocessor.Response, error) {
Expand Down
24 changes: 14 additions & 10 deletions store/tikv/mock-tikv/cop_handler_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ type dagContext struct {
evalCtx *evalContext
}

func (h *rpcHandler) handleCopDAGRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
func (h *rpcHandler) handleCopDAGRequest(req *coprocessor.Request) *coprocessor.Response {
resp := &coprocessor.Response{}
if len(req.Ranges) == 0 {
return resp, nil
return resp
}
if req.GetTp() != kv.ReqTypeDAG {
return resp, nil
return resp
}
if err := h.checkRequestContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
return resp
}

dagReq := new(tipb.DAGRequest)
err := proto.Unmarshal(req.Data, dagReq)
if err != nil {
return nil, errors.Trace(err)
resp.OtherError = err.Error()
return resp
}
sc := flagsToStatementContext(dagReq.Flags)
timeZone := time.FixedZone("UTC", int(dagReq.TimeZoneOffset))
Expand All @@ -68,7 +69,9 @@ func (h *rpcHandler) handleCopDAGRequest(req *coprocessor.Request) (*coprocessor
}
e, err := h.buildDAG(ctx, dagReq.Executors)
if err != nil {
return nil, errors.Trace(err)
return &coprocessor.Response{
OtherError: err.Error(),
}
}
var (
chunks []tipb.Chunk
Expand All @@ -78,7 +81,7 @@ func (h *rpcHandler) handleCopDAGRequest(req *coprocessor.Request) (*coprocessor
var row [][]byte
row, err = e.Next()
if err != nil {
return nil, errors.Trace(err)
break
}
if row == nil {
break
Expand Down Expand Up @@ -323,7 +326,7 @@ func flagsToStatementContext(flags uint64) *variable.StatementContext {
return sc
}

func buildResp(chunks []tipb.Chunk, err error) (*coprocessor.Response, error) {
func buildResp(chunks []tipb.Chunk, err error) *coprocessor.Response {
resp := &coprocessor.Response{}
selResp := &tipb.SelectResponse{
Error: toPBError(err),
Expand All @@ -343,10 +346,11 @@ func buildResp(chunks []tipb.Chunk, err error) (*coprocessor.Response, error) {
}
data, err := proto.Marshal(selResp)
if err != nil {
return nil, errors.Trace(err)
resp.OtherError = err.Error()
return resp
}
resp.Data = data
return resp, nil
return resp
}

func toPBError(err error) *tipb.Error {
Expand Down
8 changes: 2 additions & 6 deletions store/tikv/mock-tikv/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,10 @@ func (c *RPCClient) SendReq(ctx goctx.Context, addr string, req *tikvrpc.Request
handler.rawStartKey = MvccKey(handler.startKey).Raw()
handler.rawEndKey = MvccKey(handler.endKey).Raw()
var res *coprocessor.Response
var err error
if r.GetTp() == kv.ReqTypeDAG {
res, err = handler.handleCopDAGRequest(r)
res = handler.handleCopDAGRequest(r)
} else {
res, err = handler.handleCopAnalyzeRequest(r)
}
if err != nil {
return nil, err
res = handler.handleCopAnalyzeRequest(r)
}
resp.Cop = res
case tikvrpc.CmdMvccGetByKey:
Expand Down