【问题标题】:Enable MongoDB sharding for FIWARE Orion ContextBroker为 FIWARE Orion ContextBroker 启用 MongoDB 分片
【发布时间】:2019-09-24 11:34:30
【问题描述】:

我正在尝试为 Orion ContextBroker 和 IotAgent-Json 设置 MongoDB 分片,我能够在分片之间分配 MongoDb 中的设备配置和服务数据,但是每当我发送实际设备数据时,它都会给出以下错误:

{ "name": "ENTITY_GENERIC_ERROR", "message": "访问设备实体数据时出错:DeviceEntity1 of type: DeviceEntity1"}

我正在使用以下命令对集合进行分片:
sh.shardCollection("orion-fiwareiot.entities",{"_id.servicePath": 1, "_id.id": 1, "_id.type": 1})

截取 ContextBroker 日志:

时间=2019.729Z 9 月 25 日星期三 06:54:22 | lvl=错误 | corr=4e22de66-df61-11e9-aa53-3464a92017cd |反式=1569393389-597-00000000007 |从=127.0.0.1 | srv=fiwareiot | subsrv=/原始 | comp=猎户座 | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: collection: orion-fiwareiot.entities - update(): - 异常: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", 输入: "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 } }

我也试过手动更新文档,日志是:

更新 { 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”,值:“2019-09-25T04:17:45.645Z”}},mdNames:[“TimeInstant”],creDate:1569384878.0,modDate:1569385065.0},attrs.deviceType:{值:“FR”,类型:“字符串”,md:{ TimeInstant:{类型:“ISO8601”,值:“2019-09-25T04:17:45.645Z”}},mdNames:[“TimeInstant”],creDate:1569384878.0,modDate:1569385065.0 },attrs.deviceMacId:{值:“84:24:8D:F8:B2:B2”,类型:“字符串” , md: { 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-346a" location { : 1.0, expDate: 1.0 } }, multi: false, upsert: false } 不包含模式 { _id.servicePath: 1.0, _id.id: 1.0, _id.type: 1.0 }

的 _id 或分片键

对于遵循复合文档 ID,我应该遵循什么 MongoDB 分片键策略, _id.id_id.servicePath 可能有多个文档。 我想用"_id.id": "DeviceEntity1""_id.id": "DeviceEntity2"在两个MongoDB 分片中分发数据。

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

谢谢。

【问题讨论】:

  • 使用 MongoDB 实例而不是 MongoDB 分片的相同设置是否可以正常工作?
  • @fgalan,使用单个 MongoDB 实例可以正常工作。即使所有 Orion 数据都驻留在同一个分片中,而 IotAgent-json 数据位于其他分片上,它也能正常工作。我想在分片中分发 contextBroker 更新操作。
  • 您为 Context Broker 显示的日志消息是否完整?好像是在_id.servicePath:之后才剪掉的...
  • @fgalan,我已经更新了 Orion contextBroker 错误日志。

标签: mongodb fiware fiware-orion


【解决方案1】:

我不完全确定(自我上次设置 MongoDB 分片以来已经过去了很长时间 :) 但我建议先尝试使用更简单的分片键。例如:

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

看看进展如何。

关于:

我想用 "_id.id": "DeviceEntity1""_id.id": "DeviceEntity2" 在两个 MongoDB 分片中分发数据。

也许我记错了,或者它在最近的 MongoDB 版本中发生了变化,但据我所知,您无法选择特定文档的去向。您设置一个分片键,MongoDB 分片系统会根据键范围在分片之间分配您的文档。但是您无法确保特定文档在给定时间内以特定分片结束。

【讨论】:

    猜你喜欢
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多