github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/store/tikv/mock-tikv/errors.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 mocktikv 15 16 import "fmt" 17 18 // ErrLocked is returned when trying to Read/Write on a locked key. Client should 19 // backoff or cleanup the lock then retry. 20 type ErrLocked struct { 21 Key []byte 22 Primary []byte 23 StartTS uint64 24 } 25 26 // Error formats the lock to a string. 27 func (e *ErrLocked) Error() string { 28 return fmt.Sprintf("key is locked, key: %q, primary: %q, startTS: %v", e.Key, e.Primary, e.StartTS) 29 } 30 31 // ErrRetryable suggests that client may restart the txn. e.g. write conflict. 32 type ErrRetryable string 33 34 func (e ErrRetryable) Error() string { 35 return fmt.Sprintf("retryable: %s", string(e)) 36 } 37 38 // ErrAbort means something is wrong and client should abort the txn. 39 type ErrAbort string 40 41 func (e ErrAbort) Error() string { 42 return fmt.Sprintf("abort: %s", string(e)) 43 } 44 45 // ErrAlreadyCommitted is returned specially when client tries to rollback a 46 // committed lock. 47 type ErrAlreadyCommitted uint64 48 49 func (e ErrAlreadyCommitted) Error() string { 50 return fmt.Sprint("txn already committed") 51 }