[MongoDB] mongodb sharding cluster on windows platform (3)

Source: Internet
Author: User
Tags mongodb sharding
In the previous two blogs, we elaborated on the working principle and building process of the sharded cluster. In this blog, we mainly analyze the testing results of the sharded cluster. First, we can see that the replica Set A and B are normal: 1. Enable the sharding set to enable the sharding of a database. This is a prerequisite for sharding of any set.

In the previous two blogs, we elaborated on the working principle and building process of the sharded cluster. In this blog, we mainly analyze the testing results of the sharded cluster. First, we can see that the replica Set A and B are normal: 1. Enable the sharding set to enable the sharding of a database. This is a prerequisite for sharding of any set.

In the previous two blogs, we elaborated on the working principle and building process of the sharded cluster. In this blog, we will analyze the testing results of the sharded cluster;

First, check the status of the sharded cluster. We can see that replica set A and replica Set B are normal:

1. Enable the sharding set

Enable sharding for a database. This is a prerequisite for sharding for any set. Assume that the test database is slidetest.

Note: It looks a bit similar to the index definition, especially the unique key. When sharding is performed for an empty set, mongodb creates an index for each shard. You can directly link the parts and run getIndexs () for verification. You can log on to 3000 to view the information.

Ii. Write to sharded Cluster

Once the sharding of the set is completed, the sharding cluster is ready. You can now write data to the cluster, which is distributed to each shard.

Initialize data on 4000:

For (var I = 0; I <200; I ++) {db. spreadsheets. insert ({"filename": "sheet-" + I, "updatedate": new Date (), "username": "Alberta shao", "data ": "abcde" * 1000 })}

View results:

Next we will check what happened to the entire block. We can see that there are two blocks, and their maximum values are different.

Note: $ minKey and $ maxkey are commonly used in comparison operations as BSON boundary. $ Minkey is always light rain on all BSON types, while $ maxKey is always larger than all BSON types .. MongoDB uses these two types to compare the block endpoints

Insert data. Assume that 0.2 million records are inserted,

mongos> sh.status()--- Sharding Status ---  sharding version: {        "_id" : 1,        "version" : 4,        "minCompatibleVersion" : 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" : "admin",  "partitioned" : false,  "primary" : "config" }        {  "_id" : "slidetest",  "partitioned" : true,  "primary" : "shard-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>
As shown above, usename is used as the block partitioning key. At the same time, it can be seen that there are three blocks above, of which shard-a has two blocks and shard-B has one.

We can see the database migration through changelog:

mongos> db.changelog.count({what:"split"})2mongos> db.changelog.count({what:"moveChunk.commit"}).count()2014-11-08T20:12:09.618+0800 TypeError: Object 1 has 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" : { "username" : "albertshao", "_id" : ObjectId("545df80537216b1577de0251") }, "from" : "shard-a", "to" : "shard-b", "cloned" : NumberLong(0), "clonedBytes" : NumberLong(0), "catchup" : NumberLong(0), "steady" : NumberLong(0) } }mongos>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.