简体   繁体   English

Hyperledger fabric - 在私人数据收集中需要两个独特的领域

[英]Hyperledger fabric - Need two unique fields in private data collection

I am working on a scenario in private data collection where I want to have one more unique field other than ID.我正在处理私人数据收集中的一个场景,我想在其中拥有一个除 ID 之外的唯一字段。 eg I have an object which contains carID, color, modelNumber fields of which I want carID as well as modelNumber to be unique.例如,我有一个包含 carID、颜色、modelNumber 字段的对象,我希望其中的 carID 和 modelNumber 是唯一的。 When I try to implement this I need to call getPrivateDataQueryResults() before adding new asset using putPrivateData() and I am getting error: Unsupported transaction: Transaction has already performed queries on pvt data.当我尝试实现这一点时,我需要在使用 putPrivateData() 添加新资产之前调用 getPrivateDataQueryResults() 并且出现错误:不支持的事务:事务已经对 pvt 数据执行了查询。 Writes are not allowed.不允许写入。

I expected a boolean response from getPrivateDataQueryResults() for modelNumber.我期待 getPrivateDataQueryResults() 对 modelNumber 的布尔响应。 If it is true, it should call putPrivateData() otherwise throw error like "Model number already exists".如果为真,则应调用 putPrivateData() 否则会抛出“型号已存在”之类的错误。

But in response the error I am getting is "Unsupported transaction: Transaction has already performed queries on pvt data. Writes are not allowed."但作为回应,我得到的错误是“不受支持的交易:交易已经对 pvt 数据执行了查询。不允许写入。”

Being new in HLFI am stuck on how to implement this scenario.作为 HLFI 的新手,我一直在思考如何实现这种情况。 Any help would be greatly appreciated.任何帮助将不胜感激。

Thanks in advance.提前致谢。

When I try to implement this I need to call getPrivateDataQueryResults() before adding new asset using putPrivateData() and I am getting error: Unsupported transaction: Transaction has already performed queries on pvt data.当我尝试实现这一点时,我需要在使用 putPrivateData() 添加新资产之前调用 getPrivateDataQueryResults() 并且出现错误:不支持的事务:事务已经对 pvt 数据执行了查询。 Writes are not allowed.不允许写入。

I'm lazy so let me cite from the official documentation:我很懒所以让我引用官方文档:

Concurrency Control Version Check is a method of keeping ledger state in sync across peers on a channel.并发控制版本检查是一种在通道上的对等点之间保持账本状态同步的方法。 Peers execute transactions in parallel, and before committing to the ledger, peers check whether the state read at the time the transaction was executed has been modified in a new block that was in-flight at time of execution or in a prior transaction in the same block.节点并行执行交易,并且在提交到分类帐之前,节点检查在执行交易时读取的状态是否已在执行时正在运行的新块中或在同一交易中的先前交易中被修改堵塞。 If the data read for the transaction has changed between execution time and commit time, then a Concurrency Control Version Check violation has occurred, and the transaction is marked as invalid on the ledger and values are not updated in the state database.如果为交易读取的数据在执行时间和提交时间之间发生了变化,那么就会发生并发控制版本检查违规,并且交易在分类账上被标记为无效,并且状态数据库中的值不会更新。

The above is true for regular GetState or range queries.以上内容适用于常规 GetState 或范围查询。 However, rich queries are not re-executed upon commit time.但是,富查询不会在提交时重新执行。 This means that in order to protect the integrity of transaction execution (such that the end result of data changes is equivalent to some serial execution), if you used a rich query in your transaction, the transaction should not have any data updates.这意味着为了保护事务执行的完整性(这样数据更改的最终结果等同于某些串行执行),如果您在事务中使用了富查询,则事务不应该有任何数据更新。 That's why you're getting your error.这就是为什么你得到你的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM