[SERVER-55887] Remove util/unowned_ptr.h Created: 07/Apr/21  Updated: 29/Oct/23  Resolved: 21/Apr/21

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Question Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2021-05-03
Participants:

 Description   

unowned_ptr is only used in two functions.
These functions can just as easily use raw pointers.

Then we can get rid of a file in util and its test.

src/mongo/db/exec/working_set_common.cpp-69-bool WorkingSetCommon::fetch(OperationContext* opCtx,
src/mongo/db/exec/working_set_common.cpp-70-                             WorkingSet* workingSet,
src/mongo/db/exec/working_set_common.cpp-71-                             WorkingSetID id,
src/mongo/db/exec/working_set_common.cpp:72:                             unowned_ptr<SeekableRecordCursor> cursor,
src/mongo/db/exec/working_set_common.cpp-73-                             const NamespaceString& ns) {
src/mongo/db/exec/working_set_common.cpp-74-    WorkingSetMember* member = workingSet->get(id);
src/mongo/db/exec/working_set_common.cpp-75-
--
src/mongo/db/exec/working_set_common.h-52-    static bool fetch(OperationContext* opCtx,
src/mongo/db/exec/working_set_common.h-53-                      WorkingSet* workingSet,
src/mongo/db/exec/working_set_common.h-54-                      WorkingSetID id,
src/mongo/db/exec/working_set_common.h:55:                      unowned_ptr<SeekableRecordCursor> cursor,
src/mongo/db/exec/working_set_common.h-56-                      const NamespaceString& ns);
src/mongo/db/exec/working_set_common.h-57-};
src/mongo/db/exec/working_set_common.h-58-
--
src/mongo/db/sorter/sorter.cpp-518-    class STLComparator {  // uses greater rather than less-than to maintain a MinHeap
src/mongo/db/sorter/sorter.cpp-519-    public:
src/mongo/db/sorter/sorter.cpp-520-        explicit STLComparator(const Comparator& comp) : _comp(comp) {}
src/mongo/db/sorter/sorter.cpp:521:        bool operator()(unowned_ptr<const Stream> lhs, unowned_ptr<const Stream> rhs) const {
src/mongo/db/sorter/sorter.cpp-522-            // first compare data
src/mongo/db/sorter/sorter.cpp-523-            dassertCompIsSane(_comp, lhs->current(), rhs->current());
src/mongo/db/sorter/sorter.cpp-524-            int ret = _comp(lhs->current(), rhs->current());



 Comments   
Comment by Githook User [ 21/Apr/21 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-55887 remove unowned_ptr
Branch: master
https://github.com/mongodb/mongo/commit/edfe720bfe35c186f7f3f31dbb541ccb1f449d0a

Comment by Billy Donahue [ 19/Apr/21 ]

CR https://mongodbcr.appspot.com/782340001/

Comment by Billy Donahue [ 19/Apr/21 ]

Another thing unowned_ptr does, and I think this could be seen as harmful, is that it can be implicitly constructed from a handful of other smart pointer types. This means that calls to functions taking unowned_ptr aren't evident. They accept shared_ptr or const unique_ptr&. Passing a shared_ptr, for example, could be sharing ownership. You can't tell. So we should be calling .get() at those callsites, and at that point there's no benefit to unowned_ptr there.

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