本文整理汇总了Golang中github.com/pingcap/tidb/kv.EncodeKey函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodeKey函数的具体用法?Golang EncodeKey怎么用?Golang EncodeKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EncodeKey函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestDBClose
func (s *testKVSuite) TestDBClose(c *C) {
path := "memory:test"
d := Driver{
goleveldb.MemoryDriver{},
}
store, err := d.Open(path)
c.Assert(err, IsNil)
txn, err := store.Begin()
c.Assert(err, IsNil)
err = txn.Set([]byte("a"), []byte("b"))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
ver, err := store.CurrentVersion()
c.Assert(err, IsNil)
c.Assert(kv.MaxVersion.Cmp(ver), Equals, 1)
snap, err := store.GetSnapshot(kv.MaxVersion)
c.Assert(err, IsNil)
_, err = snap.MvccGet(kv.EncodeKey([]byte("a")), kv.MaxVersion)
c.Assert(err, IsNil)
txn, err = store.Begin()
c.Assert(err, IsNil)
err = store.Close()
c.Assert(err, IsNil)
_, err = store.Begin()
c.Assert(err, NotNil)
_, err = store.GetSnapshot(kv.MaxVersion)
c.Assert(err, NotNil)
err = txn.Set([]byte("a"), []byte("b"))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, NotNil)
snap.MvccRelease()
}
开发者ID:zebozhuang,项目名称:tidb,代码行数:47,代码来源:kv_test.go
示例17: Get
func (txn *dbTxn) Get(k []byte) ([]byte, error) {
log.Debugf("get key:%s, txn:%d", k, txn.tID)
k = kv.EncodeKey(k)
val, err := txn.UnionStore.Get(k)
if kv.IsErrNotFound(err) {
return nil, kv.ErrNotExist
}
if err != nil {
return nil, err
}
if len(val) == 0 {
return nil, kv.ErrNotExist
}
return val, nil
}
开发者ID:ninefive,项目名称:tidb,代码行数:17,代码来源:txn.go
示例18: Seek
func (txn *dbTxn) Seek(k kv.Key, fnKeyCmp func(kv.Key) bool) (kv.Iterator, error) {
log.Debugf("seek key:%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)
}
if !iter.Valid() {
return &kv.UnionIter{}, nil
}
if fnKeyCmp != nil {
if fnKeyCmp([]byte(iter.Key())[:1]) {
return &kv.UnionIter{}, nil
}
}
return iter, nil
}
开发者ID:Brian110,项目名称:tidb,代码行数:20,代码来源:txn.go
示例19: Delete
func (txn *dbTxn) Delete(k kv.Key) error {
log.Debugf("delete key:%q, txn:%d", k, txn.tID)
k = kv.EncodeKey(k)
return txn.UnionStore.Delete(k)
}
开发者ID:Brian110,项目名称:tidb,代码行数:5,代码来源:txn.go
示例20: RangePrefetch
func (txn *dbTxn) RangePrefetch(start, end kv.Key, limit int) error {
_, err := txn.UnionStore.Snapshot.RangeGet(kv.EncodeKey(start), kv.EncodeKey(end), limit)
return err
}
开发者ID:yzl11,项目名称:vessel,代码行数:4,代码来源:txn.go
注:本文中的github.com/pingcap/tidb/kv.EncodeKey函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论