Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19533

collStats through mongoS on sharded collection incorrectly scales avgObjSize

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.10
    • Affects Version/s: 2.6.10, 3.0.4
    • Component/s: Sharding
    • Labels:
    • Minor Change
    • ALL
    • Sharding 10 (02/19/16), Sharding 16 (06/24/16), Sharding 17 (07/15/16)

      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:

      1. Spins up a 1, 2, or 3 shard cluster with mtools
      2. Shards a collection and makes 1, 2, or 3 chunks, and waits for the balancer to put 1 chunk on each shard
      3. Inserts 6 documents
      4. 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

        1. 1shard.js
          10 kB
        2. 2shards.js
          10 kB
        3. 3shards.js
          10 kB
        4. repro
          0.9 kB

            Assignee:
            sam.dunietz Sam Dunietz
            Reporter:
            joanna.cheng@mongodb.com Joanna Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: