当前位置: 首页>>代码示例>>Golang>>正文


Golang errors2.ErrorEqual函数代码示例

本文整理汇总了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
}
开发者ID:Brian110,项目名称:tidb,代码行数:8,代码来源:union_store.go

示例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))
	}
}
开发者ID:ninefive,项目名称:tidb,代码行数:10,代码来源:main.go

示例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
}
开发者ID:nengwang,项目名称:tidb,代码行数:11,代码来源:main.go

示例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
}
开发者ID:ninefive,项目名称:tidb,代码行数:12,代码来源:txn.go

示例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
}
开发者ID:botvs,项目名称:tidb,代码行数:8,代码来源:memdb_buffer.go

示例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
	}
}
开发者ID:hxiaodon,项目名称:tidb,代码行数:34,代码来源:conn.go

示例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)
}
开发者ID:szctop,项目名称:tidb,代码行数:8,代码来源:drop.go

示例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
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:33,代码来源:kv.go

示例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)
	}
}
开发者ID:hxiaodon,项目名称:tidb,代码行数:36,代码来源:driver_tidb.go

示例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
}
开发者ID:rose1988c,项目名称:tidb,代码行数:61,代码来源:tables.go

示例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)
}
开发者ID:WilliamRen,项目名称:tidb,代码行数:27,代码来源:ddl.go

示例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)
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:9,代码来源:hash.go

示例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)
}
开发者ID:hanjinze,项目名称:tidb,代码行数:9,代码来源:string.go

示例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)
}
开发者ID:hanjinze,项目名称:tidb,代码行数:9,代码来源:string.go

示例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)
}
开发者ID:hanjinze,项目名称:tidb,代码行数:11,代码来源:string.go


注:本文中的github.com/pingcap/tidb/util/errors2.ErrorEqual函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。