From 4d2ca242fb7b9a28d1123831db99664eb0db3e23 Mon Sep 17 00:00:00 2001 From: Esha Maharishi Date: Wed, 7 Mar 2018 12:21:54 -0500 Subject: SERVER-33726 make reIndex command use AutoGetDb to take DBLock rather than taking DBLock directly --- src/mongo/db/commands/drop_indexes.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/mongo/db/commands/drop_indexes.cpp') 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(); -- cgit v1.2.1