Database Reference
In-Depth Information
value of EU to be sent to the tag EU, we need to have a range from EU to EV. And for US we want a range from US to UT.
This gives us the following commands:
> sh.addTagRange("testdb.testtagsharding", {region:"EU"}, {region:"EV"}, "EU")
> sh.addTagRange("testdb.testtagsharding", {region:"US"}, {region:"UT"}, "US")
From now on any documents that match these criteria will be sent to those shards. So let's introduce a few
documents in order to test things. I've written a short loop to introduce 10,000 documents that match our shard key
into the cluster.
for(i=0;i<10000;i++){db.getSiblingDB("testdb").testtagsharding.insert({region:"EU",testkey:i})}
Now we run sh.status() and can see the shard chunking breakdown:
testdb.testtagsharding
shard key: { "region" : 1, "testkey" : 1 }
chunks:
shard0000 3
{ "region" : { "$minKey" : 1 }, "testkey" : { "$minKey" : 1 } } -->> { "region" :
"EU", "testkey" : { "$minKey" : 1 } } on : shard0000 Timestamp(1, 3)
{ "region" : "EU", "testkey" : { "$minKey" : 1 } } -->> { "region" : "EU", "testkey"
: 0 } on : shard0000 Timestamp(1, 4)
{ "region" : "EU", "testkey" : 0 } -->> { "region" : { "$maxKey" : 1 }, "testkey" :
{ "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2)
tag: EU { "region" : "EU" } -->> { "region" : "EV" }
tag: US { "region" : "US" } -->> { "region" : "UT" }
From this we can see the breakdown of which chunks are where; there are three chunks on the EU shard and
none on the US shard. From the ranges we can see that two of those chunks should be empty. If you go onto each of
the individual shard servers, you will find that all of the 10,000 documents we inserted are on only one shard. You may
have noticed the following message in your logfile:
Sun Jun 30 12:11:16.549 [Balancer] chunk { _id: "testdb.testtagsharding-region_"EU"testkey_MinKey",
lastmod: Timestamp 1000|2, lastmodEpoch: ObjectId('51cf7c240a2cd2040f766e38'), ns: "testdb.
testtagsharding", min: { region: "EU", testkey: MinKey }, max: { region: MaxKey, testkey: MaxKey },
shard: "shard0000" } is not on a shard with the right tag: EU
Sun Jun 30 12:11:16.549 [Balancer] going to move to: shard0001
This message appears because we have set up our tag ranges to work only on the EU and US values. We can
rework them slightly, given what we now know, to cover all tag ranges. Let's remove those tag ranges and add new
ranges; we can remove the old documents with the following commands:
> use config
> db.tags.remove({ns:"testdb.testtagsharding"});
Now we can add the tags back, but this time we can run from minKey to US and from US to maxKey , just like the
chunk ranges in the previous example! To do this, use the special MinKey and MaxKey operators, which represent the
least and the greatest possible values for the shard key range.
> sh.addTagRange("testdb.testtagsharding", {region:MinKey}, {region:"US"}, "EU")
> sh.addTagRange("testdb.testtagsharding", {region:"US"}, {region:MaxKey}, "US")
Search WWH ::




Custom Search