How to determine the range of shards for each shard in Mongo?

let's say a document

{ x:Number } 

and I have 3 shards.

Instead of autostart, I can determine that specifically shard1 contains only data x <0, shard2 contains only data 0 = <x = <1000, and shard 3 - 1000

+7
source share
1 answer

You can. You can pre-split the pieces manually, described here: http://www.mongodb.org/display/DOCS/Splitting+Chunks

Think about how you split your pieces. If you do this poorly, you can get many performance problems, but if you know enough about your keys, you can get a lot.

If you do this, you probably want to turn off balancing:

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

(described here: http://www.mongodb.org/display/DOCS/Sharding+Administration )

This is an example of how you can do this. Depending on what you want to do, you will have to modify it (I assume that your debarking key is not called x , for example, and your range is not from -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"}) 

The split commands create chunks. Each command splits a piece containing the average value into two, so the first splits the piece containing min_value -> max_value into min_value -> 0 and 0 -> max_value . Then the second team breaks the piece containing 1000, the second piece created by the previous team into two new pieces. After this command, you have three pieces:

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

The following three commands move these pieces to separate the fragments. The docs say that the command will move the piece containing the value in find , so I selected three values ​​that I know are in different pieces and used them (in BSON there is a character for min_key and max_key , but I don’t know how use it correctly in this context. "

Read this page too http://www.mongodb.org/display/DOCS/Moving+Chunks

+10
source

All Articles