// Next - see interface 'statemgmt.RangeScanIterator' for details
func (itr *RangeScanIterator) Next() bool {
	if itr.done {
		return false
	}
	for ; itr.dbItr.Valid(); itr.dbItr.Next() {

		// making a copy of key-value bytes because, underlying key bytes are reused by itr.
		// no need to free slices as iterator frees memory when closed.
		trieKeyBytes := statemgmt.Copy(itr.dbItr.Key().Data())
		trieNodeBytes := statemgmt.Copy(itr.dbItr.Value().Data())
		value := unmarshalTrieNodeValue(trieNodeBytes)
		if util.IsNil(value) {
			continue
		}

		// found an actual key
		currentCompositeKey := trieKeyEncoderImpl.decodeTrieKeyBytes(statemgmt.Copy(trieKeyBytes))
		currentChaincodeID, currentKey := statemgmt.DecodeCompositeKey(currentCompositeKey)
		if currentChaincodeID == itr.chaincodeID && (itr.endKey == "" || currentKey <= itr.endKey) {
			itr.currentKey = currentKey
			itr.currentValue = value
			itr.dbItr.Next()
			return true
		}

		// retrieved all the keys in the given range
		break
	}
	itr.done = true
	return false
}
Beispiel #2
0
func (bucketNode *bucketNode) mergeBucketNode(anotherBucketNode *bucketNode) {
	if !bucketNode.bucketKey.equals(anotherBucketNode.bucketKey) {
		panic(fmt.Errorf("Nodes with different keys can not be merged. BaseKey=[%#v], MergeKey=[%#v]", bucketNode.bucketKey, anotherBucketNode.bucketKey))
	}
	for i, childCryptoHash := range anotherBucketNode.childrenCryptoHash {
		if !bucketNode.childrenUpdated[i] && util.IsNil(bucketNode.childrenCryptoHash[i]) {
			bucketNode.childrenCryptoHash[i] = childCryptoHash
		}
	}
}
Beispiel #3
0
func fetchBucketNodeFromDB(bucketKey *bucketKey) (*bucketNode, error) {
	openchainDB := db.GetDBHandle()
	nodeBytes, err := openchainDB.GetFromStateCF(bucketKey.getEncodedBytes())
	if err != nil {
		return nil, err
	}
	if util.IsNil(nodeBytes) {
		return nil, nil
	}
	return unmarshalBucketNode(bucketKey, nodeBytes), nil
}
Beispiel #4
0
func (c *bucketHashCalculator) computeCryptoHash() []byte {
	if c.currentChaincodeID != "" {
		c.appendCurrentChaincodeData()
		c.currentChaincodeID = ""
		c.dataNodes = nil
	}
	logger.Debug("Hashable content for bucket [%s]: length=%d, contentInStringForm=[%s]", c.bucketKey, len(c.hashingData), string(c.hashingData))
	if util.IsNil(c.hashingData) {
		return nil
	}
	return openchainUtil.ComputeCryptoHash(c.hashingData)
}
Beispiel #5
0
func unmarshalBucketNode(bucketKey *bucketKey, serializedBytes []byte) *bucketNode {
	bucketNode := newBucketNode(bucketKey)
	buffer := proto.NewBuffer(serializedBytes)
	for i := 0; i < conf.getMaxGroupingAtEachLevel(); i++ {
		childCryptoHash, err := buffer.DecodeRawBytes(false)
		if err != nil {
			panic(fmt.Errorf("this error should not occur: %s", err))
		}
		if !util.IsNil(childCryptoHash) {
			bucketNode.childrenCryptoHash[i] = childCryptoHash
		}
	}
	return bucketNode
}
Beispiel #6
0
func (dataNode *dataNode) isDelete() bool {
	return util.IsNil(dataNode.value)
}