本文整理汇总了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
}
示例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
}
示例3: LockKeys
func (txn *dbTxn) LockKeys(keys ...kv.Key) error {
for _, key := range keys {
key = kv.EncodeKey(key)
txn.markOrigin(key)
}
return nil
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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
}