我的MongoDB遇到了一些麻烦。这是我的配置:
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" : ObjectId("546f2d9c37d2895f3b8f9ec1")
}
shards:
{ "_id" : "site_A_shard_1", "host" : "site_A_shard_1/<HOST1>:27510,<HOST2>:27511", "tags" : [ "site_A" ] }
{ "_id" : "site_A_shard_2", "host" : "site_A_shard_2/<HOST2>:27521,<HOST1>:27520", "tags" : [ "site_A" ] }
{ "_id" : "site_B_shard_1", "host" : "site_B_shard_1/<HOST3>:27510,<HOST4>:27511", "tags" : [ "site_B" ] }
{ "_id" : "site_B_shard_2", "host" : "site_B_shard_2/<HOST4>:27521,<HOST3>:27520", "tags" : [ "site_B" ] }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : false, "primary" : "site_B_shard_1" }
{ "_id" : "ocs", "partitioned" : true, "primary" : "site_B_shard_1" }
ocs.adrs_queue
shard key: { "shard.target" : 1, "shard.key" : 1 }
{ "shard.target" : { "$minKey" : 1 }, "shard.key" : { "$minKey" : 1 } } -->> { "shard.target" : { "$maxKey" : 1 }, "shard.key" : { "$maxKey" : 1 } } on : site_B_shard_1 Timestamp(1, 0)
tag: site_A { "shard" : { "target" : "siteA", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteA", "key" : { "$maxKey" : 1 } } }
tag: site_B { "shard" : { "target" : "siteB", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteB", "key" : { "$maxKey" : 1 } } }
ocs.ldrs
shard key: { "shard.target" : 1, "shard.key" : 1 }
{ "shard.target" : { "$minKey" : 1 }, "shard.key" : { "$minKey" : 1 } } -->> { "shard.target" : { "$maxKey" : 1 }, "shard.key" : { "$maxKey" : 1 } } on : site_B_shard_1 Timestamp(1, 0)
tag: site_A { "shard" : { "target" : "siteA", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteA", "key" : { "$maxKey" : 1 } } }
tag: site_B { "shard" : { "target" : "siteB", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteB", "key" : { "$maxKey" : 1 } } }
ocs.notifs_queue
shard key: { "shard.target" : 1, "shard.key" : 1 }
{ "shard.target" : { "$minKey" : 1 }, "shard.key" : { "$minKey" : 1 } } -->> { "shard.target" : { "$maxKey" : 1 }, "shard.key" : { "$maxKey" : 1 } } on : site_B_shard_1 Timestamp(1, 0)
tag: site_A { "shard" : { "target" : "siteA", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteA", "key" : { "$maxKey" : 1 } } }
tag: site_B { "shard" : { "target" : "siteB", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteB", "key" : { "$maxKey" : 1 } } }
ocs.ss_queue
shard key: { "shard.target" : 1, "shard.key" : 1 }
{ "shard.target" : { "$minKey" : 1 }, "shard.key" : { "$minKey" : 1 } } -->> { "shard.target" : { "$maxKey" : 1 }, "shard.key" : { "$maxKey" : 1 } } on : site_B_shard_1 Timestamp(1, 0)
tag: site_A { "shard" : { "target" : "siteA", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteA", "key" : { "$maxKey" : 1 } } }
tag: site_B { "shard" : { "target" : "siteB", "key" : { "$minKey" : 1 } } } -->> { "shard" : { "target" : "siteB", "key" : { "$maxKey" : 1 } } }
尽管配置了标签范围,但它似乎不起作用。每次我尝试插入一些信息时,它都会存储在同一个分片(site_B_shard_1)中,即使关联的标记是site_A。
我做错了什么?
答案 0 :(得分:1)
您似乎尝试在两个分片中分发单个集合,但定义了重叠shard tag ranges,其中site_A
和site_B
包含shard.target
项的全部范围值(minkey .. maxkey
):
tag: site_A {
"shard" : {
"target" : "siteA",
"key" : { "$minKey" : 1 }
}
} -->> {
"shard" : {
"target" : "siteA",
"key" : { "$maxKey" : 1 }
}
}
tag: site_B {
"shard" : {
"target" : "siteB",
"key" : { "$minKey" : 1 }
}
} -->> {
"shard" : {
"target" : "siteB",
"key" : { "$maxKey" : 1 }
}
}
如果要使用标记感知分片在集合中分发数据,则需要定义下限包含的范围,上限是独占的,例如:
sh.addTagRange(&#39; ocs.adrs_queue&#39; {&#34; shard.target&#34;:MinKey},{&#34; shard.target&#34;:&#34;&Site_A的#34;},&#39; Site_A的&#39;) sh.addTagRange(&#39; ocs.adrs_queue&#39; {&#34; shard.target&#34;:&#34; Site_A的&#34;},{&#34; shard.target&#34;:& #34; site_B&#34;},&#39; Site_A的&#39;) sh.addTagRange(&#39; ocs.adrs_queue&#39; {&#34; shard.target&#34;:&#34; site_B&#34;},{&#34; shard.target&#34;:MaxKey },&#39; site_B&#39)
在此设置中:
shard.target
值匹配site_A
和site_B
的文档应分发到匹配的分片shard.target
值小于site_A
的文档也将在site_A
分片上分发shard.target
值大于site_B
的文档将在site_B
分片上分发有关标记感知分片和多数据中心部署的更多示例,请参阅: