0
votes

i have created sharding in MONGOD with 3 shard servers(S1,S2,S3), sharding is enabled in S1,S2,S3.

**mongos> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,`enter code here`
        "currentVersion" : 6,
        "clusterId" : ObjectId("592a59b9057c510a56f528e3")
}
  shards:
        {  "_id" : "s1",  "host" : "s1/localhost:37017,localhost:37018,localhost:37019" }
        {  "_id" : "s2",  "host" : "s2/localhost:47017,localhost:47018,localhost:47019" }
        {  "_id" : "s3",  "host" : "s3/localhost:57017,localhost:57018,localhost:57019" }
  active mongoses:
        "3.2.13" : 1
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                2 : Success
  databases:
        {  "_id" : "school",  "primary" : "s1",  "partitioned" : true }
                school.students
                        shard key: { "student_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                s1     1
                        { "student_id" : { "$minKey" : 1 } } -->> { "student_id" : { "$maxKey" : 1 } } on : s1 Timestamp(1, 0)**

the above code mentions that database (school) created in MONGOS is shared with S1 automatically.

will database SCHOOL effect in other shards(S2,S3)?

Please help me in verifying sharding is running perfectly between S1,S2 and S3 with database SCHOOl.

In above case how does data available for application in case of one set crashed which has unique data among all other sets,is restarting the set will work ,how exactly behavior would be

2
Replication factor do the case. If server is down, at least one another will have your data: docs.mongodb.com/manual/replication - FieryCat
What is you exact question ? I mean problem or do you want to understand in general how the sharding behaves ? It will be easier if you give what commands you executed as well and what was expected / actual result of those. - Albatross

2 Answers

0
votes

Below is how databases tag looks for one of sharded collections named "ShardTestDB.Test"

databases:
        {  "_id" : "ShardTestDB",  "primary" : "shardrs1",  "partitioned" : true }
                ShardTestDB.Test
                        shard key: { "_id" : "hashed" }
                        unique: false
                        balancing: true
                        chunks:
                                shardrs1    2
                                shardrs2    2
                                shardrs3    2
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-6148914691236517204") } on : shardrs1 Timestamp(4, 1) 
                        { "_id" : NumberLong("-6148914691236517204") } -->> { "_id" : NumberLong("-3074457345618258602") } on : shardrs1 Timestamp(4, 2) 
                        { "_id" : NumberLong("-3074457345618258602") } -->> { "_id" : NumberLong(0) } on : shardrs2 Timestamp(4, 3) 
                        { "_id" : NumberLong(0) } -->> { "_id" : NumberLong("3074457345618258602") } on : shardrs2 Timestamp(4, 4) 
                        { "_id" : NumberLong("3074457345618258602") } -->> { "_id" : NumberLong("6148914691236517204") } on : shardrs3 Timestamp(4, 5) 
                        { "_id" : NumberLong("6148914691236517204") } -->> { "_id" : { "$maxKey" : 1 } } on : shardrs3 Timestamp(4, 6) 
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shardrs1    1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shardrs1 Timestamp(1, 0) 

By comparing both outputs, it seems that "school.students" collection has been stored in only 1 replicaSet, which is s1 (check under chunks). So there might be some risk of loosing all of your data if the whole s1 replicaSet crashes. But it could be very unlikely. However, if only 1 machine in the replicaSet crashed, data will not get lost because other machines in the replicaSet has the same data (if they had been properly synced).

0
votes

db.collection.getShardDistribution() this will gives your shard distribution. If it's going on one shard only then you need better shard key.

Ideally hash keys are used for fields for which equal data distribution will happen or incremental column