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


Golang engine.Iterator类代码示例

本文整理汇总了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)
}
开发者ID:kevinhuo88888,项目名称:tidb,代码行数:52,代码来源:snapshot.go

示例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)
}
开发者ID:js-for-kids,项目名称:tidb,代码行数:40,代码来源:snapshot.go

示例3: newDBIter

func newDBIter(it engine.Iterator) *dbIter {
	return &dbIter{
		Iterator: it,
		valid:    it.Next(),
	}
}
开发者ID:ninefive,项目名称:tidb,代码行数:6,代码来源:snapshot.go


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