[SERVER-44891] collStats will fail if resulting BSON size > 16MB Created: 02/Dec/19  Updated: 23/Oct/23  Resolved: 20/Dec/19

Status: Closed
Project: Core Server
Component/s: Sharding, Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alex Bevilacqua Assignee: Charlie Swanson
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-77038 db.<collection>.stats() - BufBuilder... Closed
Problem/Incident
causes SERVER-44892 getShardDistribution should use $coll... Closed
Related
related to SERVER-33435 Remove the collstats command Backlog
related to DOCS-13326 Suggest using $collStats as an altern... Closed
is related to SERVER-44051 getShardDistribution() does not repor... Closed
Operating System: ALL
Sprint: Query 2019-12-30
Participants:
Case:

 Description   

Given a larger (50+) sharded cluster with a collection with a larger (45+) number of indexes, when running the collStats command the result will be a failure due to exceeding the internal BSON document size limit:

mongos> db.runCommand({ collStats : "collection", scale: 1024 })
{
   "ok" : 0,
   "errmsg" : "BSONObj size: 17465286 (0x10A7FC6) is invalid. Size must be between 0 and 16793600(16MB) First element: sharded: true",
   "code" : 10334,
   "codeName" : "Location10334"
}

See https://gist.github.com/alexbevi/dc51c0ce4820f46e46feca06dbdc64bb for reproduction details. Issue appears to originate at https://github.com/mongodb/mongo/blob/81238fa87afbe52a9658547f63c79fac126862f1/src/mongo/s/commands/cluster_coll_stats_cmd.cpp#L207 where the shard results are objectified.



 Comments   
Comment by Charlie Swanson [ 03/Jan/20 ]

alex.bevilacqua I filed DOCS-13326!

Comment by Charlie Swanson [ 20/Dec/19 ]

Hi alex.bevilacqua.

This is indeed unfortunate behavior but I believe you will be able to work around it by using the $collStats stage which will provide a cursor. I'm closing this as "Won't Fix" as we don't plan on maintaining the collStats command much anymore, but please re-open if there's some reason the agg stage won't work for this use case. I will also link this as related to SERVER-33435.

Comment by Carl Champain (Inactive) [ 02/Dec/19 ]

Passing this ticket along to the Sharding team.

Comment by Alex Bevilacqua [ 02/Dec/19 ]

A solution to this could be to accept an optional param for collStats (maybe unwindShards: true) which would return an array instead of a document. If this option were set, when the shardResults were being iterated (see https://github.com/mongodb/mongo/blob/81238fa87afbe52a9658547f63c79fac126862f1/src/mongo/s/commands/cluster_coll_stats_cmd.cpp#L108) instead of appending them to a single result object, they could be pushed to an array.

Generated at Thu Feb 08 05:07:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.