简体   繁体   English

为 FIWARE Orion ContextBroker 启用 MongoDB 分片

[英]Enable MongoDB sharding for FIWARE Orion ContextBroker

I am trying to setup MongoDB sharding for the Orion ContextBroker, and IotAgent-Json, I am able to distribute the device provisioning and service data in MongoDb between shards, but whenever i sends the actual device data it gives following error:我正在尝试为 Orion ContextBroker 和 IotAgent-Json 设置 MongoDB 分片,我能够在分片之间分配 MongoDb 中的设备配置和服务数据,但是每当我发送实际设备数据时,它都会给出以下错误:

{ "name": "ENTITY_GENERIC_ERROR", "message": "Error accesing entity data for device: DeviceEntity1 of type: DeviceEntity1"} { "name": "ENTITY_GENERIC_ERROR", "message": "访问设备实体数据时出错:DeviceEntity1 类型:DeviceEntity1"}

I am using following command to shard the collection:我正在使用以下命令对集合进行分片:
sh.shardCollection("orion-fiwareiot.entities",{"_id.servicePath": 1, "_id.id": 1, "_id.type": 1})

Intercept of ContextBroker log:截取 ContextBroker 日志:

time=Wednesday 25 Sep 06:54:22 2019.729Z |时间=2019.729Z 9 月 25 日星期三 06:54:22 | lvl=ERROR | lvl=错误 | corr=4e22de66-df61-11e9-aa53-3464a92017cd | corr=4e22de66-df61-11e9-aa53-3464a92017cd | trans=1569393389-597-00000000007 |反式=1569393389-597-00000000007 | from=127.0.0.1 |从=127.0.0.1 | srv=fiwareiot | srv=fiwareiot | subsrv=/raw | subsrv=/原始 | comp=Orion | comp=猎户座 | op=AlarmManager.cpp[211]:dbError | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: collection: orion-fiwareiot.entities - update(): <{ _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } },{ $set: { attrs.deviceName: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationType: { value: "O", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationName: { value: "Mumbai", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceType: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceMa msg=Raising alarm DatabaseError: collection: orion-fiwareiot.entities - update(): <{ _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$ / ] } },{ $set: { attrs.deviceName: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17: 45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationType: { value: "O", type: "string", md: { TimeInstant: { type: "ISO8601 ", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationName: { value: "Mumbai", type: " string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs .deviceType: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: ["TimeInstant " ],创建日期:1569384878,修改日期:1569385065 },attrs.deviceMa cAddress: { value: "84:24:8D:F8:B2:B2", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878, modDate: 1569385065 }, modDate: 1569385065, lastCorrelator: "6d0aa4fa-df4b-11e9-8293-3464a92017cd" }, $unset: { location: 1, expDate: 1 } }> - exception: OperationException: { index: 0, code: 61, errmsg: "update { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u: { $set: { attrs.deviceName: { v...", op: { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u: { $set: { attrs.deviceName: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationType: { value: "O", t cAddress: { value: "84:24:8D:F8:B2:B2", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z " } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878, modDate: 15693 modDate: 1569385065, lastCorrelator: "6d0aa4fa-df4b-11e9-8293-3464a92017cd" }, $unset: { location: 1, expDate: 1 } }> - 异常:OperationException: { index: 0, code: 61, errmsg: "更新 { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u: { $set: { attrs.deviceName : { v...", op: { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u : { $set: { attrs.deviceName: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationType: { value: "O", t ype: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationName: { value: "Mumbai", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceType: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceMacAddress: { value: "84:24:8D:F8:B2:B2", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878, modDate: 1569385065 }, modDate: 1569385065, lastCorrelator: "6d0aa4fa-df4b-11e9-8293-3464a92017cd" }, $unset: { location: ype: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.locationName: { value: "Mumbai", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceType: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09 -25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 }, attrs.deviceMacAddress: { value: "84:24:8D:F8:B2:B2", 输入: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878, modDate: 1569385065 } , attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878, modDate: 1569385065 }, modDate: 1569385065, lastCorrelator: "6d0aa4fa-df4b-11e9-8293-34a , $61未设置:{位置: 1, expDate: 1 } }, multi: false, upsert: false } } 1, expDate: 1 } }, multi: false, upsert: false } }

I also tried to manually update the document, the log is:我也试过手动更新文档,日志是:

update { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u: { $set: { attrs.deviceName: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.locationType: { value: "O", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.locationName: { value: "Mumbai", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 },attrs.deviceType: { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.deviceMacId: { value: "84:24:8D:F8:B2:B2", type: "string", m更新 { q: { _id.id: "DeviceEntity1", _id.type: "DeviceEntity", _id.servicePath: { $in: [ /^/raw$/ ] } }, u: { $set: { attrs.deviceName : { value: "FR", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ] , 创建日期: 1569384878.0, modDate: 1569385065.0 }, attrs.locationType: { value: "O", type: "string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17: 45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.locationName: { value: "Mumbai", type: "string", md: { TimeInstant: { type: "ISO8601 ", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 },attrs.deviceType: { value: "FR", type: " string", md: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs .deviceMacId: { value: "84:24:8D:F8:B2:B2", type: "string", m d: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878.0, modDate: 1569385065.0 }, modDate: 1569385065.0, lastCorrelator: "6d0aa4fa-df4b-11e9-8293-3464a92017cd" }, $unset: { location: 1.0, expDate: 1.0 } }, multi: false, upsert: false } does not contain _id or shard key for pattern { _id.servicePath: 1.0, _id.id: 1.0, _id.type: 1.0 } d: { TimeInstant: { type: "ISO8601", value: "2019-09-25T04:17:45.645Z" } }, mdNames: [ "TimeInstant" ], creDate: 1569384878.0, modDate: 1569385065.0 }, attrs.TimeInstant: { value: 1569385065.0, type: "ISO8601", mdNames: [], creDate: 1569384878.0, modDate: 1569385065.0 }, modDate: 1569385065.0, lastCorrelator: "6d0aa4fa-df4b-11e9-82793-3464a {location} 1.0, expDate: 1.0 } }, multi: false, upsert: false } 不包含模式 { _id.servicePath: 1.0, _id.id: 1.0, _id.type: 1.0 } 的 _id 或分片键

What MongoDB shard key strategy should i follow, for following composite document id, there may be multiple document for _id.id and _id.servicePath .我应该遵循什么 MongoDB 分片键策略,对于以下复合文档 id, _id.id_id.servicePath可能有多个文档。 I want to distribute data with "_id.id": "DeviceEntity1" and "_id.id": "DeviceEntity2" in two MongoDB shards.我想在两个 MongoDB 分片中使用"_id.id": "DeviceEntity1""_id.id": "DeviceEntity2"分发数据。

    "_id" : {
        "id" : "DeviceEntity1",
        "type" : "DeviceEntity",
        "servicePath" : "/raw"
    },... 

Thank You.谢谢你。

I'm not fully sure (a long time has passed since my last MongoDB sharding set up:) but I'd suggest trying first with a simpler sharding key.我不完全确定(自上次 MongoDB 分片设置以来已经过去了很长时间:)但我建议先尝试使用更简单的分片键。 For instance:例如:

db.shardCollection("orion-fiwareiot.entities", {"_id.id": 1})

and see how it goes.看看情况如何。

With regards to:关于:

I want to distribute data with "_id.id": "DeviceEntity1" and "_id.id": "DeviceEntity2" in two MongoDB shards.我想在两个 MongoDB 分片中使用"_id.id": "DeviceEntity1""_id.id": "DeviceEntity2"分发数据。

Maybe I'm not remembering correctly or it has changed in a recent MongoDB version but, as far as I know, you cannot choose where you particular documents go.也许我记错了,或者它在最近的 MongoDB 版本中发生了变化,但据我所知,您无法选择特定文档 go 的位置。 You set a sharding key and MongoDB sharding system does all the magic to distribute your documents among shards, based on the key range.您设置一个分片键,MongoDB 分片系统会根据键范围在分片之间分配您的文档。 But you cannot ensure that a particular document ends in a particular shard in a given time.但是您无法确保特定文档在给定时间内以特定分片结束。

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

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