summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-03-07 12:21:54 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-03-07 13:56:19 -0500
commit4d2ca242fb7b9a28d1123831db99664eb0db3e23 (patch)
treecb28e8b87f4dab7033719c50db2cfb489be68f83
parent86e1b61020ebe8c9490bce56b26b8037581a9c72 (diff)
downloadmongo-4d2ca242fb7b9a28d1123831db99664eb0db3e23.tar.gz
SERVER-33726 make reIndex command use AutoGetDb to take DBLock rather than taking DBLock directly
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp1
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp17
2 files changed, 10 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 72ba9bf0637..1bf42f508d8 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -324,6 +324,7 @@ Status _collModInternal(OperationContext* opCtx,
return Status(ErrorCodes::NamespaceNotFound, "ns does not exist");
}
+ // This is necessary to set up CurOp and update the Top stats.
OldClientContext ctx(opCtx, nss.ns());
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 48b70d171f9..11d199c99ec 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -121,17 +121,15 @@ public:
BSONObjBuilder& result) {
DBDirectClient db(opCtx);
- const NamespaceString toReIndexNs =
+ const NamespaceString toReIndexNss =
CommandHelpers::parseNsCollectionRequired(dbname, jsobj);
- LOG(0) << "CMD: reIndex " << toReIndexNs;
+ LOG(0) << "CMD: reIndex " << toReIndexNss;
- Lock::DBLock dbXLock(opCtx, dbname, MODE_X);
- OldClientContext ctx(opCtx, toReIndexNs.ns());
-
- Collection* collection = ctx.db()->getCollection(opCtx, toReIndexNs);
+ AutoGetOrCreateDb autoDb(opCtx, dbname, MODE_X);
+ Collection* collection = autoDb.getDb()->getCollection(opCtx, toReIndexNss);
if (!collection) {
- if (ctx.db()->getViewCatalog()->lookup(opCtx, toReIndexNs.ns()))
+ if (autoDb.getDb()->getViewCatalog()->lookup(opCtx, toReIndexNss.ns()))
return CommandHelpers::appendCommandStatus(
result, {ErrorCodes::CommandNotSupportedOnView, "can't re-index a view"});
else
@@ -139,7 +137,10 @@ public:
result, {ErrorCodes::NamespaceNotFound, "collection does not exist"});
}
- BackgroundOperation::assertNoBgOpInProgForNs(toReIndexNs.ns());
+ BackgroundOperation::assertNoBgOpInProgForNs(toReIndexNss.ns());
+
+ // This is necessary to set up CurOp and update the Top stats.
+ OldClientContext ctx(opCtx, toReIndexNss.ns());
const auto featureCompatibilityVersion =
serverGlobalParams.featureCompatibility.getVersion();