[SERVER-81638] Refactor misleading ensureNsNotCommand Created: 02/Oct/23  Updated: 08/Nov/23  Resolved: 08/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Task Priority: Major - P3
Reporter: Mathis Bessa Assignee: Ryan Berryhill
Resolution: Fixed Votes: 0
Labels: neweng, techdebt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-81288 Make NamespaceStringUtil::serialize n... Closed
Assigned Teams:
Service Arch
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2023-10-30, Service Arch 2023-11-13
Participants:

 Description   

Today the logic behind ensureNsNotCommand is a bit problematic.

We call `serialize` on a NamespaceString object just to parse the string and check for a `$`. We should refactor that so we do not have to allocated a new `std::string` just to parse the NamespaceString data.

The name of the method is also problematic.

 
This documentation page shows us that there is a restriction on collection name not including a $ , and it appears that this is where we actually do that validation. Its really like the function wants to be called ensureValidQueryNamespace and its implementation should be like:
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid collection name specified '" << nss.toStringForErrorMsg(),
!nss.isCommand() && isValidCollection(nss.coll()) && nss != NamespaceString::kLocalOplogDollarMain));



 Comments   
Comment by Githook User [ 08/Nov/23 ]

Author:

{'name': 'Ryan Berryhill', 'email': 'ryan.berryhill@mongodb.com', 'username': 'ryanberryhill'}

Message: SERVER-81638 Refactor and rename misleading ensureNsNotCommand
Branch: master
https://github.com/mongodb/mongo/commit/6ff032b838f85896235e695633f6d86cb27537e2

Generated at Thu Feb 08 06:47:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.