Database Reference
In-Depth Information
This is in line with these assumptions. A total of 20 splits have occurred, yielding 20
chunks, but only 6 migrates have taken place. For an extra-deep look at what's going
on here, you can scan the change log entries. For instance, here's the entry recording
the first chunk move:
> db.changelog.findOne({what: "moveChunk.commit"})
{
"_id" : "arete-2011-09-01T20:40:59-2",
"server" : "arete",
"clientAddr" : "127.0.0.1:55749",
"time" : ISODate("2011-03-01T20:40:59.035Z"),
"what" : "moveChunk.commit",
"ns" : "cloud-docs.spreadsheets",
"details" : {
"min" : {
"username" : { $minKey : 1 },
"_id" : { $minKey : 1 }
},
"max" : {
"username" : "Abbott",
"_id" : ObjectId("4d6d57f61d41c851ee000092")
},
"from" : "shard-a",
"to" : "shard-b"
}
}
Here you see the movement of chunks from shard-a to shard-b . In general, the doc-
uments you find in the change log are quite readable. As you learn more about shard-
ing and begin prototyping your own shard clusters, the config change log makes an
excellent live reference on split and migrate behavior. Refer to it often.
9.3
Querying and indexing a shard cluster
From the application's perspective, there's no difference between querying a sharded
cluster and querying a single mongod . In both cases, the query interface and the pro-
cess of iterating over the result set are the same. But behind the scenes, things are dif-
ferent, and it's worthwhile to understand exactly what's going on.
9.3.1
Shard query types
Imagine you're querying a shard cluster. How many shards does mongos need to con-
tact to return a proper query response? If you give it some thought, you'll see that it
depends on whether the shard key is present in the query selector. Remember that the
config servers (and thus mongos ) maintain a mapping of ranges to shards. These map-
pings are none other than the chunks that we examined earlier in the chapter. If a
query includes the shard key, then mongos can quickly consult the chunk data to deter-
mine exactly which shard contains the query's result set. This is called a targeted query .
But if the shard key isn't part of the query, the query planner will have to visit all
shards to fulfill the query completely. This is known as a global or scatter/gather query .
The diagram in figure 9.3 illustrates both query types.
Search WWH ::




Custom Search