[SERVER-53083] collStats results depend on topology and option. Created: 25/Nov/20  Updated: 29/Oct/23  Resolved: 23/Mar/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Bug Priority: Major - P3
Reporter: Sam Mercier Assignee: Ruslan Abdulkhalikov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-54470 Add $collStats aggregate pipeline sta... Closed
is related to SERVER-35479 Make $collStats count behavior have "... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

1) Setup a mongod instance.
2) Connect to the mongod instance and run the following commands producing the following output:

> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"unknown": {}}}], cursor:{}})
{
        "ok" : 0,
        "errmsg" : "unrecognized option to $collStats: unknown",
        "code" : 40168,
        "codeName" : "Location40168"
}
> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"queryExecStats": {}}}], cursor:{}})
{
        "ok" : 0,
        "errmsg" : "PlanExecutor error during aggregation :: caused by :: Unable to retrieve queryExecStats in $collStats stage :: caused by :: Collection [test.dne] not found.",
        "code" : 26,
        "codeName" : "NamespaceNotFound"
}
> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"storageStats": {}}}], cursor:{}})
{
        "ok" : 0,
        "errmsg" : "PlanExecutor error during aggregation :: caused by :: Unable to retrieve storageStats in $collStats stage :: caused by :: Collection [test.dne] not found.",
        "code" : 26,
        "codeName" : "NamespaceNotFound"
}

3) Start a sharded cluster (e.g. by running

let st = ShardingTest({shards: 2})

in the mongo shell with the `--nodb` option).
4) Connect to the mongos and run the following commands producing the following results: (if you use `ShardingTest` to start the sharded cluster the mongos should be on port 20005)

mongos> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"unknown": {}}}], cursor:{}})
{
        "result" : [ ],
        "cursor" : {
                "id" : NumberLong(0),
                "ns" : "test.dne",
                "firstBatch" : [ ]
        },
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1606339832, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1606339832, 1)
}
mongos> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"queryExecStats": {}}}], cursor:{}})
{
        "result" : [ ],
        "cursor" : {
                "id" : NumberLong(0),
                "ns" : "test.dne",
                "firstBatch" : [ ]
        },
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1606339835, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1606339835, 1)
}
mongos> db.runCommand({aggregate: "dne", pipeline:[{"$collStats": {"storageStats": {}}}], cursor:{}})
{
        "result" : [ ],
        "cursor" : {
                "id" : NumberLong(0),
                "ns" : "test.dne",
                "firstBatch" : [ ]
        },
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1606339835, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1606339835, 1)
}

Sprint: Query 2020-12-28, Query 2021-01-25, Query Optimization 2021-02-22, Query Optimization 2021-03-08, Query Optimization 2021-03-22, Query Optimization 2021-04-05
Participants:

 Description   

In three additional cases (beyond the ones described in SERVER-35479 and SERVER-35522) the results of collStats depends on the topology of the server.

Currently, if one attaches to a standalone instance of mongo, one will receive the NamespaceNotFound error code if one asks for collStats with the queryExecStats or storageStats options on a namespace that doesn't exist (e.g. "dne"). Additionally, one will receive a numeric error code if one passes an unknown option (e.g. "unknown").

However, if one connects to a mongos the NamespaceNotFound errors will be suppressed by the mongos instance if one pass such options to a namespace that doesn't exist. Additionally, because we don't validate that the options passed to collStats are correct when we do a "light parse" of the pipeline we actually get a NamespaceNotFound error when we get the routing info which then gets suppressed by the same code path if one asks for collStats on a collection that doesn't exist with an unknown option.

Resolution of this ticket should include:
1) Stopping mongos from suppressing namespace not found errors.
2) Ensuring that mongos produces an option validation error before a namespace not found error in the event of unknown options being passed to a collStats stage being run on a nonexistent namespace.
3) Tests to verify that collStats behaves correctly regardless of topology.



 Comments   
Comment by Githook User [ 23/Mar/21 ]

Author:

{'name': 'ruslan.abdulkhalikov', 'email': 'ruslan.abdulkhalikov@mongodb.com', 'username': 'rusabd1'}

Message: SERVER-53083 collStats results depend on topology and option
Branch: master
https://github.com/mongodb/mongo/commit/20c01a9f4cd201662f9d67f3974fd85df0979186

Comment by Joel Redman (Inactive) [ 07/Jan/21 ]

Still trying to get my first build. But sure!

via [1]Newton Mail
On Thu, Jan 7, 2021 at 10:49 AM, Charlie Swanson (Jira) <jira@mongodb.org> wrote:
Message Title

[2]Charlie Swanson assigned an issue to [3]Joel Redman

 

[4]Joel Redman I'm assigning this to you to track for the next sprint. Please take a look after you get to a good stopping point and/or blocked with your current ticket.

[5]Core Server / [6][7]SERVER-53083
[8]collStats results depend on topology and option.

Change By: [9]Charlie Swanson
Sprint: Query 2020-12-28, Query 2021-01- 11 25
Assignee: Backlog - Query Optimization Joel Redman

[10] [11]Add Comment
 

This message was sent from MongoDB's issue tracking system. To respond to this ticket, please login to [12]jira.mongodb.org using your JIRA, MongoDB Cloud Manager, or MongoDB Atlas credentials.
----------------------------------------------------------------------------------------
[1] https://cloudmagic.com/k/d/mailapp?ct=pi&cv=10.0.53&pv=14.2&source=email_footer_2
[2] https://jira.mongodb.org/secure/ViewProfile.jspa?name=charlie.swanson
[3] https://jira.mongodb.org/secure/ViewProfile.jspa?name=joel.redman
[4] https://jira.mongodb.org/secure/ViewProfile.jspa?name=joel.redman
[5] https://jira.mongodb.org/browse/SERVER
[6] https://jira.mongodb.org/browse/SERVER-53083
[7] https://jira.mongodb.org/browse/SERVER-53083
[8] https://jira.mongodb.org/browse/SERVER-53083
[9] https://jira.mongodb.org/secure/ViewProfile.jspa?name=charlie.swanson
[10] https://jira.mongodb.org/browse/SERVER-53083#add-comment
[11] https://jira.mongodb.org/browse/SERVER-53083#add-comment
[12] https://jira.mongodb.org

Comment by Charlie Swanson [ 07/Jan/21 ]

joel.redman I'm assigning this to you to track for the next sprint. Please take a look after you get to a good stopping point and/or blocked with your current ticket.

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