简体   繁体   English

使用CouchDB作为Ledger State数据库时,如何在Hyperledger Fabric中存储数据?

[英]How is data store in Hyperledger Fabric when using CouchDB as the Ledger State database?

I'm running the code in Chaincode for Developers Tutorial , to run a basic sample chaincode to create assets (key-value pairs) on the ledger. 我在Chaincode for Developers Tutorial中运行代码,运行基本的示例链代码以在分类帐上创建资产(键值对)。

I'm able to invoke the chaincode using the cli 我可以使用cli调用链代码

peer chaincode invoke -n mycc -c '{"Args":["set", "a", "20"]}' -C myc

and also run queries 并运行查询

peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc

Now I want to see how the key value pair gets stored in CouchDB. 现在我想看看键值对如何存储在CouchDB中。 So I changed the environment variables below in the fabric-samples/chaincode-docker-devmode/docker-compose-simple.yaml 所以我在fabric-samples / chaincode-docker-devmode / docker-compose-simple.yaml中更改了下面的环境变量

CORE_LEDGER_STATE_STATEDATABASE=CouchDB
CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984

I see the documents created like below in CouchDB UI ( http://localhost:5984/myc/_all_docs ) when I run set. 我在运行set时看到在CouchDB UI( http:// localhost:5984 / myc / _all_docs )中创建的文档如下所示。

{
  "total_rows": 3,
  "offset": 0,
  "rows": [{
      "id": "lscc\u0000mycc",
      "key": "lscc\u0000mycc",
      "value": {
        "rev": "1-dc6dc8ff92efd35358cf5b89e7949c25"
      }
    },
    {
      "id": "mycc\u0000a",
      "key": "mycc\u0000a",
      "value": {
        "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20"
      }
    },
    {
      "id": "statedb_savepoint",
      "key": "statedb_savepoint",
      "value": {
        "rev": "6-2c3d131fc75772cc9e70311998bdde9d"
      }
    }
  ]
}

How/Where is the value for the key stored and retrieved? 如何/存储和检索密钥的值在哪里? It is seen as below, when checking the document in the DB, but is retrieved properly when running the chaincode get query. 在检查DB中的文档时,如下所示,但在运行chaincode get查询时正确检索。

"value": {
  "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20"
}

When 什么时候

While key persisted into DB it is prefixed with name of the chaincode, in your example it's mycc and as a separator used []byte{0x00} value. 当密钥持久存储到DB时,它的前缀是链码的名称,在您的示例中它是mycc并且作为分隔符使用[]byte{0x00}值。 Therefore you see in you example, following output: 因此,您在示例中看到以下输出:

{
  "id": "mycc\u0000a",
  "key": "mycc\u0000a",
  "value": {
    "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20"
  }
},

which stands for key a of chaincode mycc . 它代表链mycc关键字a To get the value of this key you can simply run a curl command as following adding query parameter attachements=true , for example: 要获取此键的值,您只需运行curl命令,如下所示添加查询参数attachements=true ,例如:

curl -X GET "http://localhost:5984/mychannel/mycc%00a?attachments=true"

will result with something similar to this: 会产生与此类似的结果:

--bdb0a91d2e233fdc193f2359e6a50472
Content-Type: application/json

{"_id":"mycc\u0000a","_rev":"2-2af72e502c2b43c73064728852103fbf","chaincodeid":"mycc","version":"4:0","_attachments":{"valueBytes":{"content_type":"application/octet-stream","revpos":2,"digest":"md5-qpvq4/JGMCgu7WtvFu5zbg==","length":2,"follows":true,"encoding":"gzip","encoded_length":22}}}
--bdb0a91d2e233fdc193f2359e6a50472
Content-Disposition: attachment; filename="valueBytes"
Content-Type: application/octet-stream
Content-Length: 22
Content-Encoding: gzip

4鯄i
--bdb0a91d2e233fdc193f2359e6a50472--%

For more information about how to read data from CouchDB you might find following tutorial useful. 有关如何从CouchDB读取数据的更多信息,您可能会发现以下教程很有用。

由于数据以二进制形式保存,您将找不到确切的值(相反,您会找到哈希值),但会看到包含mycc的键的记录

暂无
暂无

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

相关问题 Hyperledger Fabric Ledger 和 couchdb 问题 - Hyperledger fabric Ledger and couchdb Problem 如何在长沙发或Hyperledger中的任何其他NoSQL DB中存储/查询分类帐数据 - How to store/query ledger data in couchdb or any other nosql DB in hyperledger 使用 CouchDB 的 Hyperledger Fabric 客户端凭证存储 - Hyperledger fabric client credential store using CouchDB 如何使用 CouchDB 的 ui 在 hyperledger fabric 1.4 中停止 CouchDB 的更新? - how to stop update in the CouchDB in hyperledger fabric 1.4 using ui of CouchDB? 当人们可以直接更改couchdb数据时,Hyperledger Fabric中的数据如何安全 - How your data is safe in Hyperledger Fabric when one can make changes to couchdb data directly 当有人有意直接更改ouchdb中的数据时,如何确保Hyperledger Fabric中的数据完整性 - How to ensure data integrity in Hyperledger Fabric when someone intentionally changes data in couchdb directly 使用 couchdb hyperledger fabric 时加入对等通道时出错 - Error join peer channel when using couchdb hyperledger fabric 如何使用超级账本结构对 couchdb 中的对象数组应用分页? - How to apply a pagination on array of objects in couchdb using hyperledger fabric? 与Hyperledger Fabric一起使用时扩展CouchDB - Scaling up CouchDB when used with Hyperledger Fabric 在Hyperledger Fabric中使用putState不反映在couchdb中的值 - Value not reflecting in couchdb using putState in Hyperledger Fabric
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM