[SERVER-33086] renameCollection target should never have identical UUID with a different database Created: 02/Feb/18  Updated: 29/Oct/23  Resolved: 19/Feb/18

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: 3.6.4, 3.7.3

Type: Improvement Priority: Major - P3
Reporter: Judah Schvimer Assignee: Xiangyu Yao (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-33087 Fix the use of dropTarget in renameCo... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v3.6
Sprint: Storage 2018-02-12, Storage 2018-02-26
Participants:
Linked BF Score: 0

 Description   

From: https://github.com/mongodb/mongo/blob/69f920a868112a059f6c09f373f9fb93a1b6b0e5/src/mongo/db/catalog/rename_collection.cpp#L141-L157

The targetUUID here is actually the source collection's UUID, and we're checking if the target collection has the same UUID as the source collection. In that case it should be impossible for the databases to be different. We should change this to an assertion if this isn't true.

    // Check if the target namespace exists and if dropTarget is true.
    // Return a non-OK status if target exists and dropTarget is not true or if the collection
    // is sharded.
    Collection* targetColl = targetDB->getCollection(opCtx, target);
    if (targetColl) {
        // If we already have the collection with the target UUID, we found our future selves,
        // so nothing left to do but drop the source collection in case of cross-db renames.
        if (targetUUID && targetUUID == targetColl->uuid()) {
            if (source.db() == target.db())
                return Status::OK();
            BSONObjBuilder unusedResult;
            return dropCollection(opCtx,
                                  source,
                                  unusedResult,
                                  {},
                                  DropCollectionSystemCollectionMode::kAllowSystemCollectionDrops);
        }



 Comments   
Comment by Githook User [ 28/Feb/18 ]

Author:

{'email': 'xiangyu.yao@mongodb.com', 'name': 'Xiangyu Yao', 'username': 'xy24'}

Message: SERVER-33086 Change renameCollection to be a noop when the target exists and has the same UUID as the source

(cherry picked from commit 6effecb6c6298f2618e05eea885d74c04c7b9c9e)
Branch: v3.6
https://github.com/mongodb/mongo/commit/9bb329b37f2a4b893c4fe9fa14301ba00be42018

Comment by Githook User [ 17/Feb/18 ]

Author:

{'email': 'xiangyu.yao@mongodb.com', 'name': 'Xiangyu Yao', 'username': 'xy24'}

Message: SERVER-33086 Change renameCollection to be a noop when the target exists and has the same UUID as the source
Branch: master
https://github.com/mongodb/mongo/commit/6effecb6c6298f2618e05eea885d74c04c7b9c9e

Generated at Thu Feb 08 04:32:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.