renameCollection target should never have identical UUID with a different database

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.6.4, 3.7.3
    • Affects Version/s: None
    • Component/s: Storage
    • None
    • Fully Compatible
    • v3.6
    • Storage 2018-02-12, Storage 2018-02-26
    • 0
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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);
              }
      

            Assignee:
            Xiangyu Yao (Inactive)
            Reporter:
            Judah Schvimer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: