2014-11-24 100 views
0

我在MongoDB中遇到了一些麻煩。這是我的配置: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_A,它也會存儲在同一個分片(site_B_shard_1)中。

我在做什麼錯?

回答

1

它看起來像你正試圖在兩個碎片分配單個集合,但已經定義了重疊shard tag ranges其中site_Asite_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.add TagRange('ocs.adrs_queue',{「shard.target」:MinKey},{「shard.target」:「site_A」},'site_A') sh.addTagRange('ocs.adrs_queue',{「shard.target 「:」site_A「},{」shard.target「:」site_B「},'site_A' sh.addTagRange('ocs.adrs_queue',{」shard.target「:」site_B「},{」shard。目標「:MaxKey}, 'site_B')

在這種設置:

  • 文檔與shard.target值進行匹配site_Asite_B和應分配給匹配碎片
  • 文檔與比site_A少10個值也將在site_A碎片分佈
  • 文件比site_B更大shard.target值將在site_B碎片

對於標籤感知分片和多數據中心部署的一些例子分佈看: