分片不会将数据平衡为两个分片

时间:2013-09-27 10:31:55

标签: mongodb mongoose mongomapper mongo-java

我添加了两个分片如下:

  shards:
        {  "_id" : "rs0",  "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
        {  "_id" : "rs1",  "host" : "rs1/serv3:27017,serv4:27017,serv5:27017" }

我已按以下方式对我的收藏帖子进行了分片:

数据库:

{  "_id" : "mypost",  "partitioned" : true,  "primary" : "rs0" }

             mypost.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    2
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
                        { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)

我的问题是即使我在_id上使用哈希键并插入34MB数据,为什么数据总是仅从分片1中提取,并且没有块被移动到分片2。

当我做的时候

db.posts.find().explain() i get:

{
        "clusteredType" : "ParallelSort",
        "shards" : {
                "rs0/serv1:27017,serv2:27017,serv3:27017" : [
                        {
                                "cursor" : "BasicCursor",
                                "isMultiKey" : false,
                                "n" : 1000,
                                "nscannedObjects" : 1000,
                                "nscanned" : 1000,
                                "nscannedObjectsAllPlans" : 1000,
                                "nscannedAllPlans" : 1000,
                                "scanAndOrder" : false,
                                "indexOnly" : false,
                                "nYields" : 0,
                                "nChunkSkips" : 0,
                                "millis" : 4,
                                "indexBounds" : {

                                },
                                "server" : "serv1:27017"
                        }
                ]
        },
        "cursor" : "BasicCursor",
        "n" : 1000,
        "nChunkSkips" : 0,
        "nYields" : 0,
        "nscanned" : 1000,
        "nscannedAllPlans" : 1000,
        "nscannedObjects" : 1000,
        "nscannedObjectsAllPlans" : 1000,
        "millisShardTotal" : 4,
        "millisShardAvg" : 4,
        "numQueries" : 1,
        "numShards" : 1,
        "indexBounds" : {

        },
        "millis" : 5
}

如何将数据自动发送到两个分片。

sh.status()

  sharding version: {
        "_id" : 1,
        "version" : 3,
        "minCompatibleVersion" : 3,
        "currentVersion" : 4,
        "clusterId" : ObjectId("50fde9a8552b8ce5c47c8ead")
}
  shards:
        {  "_id" : "rs0",  "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
        {  "_id" : "rs1",  "host" : "rs1/serv4:27017,serv5:27017,serv6:27017" }
  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "myposts",  "partitioned" : true,  "primary" : "rs0" }
                myposts.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0)
删除集合后的

状态---------------------

{  "_id" : "myposts",  "partitioned" : true,  "primary" : "rs0" }
                myposts.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    2
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
                        { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)

1 个答案:

答案 0 :(得分:0)

如果您查看Sharding Mechanics文档(如果您是mongodb 2.2或更高版本),您会发现,对于少于20个块,您需要有2个不平衡为了平衡器移动块。

我不希望你有任何块的平衡,直到你有至少4个块。

有没有理由为什么你定义了这么少的块,或者你是否要等待足够的数据来进行平衡器切片和切块?