本文整理匯總了Golang中github.com/pingcap/tidb/store/localstore/engine.Iterator類的典型用法代碼示例。如果您正苦於以下問題:Golang Iterator類的具體用法?Golang Iterator怎麽用?Golang Iterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Iterator類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Next
func (it *dbIter) Next(fn kv.FnKeyCmp) (kv.Iterator, error) {
encKey := codec.EncodeBytes(nil, it.startKey)
// max key
encEndKey := codec.EncodeBytes(nil, []byte{0xff, 0xff})
var retErr error
var engineIter engine.Iterator
for {
engineIter, retErr = it.s.db.Seek(encKey)
if retErr != nil {
return nil, errors.Trace(retErr)
}
// Check if overflow
if !engineIter.Next() {
it.valid = false
break
}
metaKey := engineIter.Key()
// Check if meet the end of table.
if bytes.Compare(metaKey, encEndKey) >= 0 {
it.valid = false
break
}
// Get real key from metaKey
key, _, err := MvccDecode(metaKey)
if err != nil {
// It's not a valid metaKey, maybe overflow (other data).
it.valid = false
break
}
// Get kv pair.
val, err := it.s.MvccGet(key, it.exceptedVersion)
if err != nil && !errors2.ErrorEqual(err, kv.ErrNotExist) {
// Get this version error
it.valid = false
retErr = err
break
}
if val != nil {
it.k = key
it.v = val
it.startKey = key.Next()
break
}
// Release the iterator, and update key
engineIter.Release()
// Current key's all versions are deleted, just go next key.
encKey = codec.EncodeBytes(nil, key.Next())
}
engineIter.Release()
return it, errors.Trace(retErr)
}
示例2: Next
func (it *dbIter) Next() (kv.Iterator, error) {
encKey := codec.EncodeBytes(nil, it.startKey)
var retErr error
var engineIter engine.Iterator
for {
var err error
engineIter, err = it.s.internalSeek(encKey)
if err != nil {
it.valid = false
retErr = err
break
}
metaKey := engineIter.Key()
// Get real key from metaKey
key, _, err := MvccDecode(metaKey)
if err != nil {
// It's not a valid metaKey, maybe overflow (other data).
it.valid = false
break
}
// Get kv pair.
val, err := it.s.MvccGet(key, it.exceptedVersion)
if err != nil && !errors2.ErrorEqual(err, kv.ErrNotExist) {
// Get this version error
it.valid = false
retErr = err
break
}
if val != nil {
it.k = bytes.CloneBytes(key)
it.v = bytes.CloneBytes(val)
it.startKey = key.Next()
break
}
// Current key's all versions are deleted, just go next key.
encKey = codec.EncodeBytes(nil, key.Next())
}
return it, errors.Trace(retErr)
}
示例3: newDBIter
func newDBIter(it engine.Iterator) *dbIter {
return &dbIter{
Iterator: it,
valid: it.Next(),
}
}