【问题标题】:MongoDB shard collecton in primary shard only仅在主分片中的 MongoDB 分片集合
【发布时间】:2021-07-26 10:41:14
【问题描述】:

我正在尝试在具有三个分片服务器的分片集群中对集合(db:mql,集合名称:teste)进行分片,但是,包含我的数据的唯一分片是主分片。

--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("60907ccc078cdbdf9b66c6d0")
  }
  shards:
        {  "_id" : "sh1",  "host" : "sh1/localhost:27022",  "state" : 1,  "tags" : [ "NYC", "SF" ] }
        {  "_id" : "sh2",  "host" : "sh2/localhost:27023",  "state" : 1 }
        {  "_id" : "sh3",  "host" : "sh3/localhost:27026",  "state" : 1 }
  active mongoses:
        "4.2.13" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                853 : Success
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                sh1     341
                                sh2     342
                                sh3     341
                        too many chunks to print, use verbose if you want to force print
        {  "_id" : "mql",  "primary" : "sh3",  "partitioned" : true,  "version" : {  "uuid" : UUID("c2c07a45-b8a7-4468-a3ef-cd5bafd8999c"),  "lastMod" : 1 } }
                mql.teste
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                sh3     1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : sh3 Timestamp(1, 0)

这是我检查集合是否分片时得到的结果:

mongos> db.collections.find( {_id: "mql.teste" , dropped : false } )
{ 
  "_id" : "mql.teste", 
  "lastmodEpoch" : ObjectId("6090c18062e39651b4cd267c"), 
  "lastmod" : ISODate("1970-02-19T17:02:47.296Z"), 
  "dropped" : false, 
  "key" : { "_id" : 1 }, 
  "unique" : false, 
  "uuid" : UUID("91d1fdd2-5062-404b-b2ec-28a1f6e15b3e") 
}

【问题讨论】:

    标签: mongodb nosql scalability sharding


    【解决方案1】:

    mongodb 分片集群平衡器尝试在每个分片上放置相同数量的块。

    该集合只有 1 个块,因此不能在分片之间划分。

    块的默认最大大小为 64MB。

    根据 MongoDB 的版本,当 mongos 或 mongod 意识到最大块大小的很大一部分已写入块时,它会调用拆分。

    或者您可以使用sh.splitAt 手动拆分块。

    您还可以运行db.getSiblingDB("mql").teste.getShardDistribution() 以获取有关每个分片上文档/块的数量和大小的信息。

    【讨论】:

      【解决方案2】:

      数据库没有分片,错过了"distributionMode" : "sharded" 检查与

      db.databases.find( {_id: "mql"}, {partitioned: 1} )
      

      您必须在数据库和集合级别启用分片:

      sh.enableSharding("mql")
      sh.shardCollection("mql.teste", { _id : 1 })
      

      注意,使用_id作为shardkey不是很聪明,最好使用{ _id: "hashed" },见Choosing a Shard Key

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-31
        • 2018-12-15
        • 1970-01-01
        • 1970-01-01
        • 2021-08-21
        • 2021-07-14
        • 2012-05-10
        • 1970-01-01
        相关资源
        最近更新 更多