diff options
author | Mihai Andrei <mihai.andrei@10gen.com> | 2020-10-29 15:58:17 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-09 18:34:13 +0000 |
commit | 1f9cbb6d62ddc0ab872ed361dc042647f57184ed (patch) | |
tree | 29eb17363beb5b45f9ed63b151cf63635dc657fd | |
parent | 5e0d73d0d8e559e34203740af93b6ca03d573ea5 (diff) | |
download | mongo-1f9cbb6d62ddc0ab872ed361dc042647f57184ed.tar.gz |
SERVER-51894 Don't call std::move() on 'collectionOptions' when calling 'userCreateNS' in create_collection.cpp
-rw-r--r-- | src/mongo/db/catalog/create_collection.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index 1cc45d31710..9b10c11b822 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -100,7 +100,9 @@ Status _createView(OperationContext* opCtx, Top::get(serviceContext).collectionDropped(nss); }); - Status status = db->userCreateNS(opCtx, nss, std::move(collectionOptions), true, idIndex); + // Even though 'collectionOptions' is passed by rvalue reference, it is not safe to move + // because 'userCreateNS' may throw a WriteConflictException. + Status status = db->userCreateNS(opCtx, nss, collectionOptions, true, idIndex); if (!status.isOK()) { return status; } @@ -162,7 +164,10 @@ Status _createTimeseries(OperationContext* opCtx, // Create the time-series view. options.viewOn = bucketsNs.coll().toString(); - auto status = db->userCreateNS(opCtx, ns, std::move(options)); + + // Even though 'options' is passed by rvalue reference, it is not safe to move because + // 'userCreateNS' may throw a WriteConflictException. + auto status = db->userCreateNS(opCtx, ns, options); if (!status.isOK()) { return status.withContext(str::stream() << "Failed to create view on " << bucketsNs << " for time-series collection " << ns); @@ -214,8 +219,9 @@ Status _createCollection(OperationContext* opCtx, Top::get(serviceContext).collectionDropped(nss); }); - Status status = - autoDb.getDb()->userCreateNS(opCtx, nss, std::move(collectionOptions), true, idIndex); + // Even though 'collectionOptions' is passed by rvalue reference, it is not safe to move + // because 'userCreateNS' may throw a WriteConflictException. + Status status = autoDb.getDb()->userCreateNS(opCtx, nss, collectionOptions, true, idIndex); if (!status.isOK()) { return status; } |