Over the past two years, our blog has elaborated on fragmented work clusters and build processes. In this blog, we mainly analyze test results in a fragmented cluster.
First, take a look at each state of the fragmented cluster. As you can see, copying sets a and B are normal:
First, open the Shard collection
Open a shard on a database. This is a prerequisite for sharding regardless of the collection. If the test database is slidetest.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc3himdg0mtkwmtexng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/center ">
Shard Collection Definition Note: It looks somewhat similar to the index definition, especially with that unique key.
When sharding an empty collection. MongoDB an index corresponding to the Shard is created on each shard.
Can directly connect the Shard. Execute getindexs () to verify. Be able to log in to view.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc3himdg0mtkwmtexng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/center ">
Second, write to the Shard cluster
Once the collection of shards is complete, the Shard cluster is ready. It is now possible to write data to the cluster. The data is distributed across the shards.
initialize the data on 4000 :
for (var i = 0; i < i++) {Db.spreadsheets.insert ({"filename": "sheet-" +i, "updatedate": New Date (), "username": " Albertshao "," Data ":" ABCDE "*1000})}
View results:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc3himdg0mtkwmtexng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/center ">
Next we examine what happened to the whole block and see that there are two pieces. And their maximum value is not the same.
Note: As a boundary of type Bson. $minKey and $maxkey are often used in comparative operations.
$minkey always light rain all bson types. $maxkey is always larger than all bson types.
。
MongoDB uses these two types to compare the endpoints of the block
Continue inserting data, if you insert 200,000 records,
mongos> sh.status ()---sharding status---sharding version: {"_id": 1, "Version": 4, "Mincomp Atibleversion ": 4," CurrentVersion ": 5," Clusterid ": ObjectId (" 545D9AF5340AEC0C2272AFDA ")} Shards: {"_id": "Shard-a", "host": "Shard-a/win--20141018ko:3000,win--20141018ko:3001"} {"_id": "Shard-b", "host": "Shard-b/win--20141018ko:30100,win--20141018ko:30101"} databases: {"_id": "ADM In "," partitioned ": false," PRIMARY ":" config "} {" _id ":" Slidetest "," partitioned ": true," PRIMARY ":" s Hard-a "} Slidetest.spreadsheets Shard key: {" username ": 1," _id ": 1} Chunks:shard-b 1 shard-a 2 {"username": {"$minKey": 1}, "_id": {"$minKey": 1}}-->> {"username": "Albertshao", "_id": ObjectId ("545df80537216b1577de0251")} On:shard-b TimestaMP (2, 0) {"username": "Albertshao", "_id": ObjectId ("545df80537216b1577de0251")}-->> {" Username ":" Albertshao "," _id ": ObjectId (" 545e062437216b1577de1802 ")} on:shard-a Timestamp (2, 2) {"username": "Albertshao", "_id": ObjectId ("545e062437216b1577de1802")}-->> {"username": {"$maxKey": 1} , "_id": {"$maxKey": 1}} on:shard-a Timestamp (2, 3) mongos>
Through the above can be seen out. is to use Usename as a block partition key.
At the same time can also see that there are always 3 pieces. There were two shard-a, and Shard-b had a piece.
We can see the migration of the database through Changelog:
Mongos> Db.changelog.count ({What: "Split"}) is 2mongos> Db.changelog.count ({What: "Movechunk.commit"}). Count () 2014-11-08t20:12:09.618+0800 Typeerror:object 1 have no method ' count ' mongos> db.changelog.find ({what: " Movechunk.commit "}). Count () 1mongos> Db.changelog.find ({What:" Movechunk.commit "}) {" _id ":" WIN--20141018KO-2014-11-08T11:01:40-545DF8141603DFC967D0FDCD "," Server ":" Win--20141018ko "," clientAddr ":" 127.0.0.1:50644 "," Time ": Isodate (" 2014-11-08t11:01:40.826z ")," what ":" Movechunk.commit "," ns ":" Slidetest.spreadsheets "," Details ": {" min ": {" username ": {" $minKey ": 1}," _id ": {" $minKey ": 1}}," Max ": {" U Sername ":" Albertshao "," _id ": ObjectId (" 545df80537216b1577de0251 ")}," from ":" Shard-a "," to ":" Shard-b "," cloned ": Numberlong (0), "clonedbytes": Numberlong (0), "catchup": Numberlong (0), "steady": Numberlong (0)}}mongos>
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
"MongoDB" in the Windows platform MongoDB slicing cluster (iii)