[SERVER-75733] Clarify lifetime guarantees of NamespaceString::ns and DatabaseName::db Created: 05/Apr/23  Updated: 29/Oct/23  Resolved: 15/Apr/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.0-rc1

Type: Improvement Priority: Major - P3
Reporter: Matt Broadstone Assignee: Matt Broadstone
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Backport Requested:
v7.0
Sprint: Server Serverless 2023-04-17
Participants:

 Description   

NamespaceString::ns and DatabaseName::db both return const std::string& to their own std::string storage. This leads to difficult-to-maintain code because the lifetime of the returned value is unclear: sometimes it results in a copy, other times it remains a const-ref.

With the upcoming changes in SERVER-75529, we no longer have the option of returning a const-ref to a member variable. Having these methods return std::string violates assumptions of some call sites due to the aforementioned lifetime ambiguity. This ticket is a pre-requisite, it will change these methods to return a StringData which will a) clarify the lifetime assumptions at the callsite, b) ease the transition to the changes proposed in SERVER-75529.



 Comments   
Comment by Githook User [ 02/May/23 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@mongodb.com', 'username': 'mbroadst'}

Message: SERVER-75733 SERVER-76222 SERVER-75529 SERVER-76632 SERVER-76632 Backport perf improvements to NamespaceString

(cherry picked from commit 3e76161bc537343aa585b305c068b1910578c07f)
(cherry picked from commit 7cc71f7d5f29a5850a4d186b9554df3dcb407117)
(cherry picked from commit 7c1ed6898f9004cf7aa9b2e16371fa83c72b3ba3)
(cherry picked from commit 95782eb4c729cd341ae2398863faa8292d8abd4e)
(cherry picked from commit bcff3cee04973b3ab91b78a70ca6b5740f22e1a0)
Branch: v7.0
https://github.com/mongodb/mongo/commit/57cb7734d42bad79f636e9be2ad313398614e83e

Comment by Githook User [ 14/Apr/23 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@mongodb.com', 'username': 'mbroadst'}

Message: SERVER-75733 Return StringData in NSS::ns, DatabaseName::db
Branch: master
https://github.com/mongodb/mongo/commit/3e76161bc537343aa585b305c068b1910578c07f

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