Data not getting distributed across shards

Dear all,

I’ve been following the book “MongoDB The Definitive Guide, 3rd Ed” to grasp some knowledge about sharding. Please take a look at the following steps that I did based on the book’s example:

use sample
for (var i=0; i<100000; i++) {
db.users.insert({“username”: “user”+i, “created_at”: new Date()});
}

sh.enableSharding(“sample”)
db.users.createIndex({“username”: 1})
sh.shardCollection(“sample.users”, {“username” : 1})
db.adminCommand( { flushRouterConfig: “sample.users” } );

After a while, I ran the sh.status() command to check whether data get distributed across shards.

mongos> sh.status()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“6107bf46d86674a86df43f0c”)
}
shards:
{ “_id” : “rs1”, “host” : “rs1/mongo-01:27011,mongo-02:27011,mongo-03:27011”, “state” : 1, “tags” : [ “zone1”, “zone2” ] }
{ “_id” : “rs2”, “host” : “rs2/mongo-01:27012,mongo-02:27012,mongo-03:27012”, “state” : 1, “tags” : [ “zone2” ] }
most recently active mongoses:
“4.4.3” : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ “_id” : “config”, “primary” : “config”, “partitioned” : true }
config.system.sessions
shard key: { “_id” : 1 }
unique: false
balancing: true
chunks:
rs1 512
rs2 512
too many chunks to print, use verbose if you want to force print
{ “_id” : “sample”, “primary” : “rs2”, “partitioned” : true, “version” : { “uuid” : UUID(“99233e26-17ba-440d-b8ca-a1e6a206e2f5”), “lastMod” : 1 } }
sample.users
shard key: { “username” : 1 }
unique: false
balancing: true
chunks:
rs2 1
{ “username” : { “$minKey” : 1 } } -->> { “username” : { “$maxKey” : 1 } } on : rs2 Timestamp(1, 0)

mongos> db.getSiblingDB(“sample”).users.getShardDistribution();

Shard rs2 at rs2/mongo-01:27012,mongo-02:27012,mongo-03:27012
data : 6.28MiB docs : 100000 chunks : 1
estimated data per chunk : 6.28MiB
estimated docs per chunk : 100000

Totals
data : 6.28MiB docs : 100000 chunks : 1
Shard rs2 contains 100% data, 100% docs in cluster, avg obj size on shard : 65B

As you can see from the output, data reside on only 1 shard. I’ve been studying on the MongoDB forum and the internet, but haven’t found the solution. So I’ve created the topic, please have a look and help me out.

Thanks,
Thang

Hi @Thang_Duong ,

I don’t think that 6.4mb of data justify a default chunk split.

If there is only one chunk and you haven’t used splitAt to manually split chunks the data will be residing on one shard until it grows and justify an auto split.

I suggest to read this

Additionally you have zone sharding defined but I can’t seem to understand which rangesbelong to what zone. Can you elaborate??

Thanks
Pavel

Hi @Pavel_Duchovny,

I’ve used splitAt to manually split chunks, now the data is distributed across 2 shards. Looks like I don’t have enough data to trigger an auto split.
Thank you very much for your suggestion!

mongos> db.getSiblingDB(“sample”).users.getShardDistribution();

Shard rs1 at rs1/mongo-01:27011,mongo-02:27011,mongo-03:27011
data : 2.79MiB docs : 44449 chunks : 1
estimated data per chunk : 2.79MiB
estimated docs per chunk : 44449

Shard rs2 at rs2/mongo-01:27012,mongo-02:27012,mongo-03:27012
data : 6.28MiB docs : 100000 chunks : 1
estimated data per chunk : 6.28MiB
estimated docs per chunk : 100000

Totals
data : 9.07MiB docs : 144449 chunks : 2
Shard rs1 contains 30.77% data, 30.77% docs in cluster, avg obj size on shard : 65B
Shard rs2 contains 69.22% data, 69.22% docs in cluster, avg obj size on shard : 65B

Btw, nvm the zone sharding settings, some other folks in my team have been trying to test things.

Thanks,
Thang

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.