當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。