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


Golang bytes.CloneBytes函数代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/util/bytes.CloneBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang CloneBytes函数的具体用法?Golang CloneBytes怎么用?Golang CloneBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CloneBytes函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Next

func (i *iterator) Next() bool {
	i.d.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(bucketName)
		c := b.Cursor()
		var key []byte
		var value []byte

		if !i.seeked {
			i.seeked = true
			if i.key == nil {
				key, value = c.First()
			} else {
				key, value = c.Seek(i.key)
			}
		} else {
			c.Seek(i.key)
			key, value = c.Next()
		}

		i.key = bytes.CloneBytes(key)
		i.value = bytes.CloneBytes(value)

		return nil
	})

	return i.key != nil
}
开发者ID:netroby,项目名称:tidb,代码行数:27,代码来源:boltdb.go

示例2: SeekReverse

func (d *db) SeekReverse(startKey []byte) ([]byte, []byte, error) {
	var key, value []byte
	err := d.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(bucketName)
		c := b.Cursor()
		var k, v []byte
		if startKey == nil {
			k, v = c.Last()
		} else {
			c.Seek(startKey)
			k, v = c.Prev()
		}
		if k != nil {
			key, value = bytes.CloneBytes(k), bytes.CloneBytes(v)
		}
		return nil
	})

	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	if key == nil {
		return nil, nil, errors.Trace(engine.ErrNotFound)
	}
	return key, value, nil
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:26,代码来源:boltdb.go

示例3: MultiSeek

func (d *db) MultiSeek(keys [][]byte) []*engine.MSeekResult {
	res := make([]*engine.MSeekResult, 0, len(keys))
	d.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(bucketName)
		c := b.Cursor()
		for _, key := range keys {
			var k, v []byte
			if key == nil {
				k, v = c.First()
			} else {
				k, v = c.Seek(key)
			}

			r := &engine.MSeekResult{}
			if k == nil {
				r.Err = engine.ErrNotFound
			} else {
				r.Key, r.Value, r.Err = bytes.CloneBytes(k), bytes.CloneBytes(v), nil
			}

			res = append(res, r)
		}
		return nil
	})

	return res
}
开发者ID:lovedboy,项目名称:tidb,代码行数:27,代码来源:boltdb.go

示例4: Seek

func (i *iterator) Seek(startKey []byte) bool {
	i.d.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(bucketName)
		c := b.Cursor()
		var key []byte
		var value []byte

		key, value = c.Seek(startKey)

		i.key = bytes.CloneBytes(key)
		i.value = bytes.CloneBytes(value)

		return nil
	})

	return i.key != nil
}
开发者ID:netroby,项目名称:tidb,代码行数:17,代码来源:boltdb.go

示例5: 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

示例6: Get

func (d *db) Get(key []byte) ([]byte, error) {
	var value []byte

	err := d.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(bucketName)
		v := b.Get(key)
		if v == nil {
			return errors.Trace(engine.ErrNotFound)
		}
		value = bytes.CloneBytes(v)
		return nil
	})

	return value, errors.Trace(err)
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:15,代码来源:boltdb.go

示例7: getAllVersions

func (gc *localstoreCompactor) getAllVersions(k kv.Key) ([]kv.EncodedKey, error) {
	startKey := MvccEncodeVersionKey(k, kv.MaxVersion)
	endKey := MvccEncodeVersionKey(k, kv.MinVersion)

	it, err := gc.db.Seek(startKey)
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer it.Release()

	var ret []kv.EncodedKey
	for it.Next() {
		if kv.EncodedKey(it.Key()).Cmp(endKey) < 0 {
			ret = append(ret, bytes.CloneBytes(kv.EncodedKey(it.Key())))
		}
	}
	return ret, nil
}
开发者ID:netroby,项目名称:tidb,代码行数:18,代码来源:compactor.go

示例8: getAllVersions

func (gc *localstoreCompactor) getAllVersions(key kv.Key) ([]kv.EncodedKey, error) {
	var keys []kv.EncodedKey
	k := key
	for ver := kv.MaxVersion; ver.Ver > 0; ver.Ver-- {
		mvccK, _, err := gc.db.Seek(MvccEncodeVersionKey(key, ver))
		if terror.ErrorEqual(err, engine.ErrNotFound) {
			break
		}
		if err != nil {
			return nil, errors.Trace(err)
		}
		k, ver, err = MvccDecode(mvccK)
		if k.Cmp(key) != 0 {
			break
		}
		if err != nil {
			return nil, errors.Trace(err)
		}
		keys = append(keys, bytes.CloneBytes(mvccK))
	}
	return keys, nil
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:22,代码来源:compactor.go

示例9: MvccGet

func (s *dbSnapshot) MvccGet(k kv.Key, ver kv.Version) ([]byte, error) {
	// engine Snapshot return nil, nil for value not found,
	// so here we will check nil and return kv.ErrNotExist.
	// get newest version, (0, MaxUint64)
	// Key arrangement:
	// Key -> META
	// ...
	// Key_ver
	// Key_ver-1
	// Key_ver-2
	// ...
	// Key_ver-n
	// Key_0
	// NextKey -> META
	// NextKey_xxx
	startKey := MvccEncodeVersionKey(k, ver)
	endKey := MvccEncodeVersionKey(k, kv.MinVersion)

	it, err := s.internalSeek(startKey)
	if err != nil {
		return nil, errors.Trace(err)
	}

	var rawKey []byte
	var v []byte
	// Check if the scan is not exceed this key's all versions and the value is not
	// tombstone.
	if kv.EncodedKey(it.Key()).Cmp(endKey) < 0 && !isTombstone(it.Value()) {
		rawKey = it.Key()
		v = it.Value()
	}
	// No such key (or it's tombstone).
	if rawKey == nil {
		return nil, kv.ErrNotExist
	}
	return bytes.CloneBytes(v), nil
}
开发者ID:js-for-kids,项目名称:tidb,代码行数:37,代码来源:snapshot.go


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