本文整理汇总了Golang中github.com/pingcap/tidb/util/errors2.ErrorEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorEqual函数的具体用法?Golang ErrorEqual怎么用?Golang ErrorEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: IsErrNotFound
// IsErrNotFound checks if err is a kind of NotFound error.
func IsErrNotFound(err error) bool {
if errors2.ErrorEqual(err, leveldb.ErrNotFound) || errors2.ErrorEqual(err, ErrNotExist) {
return true
}
return false
}
示例2: mayExit
func mayExit(err error, line string) {
if errors2.ErrorEqual(err, liner.ErrPromptAborted) || errors2.ErrorEqual(err, io.EOF) {
fmt.Println("\nBye")
saveHistory()
os.Exit(0)
}
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
}
示例3: mayExit
func mayExit(err error, l string) bool {
if errors2.ErrorEqual(err, liner.ErrPromptAborted) || errors2.ErrorEqual(err, io.EOF) {
fmt.Println("\nBye")
saveHistory()
return true
}
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
return false
}
示例4: IsRetryableError
// IsRetryableError check if the err is not a fatal error and the under going operation is worth to retried.
func IsRetryableError(err error) bool {
if err == nil {
return false
}
if errors2.ErrorEqual(err, ErrLockConflict) || errors2.ErrorEqual(err, ErrConditionNotMatch) {
return true
}
return false
}
示例5: Get
// Get returns the value associated with key.
func (m *memDbBuffer) Get(k Key) ([]byte, error) {
v, err := m.db.Get(k)
if errors2.ErrorEqual(err, leveldb.ErrNotFound) {
return nil, ErrNotExist
}
return v, nil
}
示例6: Run
func (cc *clientConn) Run() {
defer func() {
r := recover()
if r != nil {
const size = 4096
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Errorf("lastCmd %s, %v, %s", cc.lastCmd, r, buf)
}
cc.Close()
}()
for {
cc.alloc.Reset()
data, err := cc.readPacket()
if err != nil {
if errors2.ErrorNotEqual(err, io.EOF) {
log.Error(err)
}
return
}
if err := cc.dispatch(data); err != nil {
if errors2.ErrorEqual(err, io.EOF) {
return
}
log.Errorf("dispatch error %s, %s", errors.ErrorStack(err), cc)
log.Errorf("cmd: %s", string(data[1:]))
cc.writeError(err)
}
cc.pkg.sequence = 0
}
}
示例7: Exec
// Exec implements the stmt.Statement Exec interface.
func (s *DropDatabaseStmt) Exec(ctx context.Context) (rset.Recordset, error) {
err := sessionctx.GetDomain(ctx).DDL().DropSchema(ctx, model.NewCIStr(s.Name))
if errors2.ErrorEqual(err, ddl.ErrNotExists) && s.IfExists {
err = nil
}
return nil, errors.Trace(err)
}
示例8: tryConditionLockKey
// Both lock and unlock are used for simulating scenario of percolator papers.
func (s *dbStore) tryConditionLockKey(tid uint64, key string, snapshotVal []byte) error {
s.mu.Lock()
defer s.mu.Unlock()
if _, ok := s.keysLocked[key]; ok {
return errors.Trace(kv.ErrLockConflict)
}
metaKey := codec.EncodeBytes(nil, []byte(key))
currValue, err := s.db.Get(metaKey)
if errors2.ErrorEqual(err, kv.ErrNotExist) || currValue == nil {
// If it's a new key, we won't need to check its version
return nil
}
if err != nil {
return errors.Trace(err)
}
_, ver, err := codec.DecodeUint(currValue)
if err != nil {
return errors.Trace(err)
}
// If there's newer version of this key, returns error.
if ver > tid {
log.Warnf("txn:%d, tryLockKey condition not match for key %s, currValue:%q, snapshotVal:%q", tid, key, currValue, snapshotVal)
return errors.Trace(kv.ErrConditionNotMatch)
}
s.keysLocked[key] = tid
return nil
}
示例9: Bootstrap
// Bootstrap initiates TiDB server.
func Bootstrap(store kv.Storage) {
td := NewTiDBDriver(store)
tc, err := td.OpenCtx(defaultCapability, mysql.DefaultCollationID, "")
defer tc.Close()
if err != nil {
log.Fatal(err)
}
// Create a test database.
_, err = tc.Execute("CREATE DATABASE IF NOT EXISTS test")
if err != nil {
log.Fatal(err)
}
// Check if mysql db exists.
_, err = tc.Execute("USE mysql;")
if err == nil {
// We have already finished bootstrap.
return
} else if !errors2.ErrorEqual(err, tidberrors.ErrDatabaseNotExist) {
log.Fatal(err)
}
_, err = tc.Execute("CREATE DATABASE mysql;")
if err != nil {
log.Fatal(err)
}
_, err = tc.Execute("CREATE TABLE mysql.user (Host CHAR(64), User CHAR(16), Password CHAR(41), PRIMARY KEY (Host, User));")
if err != nil {
log.Fatal(err)
}
// Insert a default user with empty password.
_, err = tc.Execute(`INSERT INTO mysql.user VALUES ("localhost", "root", ""), ("127.0.0.1", "root", "");`)
if err != nil {
log.Fatal(err)
}
}
示例10: AddRecord
// AddRecord implements table.Table AddRecord interface.
func (t *Table) AddRecord(ctx context.Context, r []interface{}) (recordID int64, err error) {
id := variable.GetSessionVars(ctx).LastInsertID
// Already have auto increment ID
if id != 0 {
recordID = int64(id)
} else {
recordID, err = t.alloc.Alloc(t.ID)
if err != nil {
return 0, err
}
}
txn, err := ctx.GetTxn(false)
if err != nil {
return 0, err
}
for _, v := range t.indices {
if v == nil {
continue
}
colVals, _ := v.FetchValues(r)
if err = v.X.Create(txn, colVals, recordID); err != nil {
if errors2.ErrorEqual(err, kv.ErrKeyExists) {
// Get the duplicate row handle
iter, _, terr := v.X.Seek(txn, colVals)
if terr != nil {
return 0, errors.Trace(terr)
}
_, h, terr := iter.Next()
if terr != nil {
return 0, errors.Trace(terr)
}
return h, errors.Trace(err)
}
return 0, errors.Trace(err)
}
}
// split a record into multiple kv pair
// first key -> LOCK
k := t.RecordKey(recordID, nil)
// A new row with current txn-id as lockKey
err = txn.Set([]byte(k), []byte(txn.String()))
if err != nil {
return 0, err
}
// column key -> column value
for _, c := range t.Cols() {
colKey := t.RecordKey(recordID, c)
data, err := t.EncodeValue(r[c.Offset])
if err != nil {
return 0, err
}
err = txn.Set([]byte(colKey), data)
if err != nil {
return 0, err
}
}
variable.GetSessionVars(ctx).AddAffectedRows(1)
return recordID, nil
}
示例11: deleteTableData
func (d *ddl) deleteTableData(ctx context.Context, t table.Table) error {
// Remove data
err := t.Truncate(ctx)
if err != nil {
return errors.Trace(err)
}
txn, err := ctx.GetTxn(false)
if err != nil {
return errors.Trace(err)
}
// Remove indices
for _, v := range t.Indices() {
if v != nil && v.X != nil {
if err = v.X.Drop(txn); err != nil {
return errors.Trace(err)
}
}
}
// Remove auto ID key
err = txn.Delete([]byte(meta.AutoIDKey(t.TableID())))
// Auto ID meta is created when the first time used, so it may not exist.
if errors2.ErrorEqual(err, kv.ErrNotExist) {
return nil
}
return errors.Trace(err)
}
示例12: HGet
// HGet gets the value of a hash field.
func (t *TxStructure) HGet(key []byte, field []byte) ([]byte, error) {
dataKey := t.encodeHashDataKey(key, field)
value, err := t.txn.Get(dataKey)
if errors2.ErrorEqual(err, kv.ErrNotExist) {
err = nil
}
return value, errors.Trace(err)
}
示例13: Clear
// Clear removes the string value of the key.
func (t *TxStructure) Clear(key []byte) error {
ek := t.encodeStringDataKey(key)
err := t.txn.Delete(ek)
if errors2.ErrorEqual(err, kv.ErrNotExist) {
err = nil
}
return errors.Trace(err)
}
示例14: Get
// Get gets the string value of a key.
func (t *TxStructure) Get(key []byte) ([]byte, error) {
ek := t.encodeStringDataKey(key)
value, err := t.txn.Get(ek)
if errors2.ErrorEqual(err, kv.ErrNotExist) {
err = nil
}
return value, errors.Trace(err)
}
示例15: Inc
// Inc increments the integer value of a key by step, returns
// the value after the increment.
func (t *TxStructure) Inc(key []byte, step int64) (int64, error) {
ek := t.encodeStringDataKey(key)
// txn Inc will lock this key, so we don't lock it here.
n, err := t.txn.Inc(ek, step)
if errors2.ErrorEqual(err, kv.ErrNotExist) {
err = nil
}
return n, errors.Trace(err)
}