Database Reference
In-Depth Information
Having inserted this much data, you'll definitely have more than one chunk. You can
check the chunk state quickly by counting the number of documents in the chunks
collection:
> use config
> db.chunks.count()
10
You can see more detailed information by running sh.status() . This method prints
all of the chunks along with their ranges. For brevity, I'll only show the first two
chunks:
> sh.status()
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id": "shard-a", "host": "shard-a/arete:30000,arete:30001" }
{ "_id": "shard-b", "host": "shard-b/arete:30100,arete:30101" }
databases:
{ "_id": "admin", "partitioned": false, "primary": "config" }
{ "_id": "test", "partitioned": false, "primary": "shard-a" }
{ "_id": "cloud-docs", "partitioned": true, "primary": "shard-b" }
shard-a 5
shard-b 5
{ "username": { $minKey : 1 }, "_id" : { $minKey : 1 } } --
>> { "username": "Abdul",
"_id": ObjectId("4e89ffe7238d3be9f0000012") }
on: shard-a { "t" : 2000, "i" : 0 }
{ "username" : "Abdul",
"_id" : ObjectId("4e89ffe7238d3be9f0000012") } -->> {
"username" : "Buettner",
"_id" : ObjectId("4e8a00a0238d3be9f0002e98") }
on : shard-a { "t" : 3000, "i" : 0 }
The picture has definitely changed. You now have 10 chunks. Naturally, each chunk
represents a contiguous range of data. You can see that the first chunk with data is
composed of documents from $minKey to Abdul and that the second chunk runs from
Abdul to Buettner. 10 But not only do you have more chunks—the chunks have
migrated to the second shard. You could visually scan the sh.status() output to see
this, but there's an easier way:
> db.chunks.count({"shard": "shard-a"})
5
> db.chunks.count({"shard": "shard-b"})
5
As long as the cluster's data size is small, the splitting algorithm dictates that splits hap-
pen often. That's what you see now. This gives you a good distribution of data and
chunks early on. From now on, as long as writes remain evenly distributed across the
existing chunk ranges, few migrates will occur.
10
If you're following along, note that your chunk distributions may differ somewhat.
Search WWH ::




Custom Search