具有标记感知分片的Mongodb复合分片键

时间:2016-02-18 15:20:59

标签: mongodb

具有标记感知分片的Mongodb复合分片键。

环境

  • 我有一个包含4个分片的mongodb群集。
  • 前两个分片的国家/地区代码为Americas,最后两个分片的标记为Europe
  • 分片键在字段country, user, domain上是复合的。

问题

我正在尝试根据国家/地区设置标记感知分片,因此任何包含country: 1的文档都会在前两个分片之间自动分片,而country: 2的任何文档都会自动分片到最后一个2个碎片。

Sample Data:`
"_id" : ObjectId("56c4cc2fb086de4769800fe4"), "timestamp" : ISODate("1970-01-01T00:00:00Z"), "user" : "guest", "category" : "Google", "domain" : "google.com", "source" : 1.1.1.1, "destination" : 2.2.2.2, "country" : 1, "__v" : 0`
"_id" : ObjectId("56c4cc2fb086de4769800fe4"), "timestamp" : ISODate("1970-01-01T00:00:00Z"), "user" : "guest2", "category" : "Bing", "domain" : "bing.com", "source" : 2.2.2.2, "destination" : 3.3.3.3, "country" : 2, "__v" : 0`

config.tags:
"_id" : { "ns" : "logs.sitea", "min" : { "country" : "1" } }, "ns" : "logs.sitea", "min" : { "country" : "1" }, "max" : { "country" : "2" }, "tag" : "Americas"`
"_id" : { "ns" : "logs.siteb", "min" : { "country" : "2" } }, "ns" : "logs.siteb", "min" : { "country" : "2" }, "max" : { "country" : "3" }, "tag" : "Europe"`

config.shards:
"_id" : "shard0000", "host" : "1.1.1.1:27019", "tags" : [ "Americas" ]`
"_id" : "shard0001", "host" : "1.1.1.2:27019", "tags" : [ "Americas" ]`
"_id" : "shard0002", "host" : "2.2.2.2:27019", "tags" : [ "Europe" ]`
"_id" : "shard0003", "host" : "2.2.2.3:27019", "tags" : [ "Europe" ]`

sh.status:
"_id" : "logs",  "primary" : "shard0002",  "partitioned" : true`
            logs.sitea`
                    shard key: { "country" : 1, "user" : 1, "domain" : 1 }
                    unique: false`
                    balancing: true`
                    chunks:`
                    tag: Americas  { "country" : "1" } -->> { "country" : "2"`

"_id" : "logs",  "primary" : "shard0002",  "partitioned" : true }`
            logs.siteb`
                    shard key: { "country" : 1, "user" : 1, "domain" : 1 
                    unique: false`
                    balancing: true`
                    chunks:`
                    tag: Europe  { "country" : "2" } -->> { "country" : "3" }

1 个答案:

答案 0 :(得分:0)

我的问题是国家/地区代码的双引号。

将标记更新为此解决了我的问题: " _id" :{" ns" :" logs.sitea"," min" :{" country" :1}}," ns" :" logs.sitea"," min" :{" country" :1}," max" :{" country" :2}," tag" :"美洲"`