summaryrefslogtreecommitdiff
path: root/src/mongo/db/cloner.cpp
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2019-06-26 17:03:46 -0400
committerjannaerin <golden.janna@gmail.com>2019-07-03 11:39:23 -0400
commit7584ab9b19d154146925f6b5e57d364e80dd8fb6 (patch)
tree523ea345a1c90ed9f173c8c8430cb66c2b07d62c /src/mongo/db/cloner.cpp
parent175995d2a5099d74c93f7b36bb20e399686c03c5 (diff)
downloadmongo-7584ab9b19d154146925f6b5e57d364e80dd8fb6.tar.gz
SERVER-41683 Only check UUID in movePrimary collection cloner
Diffstat (limited to 'src/mongo/db/cloner.cpp')
-rw-r--r--src/mongo/db/cloner.cpp115
1 files changed, 54 insertions, 61 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 60baaaa1e59..3ddd265ea1e 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -585,74 +585,67 @@ Status Cloner::createCollectionsForDb(
const NamespaceString nss(dbName, params.collectionName);
uassertStatusOK(userAllowedCreateNS(dbName, params.collectionName));
- Status status =
- writeConflictRetry(opCtx, "createCollection", nss.ns(), [&] {
- opCtx->checkForInterrupt();
- WriteUnitOfWork wunit(opCtx);
-
- Collection* collection = db->getCollection(opCtx, nss);
- if (collection) {
- if (!params.shardedColl) {
- // If the collection is unsharded then we want to fail when a collection
- // we're trying to create already exists.
- return Status(ErrorCodes::NamespaceExists,
- str::stream() << "unsharded collection with same namespace "
- << nss.ns()
- << " already exists.");
- }
-
- // If the collection is sharded and a collection with the same name already
- // exists on the target, we check if the existing collection's options and
- // UUID match those of the one we're trying to create. If they do, we treat
- // the create as a no-op; if they don't match, we return an error.
- auto existingOpts = DurableCatalog::get(opCtx)
- ->getCollectionOptions(opCtx, collection->ns())
- .toBSON();
- UnorderedFieldsBSONObjComparator bsonCmp;
-
- optionsBuilder.append(params.collectionInfo["info"]["uuid"]);
- auto options = optionsBuilder.obj();
-
- if (bsonCmp.evaluate(existingOpts == options)) {
- return Status::OK();
- }
+ Status status = writeConflictRetry(opCtx, "createCollection", nss.ns(), [&] {
+ opCtx->checkForInterrupt();
+ WriteUnitOfWork wunit(opCtx);
- return Status(
- ErrorCodes::InvalidOptions,
- str::stream()
- << "sharded collection with same namespace "
- << nss.ns()
- << " already exists, but options don't match. Existing options are "
- << existingOpts
- << " and new options are "
- << options);
+ Collection* collection = db->getCollection(opCtx, nss);
+ if (collection) {
+ if (!params.shardedColl) {
+ // If the collection is unsharded then we want to fail when a collection
+ // we're trying to create already exists.
+ return Status(ErrorCodes::NamespaceExists,
+ str::stream() << "unsharded collection with same namespace "
+ << nss.ns()
+ << " already exists.");
}
- // If the collection does not already exist and is sharded, we create a new
- // collection on the target shard with the UUID of the original collection and
- // copy the options and secondary indexes. If the collection does not already
- // exist and is unsharded, we create a new collection with its own UUID and
- // copy the options and secondary indexes of the original collection.
+ // If the collection is sharded and a collection with the same name already
+ // exists on the target, we check if the existing collection's UUID matches
+ // that of the one we're trying to create. If it does, we treat the create
+ // as a no-op; if it doesn't match, we return an error.
+ auto existingOpts =
+ DurableCatalog::get(opCtx)->getCollectionOptions(opCtx, collection->ns());
+ const UUID clonedUUID =
+ uassertStatusOK(UUID::parse(params.collectionInfo["info"]["uuid"]));
+
+ if (clonedUUID == existingOpts.uuid)
+ return Status::OK();
+
+ return Status(
+ ErrorCodes::InvalidOptions,
+ str::stream() << "sharded collection with same namespace " << nss.ns()
+ << " already exists, but UUIDs don't match. Existing UUID is "
+ << existingOpts.uuid
+ << " and new UUID is "
+ << clonedUUID);
+ }
- if (params.shardedColl) {
- optionsBuilder.append(params.collectionInfo["info"]["uuid"]);
- }
+ // If the collection does not already exist and is sharded, we create a new
+ // collection on the target shard with the UUID of the original collection and
+ // copy the options and secondary indexes. If the collection does not already
+ // exist and is unsharded, we create a new collection with its own UUID and
+ // copy the options and secondary indexes of the original collection.
- const bool createDefaultIndexes = true;
- auto options = optionsBuilder.obj();
+ if (params.shardedColl) {
+ optionsBuilder.append(params.collectionInfo["info"]["uuid"]);
+ }
- CollectionOptions collectionOptions = uassertStatusOK(CollectionOptions::parse(
- options, CollectionOptions::ParseKind::parseForStorage));
- auto indexSpec = fixIndexSpec(nss.db().toString(), params.idIndexSpec);
- Status createStatus = db->userCreateNS(
- opCtx, nss, collectionOptions, createDefaultIndexes, indexSpec);
- if (!createStatus.isOK()) {
- return createStatus;
- }
+ const bool createDefaultIndexes = true;
+ auto options = optionsBuilder.obj();
- wunit.commit();
- return Status::OK();
- });
+ CollectionOptions collectionOptions = uassertStatusOK(
+ CollectionOptions::parse(options, CollectionOptions::ParseKind::parseForStorage));
+ auto indexSpec = fixIndexSpec(nss.db().toString(), params.idIndexSpec);
+ Status createStatus =
+ db->userCreateNS(opCtx, nss, collectionOptions, createDefaultIndexes, indexSpec);
+ if (!createStatus.isOK()) {
+ return createStatus;
+ }
+
+ wunit.commit();
+ return Status::OK();
+ });
// Break early if one of the creations fails.
if (!status.isOK()) {