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


Golang kv.EncodeKey函数代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/kv.EncodeKey函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodeKey函数的具体用法?Golang EncodeKey怎么用?Golang EncodeKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EncodeKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getSnapshotRows

func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) ([]int64, error) {
	ver := kv.Version{Ver: version}

	snap, err := d.store.GetSnapshot(ver)
	if err != nil {
		return nil, errors.Trace(err)
	}

	defer snap.MvccRelease()

	firstKey := t.RecordKey(seekHandle, nil)
	prefix := []byte(t.KeyPrefix())

	it := snap.NewMvccIterator(kv.EncodeKey([]byte(firstKey)), ver)
	defer it.Close()

	handles := make([]int64, 0, maxBatchSize)

	for it.Valid() {
		key := kv.DecodeKey([]byte(it.Key()))
		if !bytes.HasPrefix(key, prefix) {
			break
		}

		var handle int64
		handle, err = util.DecodeHandleFromRowKey(string(key))
		if err != nil {
			return nil, errors.Trace(err)
		}

		rk := kv.EncodeKey(t.RecordKey(handle, nil))

		handles = append(handles, handle)
		if len(handles) == maxBatchSize {
			seekHandle = handle + 1
			break
		}

		err = kv.NextUntil(it, util.RowKeyPrefixFilter(rk))
		if terror.ErrorEqual(err, kv.ErrNotExist) {
			break
		} else if err != nil {
			return nil, errors.Trace(err)
		}
	}

	return handles, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:48,代码来源:index.go

示例2: Inc

func (txn *dbTxn) Inc(k []byte, step int64) (int64, error) {
	log.Debugf("Inc %s, step %d txn:%d", k, step, txn.tID)
	k = kv.EncodeKey(k)

	if err := txn.markOrigin(k); err != nil {
		return 0, err
	}
	val, err := txn.UnionStore.Get(k)
	if kv.IsErrNotFound(err) {
		err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(step, 10)))
		if err != nil {
			return 0, err
		}

		return step, nil
	}

	if err != nil {
		return 0, err
	}

	intVal, err := strconv.ParseInt(string(val), 10, 0)
	if err != nil {
		return intVal, err
	}

	intVal += step
	err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(intVal, 10)))
	if err != nil {
		return 0, err
	}

	return intVal, nil
}
开发者ID:ninefive,项目名称:tidb,代码行数:34,代码来源:txn.go

示例3: LockKeys

func (txn *dbTxn) LockKeys(keys ...kv.Key) error {
	for _, key := range keys {
		key = kv.EncodeKey(key)
		txn.markOrigin(key)
	}
	return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:7,代码来源:txn.go

示例4: Inc

func (txn *dbTxn) Inc(k kv.Key, step int64) (int64, error) {
	log.Debugf("Inc %q, step %d txn:%d", k, step, txn.tid)
	k = kv.EncodeKey(k)

	txn.markOrigin(k)
	val, err := txn.UnionStore.Get(k)
	if kv.IsErrNotFound(err) {
		err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(step, 10)))
		if err != nil {
			return 0, errors.Trace(err)
		}

		return step, nil
	}
	if err != nil {
		return 0, errors.Trace(err)
	}

	intVal, err := strconv.ParseInt(string(val), 10, 0)
	if err != nil {
		return intVal, errors.Trace(err)
	}

	intVal += step
	err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(intVal, 10)))
	if err != nil {
		return 0, errors.Trace(err)
	}
	txn.store.compactor.OnSet(k)
	return intVal, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:31,代码来源:txn.go

示例5: BatchPrefetch

func (txn *dbTxn) BatchPrefetch(keys []kv.Key) error {
	encodedKeys := make([]kv.Key, len(keys))
	for i, k := range keys {
		encodedKeys[i] = kv.EncodeKey(k)
	}
	_, err := txn.UnionStore.Snapshot.BatchGet(encodedKeys)
	return err
}
开发者ID:yzl11,项目名称:vessel,代码行数:8,代码来源:txn.go

示例6: Delete

