如何在Mongo中为每个分片定义分片范围? [英] How to define sharding range for each shard in Mongo?

查看:76
本文介绍了如何在Mongo中为每个分片定义分片范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,文件是

{
  x:Number
}

我有3个碎片.

除了自动分片,我可以具体定义shard1仅包含数据x <0,shard2仅包含数据0 =< x = < 1000,而分片3为1000

Instead of autosharding, can I define specifically shard1 only contains data x<0, shard2 only contains data 0 =< x =< 1000 , and shard 3 is 1000

推荐答案

可以.可以手动预分割块,在此处进行了描述: http://www.mongodb. org/display/DOCS/Splitting + Chunks

You can. It's possible to pre-split chunks manually, it's described here: http://www.mongodb.org/display/DOCS/Splitting+Chunks

请仔细考虑如何拆分块.如果操作不当,可能会遇到很多性能问题,但是,如果您对密钥的了解足够多,则可以收获很多.

Think carefully about how you split your chunks. If you do it badly you can get lots of performance problems, but if you know enough about your keys you can gain a lot.

如果这样做,可能要关闭平衡器:

If you do it you probably want to turn off the balancer:

> use config
> db.settings.update({_id: "balancer"}, {$set: {stopped: true}}, true);

(在此进行描述: http://www.mongodb.org/display/DOCS/共享+管理)

这是如何执行此操作的示例.根据您要执行的操作,您必须对其进行修改(例如,假设您的分片键未命名为x,并且范围不是-1000至2000).

This is an example of how you might do it. Depending on exactly what you want to do you will have to modify it (I assume your shard key is not named x, for example, and your range isn't -1000 to 2000).

> use admin
> db.runCommand({split: "my_db.my_coll", middle: {x: 0}})
> db.runCommand({split: "my_db.my_coll", middle: {x: 1000}})
> db.runCommand({movechunk: "my_db.my_coll", find: {x:   -1}, to: "shard_1_name"})
> db.runCommand({movechunk: "my_db.my_coll", find: {x:    0}, to: "shard_2_name"})
> db.runCommand({movechunk: "my_db.my_coll", find: {x: 1000}, to: "shard_3_name"})

split命令创建块.每个命令将包含中间值的块拆分为两个,因此第一个命令将包含min_value -> max_value的块拆分为min_value -> 00 -> max_value.然后,第二个命令将包含上一个命令的第二个块(即1000)拆分为两个新块.执行该命令后,您将获得三个大块:

The split commands create the chunks. Each command splits the chunk containing the middle value into two, so the first splits the chunk containing min_value -> max_value into min_value -> 0 and 0 -> max_value. Then the second command splits the chunk containing 1000, the second chunk created by the previous command, into two new chunks. After that command you have three chunks:

  • min_value -> 0
  • 0 -> 1000
  • 1000 -> max_value
  • min_value -> 0
  • 0 -> 1000
  • 1000 -> max_value

以下三个命令将这些块移动到单独的分片中.文档说该命令将移动包含find中值的块,因此我选择了三个我知道分别位于不同块中的值并使用了这些值(BSON中有一个符号用于min_keymax_key,但是我我不确定在这种情况下如何正确使用它.

The three following commands moves these chunks to separate shards. The docs say that the command will move the chunk containing the value in find, so I picked three values I know are in different chunks and used these (there is a symbol in BSON for min_key and max_key, but I'm not sure how to use it properly in this context).

也请阅读此页面 http://www.mongodb.org/display/DOCS/Moving + Chunks

这篇关于如何在Mongo中为每个分片定义分片范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