1
votes

I have added two shards as follows:

  shards:
        {  "_id" : "rs0",  "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
        {  "_id" : "rs1",  "host" : "rs1/serv3:27017,serv4:27017,serv5:27017" }

I have sharded my collection posts as follows:

databases:

{  "_id" : "mypost",  "partitioned" : true,  "primary" : "rs0" }

             mypost.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    2
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
                        { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)

My question is even though I use hashed key on _id and inserted 34MB of data why data is always fetched from shard 1 only and no chunk is moved to shard 2.

when I do

db.posts.find().explain() i get:

{
        "clusteredType" : "ParallelSort",
        "shards" : {
                "rs0/serv1:27017,serv2:27017,serv3:27017" : [
                        {
                                "cursor" : "BasicCursor",
                                "isMultiKey" : false,
                                "n" : 1000,
                                "nscannedObjects" : 1000,
                                "nscanned" : 1000,
                                "nscannedObjectsAllPlans" : 1000,
                                "nscannedAllPlans" : 1000,
                                "scanAndOrder" : false,
                                "indexOnly" : false,
                                "nYields" : 0,
                                "nChunkSkips" : 0,
                                "millis" : 4,
                                "indexBounds" : {

                                },
                                "server" : "serv1:27017"
                        }
                ]
        },
        "cursor" : "BasicCursor",
        "n" : 1000,
        "nChunkSkips" : 0,
        "nYields" : 0,
        "nscanned" : 1000,
        "nscannedAllPlans" : 1000,
        "nscannedObjects" : 1000,
        "nscannedObjectsAllPlans" : 1000,
        "millisShardTotal" : 4,
        "millisShardAvg" : 4,
        "numQueries" : 1,
        "numShards" : 1,
        "indexBounds" : {

        },
        "millis" : 5
}

How can my data be sent to both the shard automatically.

sh.status()

  sharding version: {
        "_id" : 1,
        "version" : 3,
        "minCompatibleVersion" : 3,
        "currentVersion" : 4,
        "clusterId" : ObjectId("50fde9a8552b8ce5c47c8ead")
}
  shards:
        {  "_id" : "rs0",  "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
        {  "_id" : "rs1",  "host" : "rs1/serv4:27017,serv5:27017,serv6:27017" }
  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "myposts",  "partitioned" : true,  "primary" : "rs0" }
                myposts.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0)

status after delete of collection---------------------

{  "_id" : "myposts",  "partitioned" : true,  "primary" : "rs0" }
                myposts.posts
                        shard key: { "_id" : "hashed" }
                        chunks:
                                rs0    2
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
                        { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)
1
sh.status() output? You seem to have a shard key that only consists of the value 0 which is odd - Sammaye
@Sammaye can you explain a bit detail? - Phalguni Mukherjee
@Sammaye my id field values are all diffrenet:{ "_id" : ObjectId("50ab0f8bbcf1bfe2536dc3f8") } { "_id" : ObjectId("50ab0f8bbcf1bfe2536dc3f9") } { "_id" : ObjectId("50ab0f8bbcf1bfe2536dc3fa") } { "_id" : ObjectId("50ab0f8bbcf1bfe2536dc3fb") } - Phalguni Mukherjee
What I meant was can you first add the output of sh.status()? - Sammaye
@Sammaye sh.status() is the output shown in first two grey, it is broken and made two parts to be more clear. - Phalguni Mukherjee

1 Answers

0
votes

If you look over the Sharding Mechanics documentation (and if you are mongodb 2.2 or later), you'll see that for fewer than 20 chunks, you'll need to have an imbalance of 2 for the balancer to move chunks.

I wouldn't expect you to have any balancing of chunks until you have a minimum of 4 chunks.

Is there a reason why you have so few chunks defined or are you going to wait for enough data to roll in to have the balancer slice and dice things for you?