MongoDB平衡器不会自动重新分发文档

时间:2014-07-12 22:00:10

标签: mongodb

我刚刚在文档中添加了一个新的replicaset分片并在我的数据库上激活了分片,但似乎数据没有在两个分片中重新分配。 我有了2个分片后运行了以下命令:

sh.enableSharding("app")
sh.shardCollection("app.rooms", { _id: 1 })
sh.shardCollection("app.messages", { r: 1 })

这是我的分片状态:

mongos> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "version" : 4,
    "minCompatibleVersion" : 4,
    "currentVersion" : 5,
    "clusterId" : ObjectId("5374d041208075ddc590b642")
}
  shards:
    {  "_id" : "shard1",  "host" : "shard1/ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017,ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017,ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017" }
    {  "_id" : "shard2",  "host" : "shard2/ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017,ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017,ec2-XXX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:27017" }
  databases:
    {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
    {  "_id" : "app",  "partitioned" : true,  "primary" : "shard1" }
        app.messages
            shard key: { "r" : 1 }
            chunks:
                shard1  2018
            too many chunks to print, use verbose if you want to force print
        app.rooms
            shard key: { "_id" : 1 }
            chunks:
                shard1  3
            { "_id" : { "$minKey" : 1 } } -->> { "_id" : "PIn7KMxI" } on : shard1 Timestamp(1, 0)
            { "_id" : "PIn7KMxI" } -->> { "_id" : "pb7eAsMG" } on : shard1 Timestamp(1, 1)
            { "_id" : "pb7eAsMG" } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 2)
    {  "_id" : "test",  "partitioned" : false,  "primary" : "shard1" }

详细版本可在此处找到:http://pastebin.com/ipz7pqPB

所以看起来所有块都只映射到第一个分片。这看起来很不错,因为目前所有数据都在shard1中。

现在,我希望mongodb将一半的块从shard1迁移到shard2,就像它应该自动写成in the docs一样。

这应该是平衡器的角色,它根据此命令的结果运行:

mongos> sh.getBalancerState()
true

我有点卡在这里,因为文档没有进一步解释平衡器如何工作。

1 个答案:

答案 0 :(得分:0)

好的,这里的问题是我的服务器时钟没有同步。 我在所有主机上安装了ntp并解决了问题!