summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-04-04 15:20:14 -0400
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-04-05 13:46:35 -0400
commitac6544a9194197b5ab10f563cf1a19dcdc42349c (patch)
tree865d85a31d942f521ba53fcd4d51edc3b9397971 /src/mongo
parenta6d486b8a6e0c81771bd771cc0237236791d635d (diff)
downloadmongo-ac6544a9194197b5ab10f563cf1a19dcdc42349c.tar.gz
SERVER-34316 Directly take DBLock and CollectionLock in onCannotImplicitlyCreateCollection
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/implicit_create_collection.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mongo/db/s/implicit_create_collection.cpp b/src/mongo/db/s/implicit_create_collection.cpp
index eb705256584..c15fc331d41 100644
--- a/src/mongo/db/s/implicit_create_collection.cpp
+++ b/src/mongo/db/s/implicit_create_collection.cpp
@@ -36,6 +36,7 @@
#include <memory>
#include <string>
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/commands.h"
#include "mongo/db/namespace_string.h"
@@ -89,10 +90,16 @@ public:
});
try {
- AutoGetCollection autoColl(opCtx, _ns, MODE_IS);
- if (autoColl.getCollection() != nullptr) {
- // Collection already created, no more work needs to be done.
- return Status::OK();
+ // Take the DBLock and CollectionLock directly rather than using AutoGetCollection
+ // (which calls AutoGetDb) to avoid doing database and shard version checks.
+ Lock::DBLock dbLock(opCtx, _ns.db(), MODE_IS);
+ const auto db = dbHolder().get(opCtx, _ns.db());
+ if (db) {
+ Lock::CollectionLock collLock(opCtx->lockState(), _ns.ns(), MODE_IS);
+ if (db->getCollection(opCtx, _ns.ns())) {
+ // Collection already created, no more work needs to be done.
+ return Status::OK();
+ }
}
} catch (const DBException& ex) {
return ex.toStatus();