func (txn *hbaseTxn) Delete(k kv.Key) error {
	log.Debugf("delete %q txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	err := txn.UnionStore.Delete(k)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:9,代码来源:txn.go

示例7: Seek

func (txn *hbaseTxn) Seek(k kv.Key) (kv.Iterator, error) {
	log.Debugf("seek %q txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	iter, err := txn.UnionStore.Seek(k, txn)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return kv.NewDecodeKeyIter(iter), nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:9,代码来源:txn.go

示例8: LockKeys

func (txn *dbTxn) LockKeys(keys ...kv.Key) error {
	for _, key := range keys {
		key = kv.EncodeKey(key)
		if err := txn.markOrigin(key); err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
开发者ID:botvs,项目名称:tidb,代码行数:9,代码来源:txn.go

示例9: LockKeys

func (txn *dbTxn) LockKeys(keys ...[]byte) error {
	for _, key := range keys {
		key = kv.EncodeKey(key)
		if err := txn.markOrigin(key); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:ninefive,项目名称:tidb,代码行数:9,代码来源:txn.go

示例10: Delete

func (txn *dbTxn) Delete(k kv.Key) error {
	log.Debugf("delete key:%q, txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	err := txn.UnionStore.Delete(k)
	if err != nil {
		return errors.Trace(err)
	}
	txn.store.compactor.OnDelete(k)
	return nil
}
开发者ID:botvs,项目名称:tidb,代码行数:10,代码来源:txn.go

示例11: Set

func (txn *dbTxn) Set(k []byte, data []byte) error {
	if len(data) == 0 {
		// Incase someone use it in the wrong way, we can figure it out immediately
		debug.PrintStack()
		return ErrCannotSetNilValue
	}

	log.Debugf("set key:%s, txn:%d", k, txn.tID)
	k = kv.EncodeKey(k)
	return txn.UnionStore.Set(k, data)
}
开发者ID:ninefive,项目名称:tidb,代码行数:11,代码来源:txn.go

示例12: Set

func (txn *hbaseTxn) Set(k kv.Key, data []byte) error {
	if len(data) == 0 {
		// Incase someone use it in the wrong way, we can figure it out immediately
		debug.PrintStack()
		return errors.Trace(ErrCannotSetNilValue)
	}

	log.Debugf("set key:%q, txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	return txn.UnionStore.Set(k, data)
}
开发者ID:yzl11,项目名称:vessel,代码行数:11,代码来源:txn.go

示例13: Get

func (txn *hbaseTxn) Get(k kv.Key) ([]byte, error) {
	log.Debugf("get key:%q, txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	val, err := txn.UnionStore.Get(k)
	if kv.IsErrNotFound(err) || len(val) == 0 {
		return nil, errors.Trace(kv.ErrNotExist)
	}
	if err != nil {
		return nil, errors.Trace(err)
	}
	return val, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:12,代码来源:txn.go

示例14: GetInt64

func (txn *dbTxn) GetInt64(k kv.Key) (int64, error) {
	k = kv.EncodeKey(k)
	val, err := txn.UnionStore.Get(k)
	if kv.IsErrNotFound(err) {
		return 0, nil
	}
	if err != nil {
		return 0, errors.Trace(err)
	}
	intVal, err := strconv.ParseInt(string(val), 10, 0)
	return intVal, errors.Trace(err)
}
开发者ID:yzl11,项目名称:vessel,代码行数:12,代码来源:txn.go

示例15: Set

func (txn *dbTxn) Set(k kv.Key, data []byte) error {
	if len(data) == 0 {
		// Incase someone use it in the wrong way, we can figure it out immediately.
		debug.PrintStack()
		return errors.Trace(ErrCannotSetNilValue)
	}

	log.Debugf("set key:%q, txn:%d", k, txn.tid)
	k = kv.EncodeKey(k)
	err := txn.UnionStore.Set(k, data)
	if err != nil {
		return errors.Trace(err)
	}
	txn.store.compactor.OnSet(k)
	return nil
}
开发者ID:botvs,项目名称:tidb,代码行数:16,代码来源:txn.go


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