Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Verify Sharding?

I am trying to shard MongoDB. I am done with Sharding configuration, but I am not sure how to verify if sharding is functional.

How do i check whether my data is get sharded? Is there a query to verify/validate the shards?

like image 349
SampathKumar Avatar asked Jan 06 '11 07:01

SampathKumar


People also ask

How can I check my sharding status?

(1, 2) The sharded collection section, by default, displays the chunk information if the total number of chunks is less than 20. To display the information when you have 20 or more chunks, call the sh. status() methods with the verbose parameter set to true , i.e. sh. status(true) .

What is true sharding?

Sharding is a method for distributing a single dataset across multiple databases, which can then be stored on multiple machines. This allows for larger datasets to be split into smaller chunks and stored in multiple data nodes, increasing the total storage capacity of the system.

What is the process of sharding?

Sharding involves splitting and distributing one logical data set across multiple databases that share nothing and can be deployed across multiple servers. To achieve sharding, the rows or columns of a larger database table are split into multiple smaller tables.


2 Answers

You can also execute a simple command on your mongos router :

> use admin
> db.printShardingStatus();

which should output informations about your shards, your sharded dbs and your sharded collection as mentioned in the mongodb documentation

sharding version: { "_id" : 1, "version" : 2 }
  shards:
      { "_id" : ObjectId("4bd9ae3e0a2e26420e556876"), "host" : "localhost:30001" }
      { "_id" : ObjectId("4bd9ae420a2e26420e556877"), "host" : "localhost:30002" }
      { "_id" : ObjectId("4bd9ae460a2e26420e556878"), "host" : "localhost:30003" }

  databases:
    { "name" : "admin", "partitioned" : false,
          "primary" : "localhost:20001",
          "_id" : ObjectId("4bd9add2c0302e394c6844b6") }
    my chunks

        { "name" : "foo", "partitioned" : true,
          "primary" : "localhost:30002",
          "sharded" : { "foo.foo" : { "key" : { "_id" : 1 }, "unique" : false } },
          "_id" : ObjectId("4bd9ae60c0302e394c6844b7") }
        my chunks
        foo.foo { "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } }
                  on : localhost:30002 { "t" : 1272557259000, "i" : 1 }
like image 111
Manu Eidenberger Avatar answered Sep 19 '22 00:09

Manu Eidenberger


MongoDB has detailed documentation on Sharding here ...

http://www.mongodb.org/display/DOCS/Sharding+Introduction

To anwser you question (I think), see the portion on the config Servers ...

Each config server has a complete copy of all chunk information. A two-phase commit is used to ensure the consistency of the configuration data among the config servers.

Basically, it is the config server's job to make sure everything get sharded ... correctly.

Also, there are system collections you can query ...

db.runCommand( { listshards : 1 } );

Lots of help in the prez below too ...

http://www.slideshare.net/mongodb/mongodb-sharding-internals

http://www.10gen.com/video/mongosv2010/sharding

like image 44
Justin Jenkins Avatar answered Sep 19 '22 00:09

Justin Jenkins