Mongodb – Wrong sharding on mongoDB 3.0

mongodbmongodb-3.0sharding

I have a mongos with 2 shard servers (and 3 config servers)

sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("55ae2ddab9e8641e489ce39b")
}
  shards:
        {  "_id" : "shard0000",  "host" : "192.168.212.182:27018" }
        {  "_id" : "shard0001",  "host" : "192.168.212.106:27018" }
  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "Vision_1282",  "partitioned" : true,  "primary" : "shard0001" }
                Vision_1282.Group
                        shard key: { "groepNr" : 1, "valId" : 1 }
                        chunks:
                                shard0001       1
                        { "groepNr" : { "$minKey" : 1 }, "valId" : { "$minKey" : 1 } } -->> { "groepNr" : { "$maxKey" : 1 }, "valId" : { "$maxKey" : 1 } } on : shard0001 Timestamp(1, 0)
        {  "_id" : "db",  "partitioned" : false,  "primary" : "shard0000" }

I made the shard key as follows:

db.runCommand({ shardcollection : "Vision_1282.Group", key : {groepNr : 1, valId : 1}})

I insert about 10.000 records, where the groepNr is 1, 2, 3 or 4 and a valId can be between 1 and 4001.

When I look at the shardDistribution I see that shard001 only has records where groepNr = 1 and valId = 1. All other records are in shard002.

I thought that the value behind the key value (here groepNr and valId) is 1 for ascending and -1 for descending.

PS. in PHP code, where I do the inserts I also ensure to use the index.
$collection->ensureIndex(array("groepNr" => 1 , "valId" => 1));

Did I do something wrong with creating the shardkey?

Best Answer

I have lowered the chunksize to 1 MB:

 { "_id" : "chunksize", "value" : 1 }

I inserted now about 10.000 documents.

If I look at the sh.status(), I see this:

Shard shard0000 at 192.168.212.182:27018
 data : 1.33Mb docs : 5761 chunks : 4
 estimated data per chunk : 343kb
 estimated docs per chunk : 1440

Shard shard0001 at 192.168.212.106:27018
 data : 1017kb docs : 4249 chunks : 3
 estimated data per chunk : 339kb
 estimated docs per chunk : 1416

Totals
 data : 2.33Mb docs : 10010 chunks : 7
 Shard shard0000 contains 57.41% data, 57.55% docs in cluster, avg obj size on shard : 243b
 Shard shard0001 contains 42.58% data, 42.44% docs in cluster, avg obj size on shard : 245b

Also I run the scripts AllChunkInfo("Vision_1282.Group"), with this result:

mongos> AllChunkInfo("Vision_1282.Group")
ChunkID,Shard,ChunkSize,ObjectsInChunk
Vision_1282.Group-groepNr_MinKeyvalId_MinKey,shard0001,83504,301
Vision_1282.Group-groepNr_"1"valId_"2000",shard0001,1920,8
Vision_1282.Group-groepNr_"1"valId_"2002",shard0001,974144,4012
Vision_1282.Group-groepNr_"2"valId_"1",shard0000,524384,2138
Vision_1282.Group-groepNr_"3"valId_"4",shard0000,498704,2031
Vision_1282.Group-groepNr_"4"valId_"4",shard0000,292800,1220
Vision_1282.Group-groepNr_"4"valId_"6",shard0000,113520,473
***********Summary Chunk Information***********
Total Chunks: 7
Average Chunk Size (bytes): 355568
Empty Chunks: 0
Average Chunk Size (non-empty): 355568

So you are right, the records were to small and the chunksize was to big.

Tx.