When you try and run collStats on a mongoS, on a sharded collection, if you provide a "scale" argument, the avgObjSize is incorrectly scaled.
The actual scaled value also depends on the number of shards.
The same collStats command run on a mongoD does not scale the avgObjSize value
Full repro scripts attached, requires mtools. Test it like
bash repro
If I were better at scripting it would be prettier, but it does the following:
- Spins up a 1, 2, or 3 shard cluster with mtools
- Shards a collection and makes 1, 2, or 3 chunks, and waits for the balancer to put 1 chunk on each shard
- Inserts 6 documents
- Connects to the mongoS and directly to each shard, and gets the output of
db.version() db.foo.stats().avgObjSize db.foo.stats(1024).avgObjSize
The average object size should be 2032, and this is reported every time for db.foo.stats().avgObjSize
For db.foo.stats(1024).avgObjSize
- If you're connecting to a mongod directly, it reports 2032
- If you're connecting to a mongoS...
- ... and there's 1 shard, it reports 1.83333
- ... and there's 2 shards, it reports 1.6666666666666667
- ... and there's 3 shards, it reports 1.5
Tested in 2.6.10 and 3.0.4
jstests/sharding/stats.js will need be be updated as it's not catching this
- related to
-
SERVER-8617 db.stats(scale) and db.collection.stats(scale) are inconsistent w.r.t. "avgObjSize"
- Closed
-
SERVER-7347 Do not scale avgObjSize in db.stats() for mongos to be consistent with mongod
- Closed