-
Type:
Question
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.4.10
-
Component/s: Sharding
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Hi all,
I have a 2-shards-3-replicas cluster in prod, config db is 3-replicas and 2 mongos instances, mongo version is 3.4.10.
I already enabled sharding at db level, then try to shard the collection
*mongos> db.user.ensureIndex(\{person_id: "hashed"}, \{background: true})*
{
"raw" : {
"prod1/172.31.0.16:27017,172.31.0.76:27017,172.31.0.85:27017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1,
"$gleStats" : {
"lastOpTime" : {
"ts" : Timestamp(1567133797, 47),
"t" : NumberLong(11)
},
"electionId" : ObjectId("7fffffff000000000000000b")
}
}
},
"ok" : 1
}
*mongos> sh.shardCollection("prod.user", \{ person_id : "hashed" } )*
{ "collectionsharded" : "prod.user", "ok" : 1 }
*mongos> db.collections.find(\{_id:"prod.user"})*
{ "_id" : "prod.user", "lastmodEpoch" : ObjectId("5d68a55593c736ce7519fdb8"), "lastmod" : ISODate("1970-02-19T17:02:47.694Z"), "dropped" : false, "key" : \{ "person_id" : "hashed" }, "unique" : false }
*mongos> db.user.getShardDistribution()*
Shard prod1 at prod1/172.31.0.16:27017,172.31.0.76:27017,172.31.0.85:27017
data : 12.45GiB docs : 65857922 chunks : 399
estimated data per chunk : 31.96MiB
estimated docs per chunk : 165057
Totals
data : 12.45GiB docs : 65857922 chunks : 399
Shard prod1 contains 100% data, 100% docs in cluster, avg obj size on shard : 203B
Everything seems fine through mongos,but the output in shard instance is below, and the collection still holds on single shard server
*prod1:PRIMARY> db.user.getShardDistribution()* Collection prod.user is not sharded.
I try to re-shard through mongos, which fails
*mongos> sh.shardCollection("prod.user", \{ person_id : "hashed" } )*
{
"code" : 20,
"ok" : 0,
"errmsg" : "sharding already enabled for collection prod.user"
}
There must be some confusions between mongos and shard, but I'm not sure how to debug, since it's prod, every action should be with caution.
Please help to give some tips, thanks!