Skip to content

Commit

Permalink
mock-tikv: return correct Locked error. (pingcap#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Nov 21, 2016
1 parent b92330c commit 8475658
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions store/tikv/mock-tikv/cop_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/juju/errors"
"github.com/pingcap/kvproto/pkg/coprocessor"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/distsql"
"github.com/pingcap/tidb/distsql/xeval"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -107,7 +108,16 @@ func (h *rpcHandler) handleCopRequest(req *coprocessor.Request) (*coprocessor.Re
selResp.Error = toPBError(err)
selResp.Chunks = chunks
if err != nil {
resp.OtherError = err.Error()
if locked, ok := errors.Cause(err).(*ErrLocked); ok {
resp.Locked = &kvrpcpb.LockInfo{
Key: locked.Key,
PrimaryLock: locked.Primary,
LockVersion: locked.StartTS,
LockTtl: locked.TTL,
}
} else {
resp.OtherError = err.Error()
}
}
data, err := proto.Marshal(selResp)
if err != nil {
Expand Down Expand Up @@ -520,7 +530,6 @@ func (h *rpcHandler) getIndexRowFromRange(ctx *selectContext, ran kv.KeyRange, d
pair = pairs[0]
}
if pair.Err != nil {
// TODO: handle lock error.
return nil, errors.Trace(pair.Err)
}
if pair.Key == nil {
Expand Down

0 comments on commit 8475658

Please sign in to comment.