Ejemplo n.º 1
0
func newDataKey(chaincodeID string, key string) *dataKey {
	logger.Debug("Enter - newDataKey. chaincodeID=[%s], key=[%s]", chaincodeID, key)
	compositeKey := statemgmt.ConstructCompositeKey(chaincodeID, key)
	bucketHash := conf.computeBucketHash(compositeKey)
	// Adding one because - we start bucket-numbers 1 onwards
	bucketNumber := int(bucketHash)%conf.getNumBucketsAtLowestLevel() + 1
	dataKey := &dataKey{newBucketKeyAtLowestLevel(bucketNumber), compositeKey}
	logger.Debug("Exit - newDataKey=[%s]", dataKey)
	return dataKey
}
Ejemplo n.º 2
0
// AddChangesForPersistence - method implementation for interface 'statemgmt.HashableState'
func (impl *StateImpl) AddChangesForPersistence(writeBatch *gorocksdb.WriteBatch) error {
	delta := impl.stateDelta
	if delta == nil {
		return nil
	}
	openchainDB := db.GetDBHandle()
	updatedChaincodeIds := delta.GetUpdatedChaincodeIds(false)
	for _, updatedChaincodeID := range updatedChaincodeIds {
		updates := delta.GetUpdates(updatedChaincodeID)
		for updatedKey, value := range updates {
			compositeKey := statemgmt.ConstructCompositeKey(updatedChaincodeID, updatedKey)
			if value.IsDeleted() {
				writeBatch.DeleteCF(openchainDB.StateCF, compositeKey)
			} else {
				writeBatch.PutCF(openchainDB.StateCF, compositeKey, value.GetValue())
			}
		}
	}
	return nil
}
Ejemplo n.º 3
0
func minimumPossibleDataKeyBytes(bucketNumber int, chaincodeID string, key string) []byte {
	b := encodeBucketNumber(bucketNumber)
	b = append(b, statemgmt.ConstructCompositeKey(chaincodeID, key)...)
	return b
}
Ejemplo n.º 4
0
// Get - method implementation for interface 'statemgmt.HashableState'
func (impl *StateImpl) Get(chaincodeID string, key string) ([]byte, error) {
	compositeKey := statemgmt.ConstructCompositeKey(chaincodeID, key)
	openchainDB := db.GetDBHandle()
	return openchainDB.GetFromStateCF(compositeKey)
}
Ejemplo n.º 5
0
func (testHasher *testHasher) populate(chaincodeID string, key string, hash uint32) {
	testHasher.testHashFunctionInput[string(statemgmt.ConstructCompositeKey(chaincodeID, key))] = hash
}