SampathKumar
SampathKumar

Reputation: 141

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?

Upvotes: 6

Views: 16664

Answers (3)

Gert van den Berg
Gert van den Berg

Reputation: 2786

If you just want to check whether you are conencted to a sharded cluster or not: db.isMaster() can be used to detect that you are connected to a sharding router (mongos).

If db.isMaster().msg is "isdbgrid", you are connected to a sharded instance.

db.isMaster() can be run without authentication.

For checking the details of the shards, sh.status() also works, which has the same output as db.printShardingStatus(); works.

Upvotes: 0

Manu Eidenberger
Manu Eidenberger

Reputation: 2096

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 }

Upvotes: 16

Justin Jenkins
Justin Jenkins

Reputation: 27090

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

Upvotes: 5

Related Questions