github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/store/tikv/error.go (about) 1 // Copyright 2016 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package tikv 15 16 import ( 17 "github.com/insionng/yougam/libraries/juju/errors" 18 pb "github.com/insionng/yougam/libraries/pingcap/kvproto/pkg/kvrpcpb" 19 ) 20 21 var ( 22 // errInnerRetryable if caller can retry this directly then return this error. 23 errInnerRetryable = errors.New("try again innerly") 24 // errInvalidResponse represents response message is invalid. 25 errInvalidResponse = errors.New("invalid response") 26 // errBodyMissing response body is missing error 27 errBodyMissing = errors.New("response body is missing") 28 ) 29 30 // TiDB decides whether to retry transaction by checking if error message contains 31 // string "try again later" literally. 32 // In TiClient we use `errors.Annotate(err, txnRetryableMark)` to direct TiDB to 33 // restart a transaction. 34 // Note that it should be only used if i) the error occurs inside a transaction 35 // and ii) the error is not totally unexpected and hopefully will recover soon. 36 const txnRetryableMark = "[try again later]" 37 38 // errMismatch if response mismatches request return error. 39 func errMismatch(resp *pb.Response, req *pb.Request) error { 40 return errors.Errorf("message type mismatches, response[%s] request[%s]", 41 resp.GetType(), req.GetType()) 42 }