diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2019-03-21 17:00:09 -0400 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2019-03-24 17:11:54 -0400 |
commit | 85126f13b5b26700cb9dc869df3ad747515e6a25 (patch) | |
tree | ce150ada40a6a52f712fd4681aac2c35ffb69427 /src/mongo/db/commands | |
parent | 10f196bb962c6d4f983b9d7b1209aff26f97573a (diff) | |
download | mongo-85126f13b5b26700cb9dc869df3ad747515e6a25.tar.gz |
SERVER-39079 Move BackgroundOperation checks out of the catalog layer; add parallel IndexBuildsCoordinator checks for all BackgroundOperation checks
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/compact.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/drop_indexes.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/commands/rename_collection_cmd.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/test_commands.cpp | 5 |
5 files changed, 36 insertions, 20 deletions
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index 9ae2e824099..d78af120927 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -43,6 +43,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/jsobj.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/views/view_catalog.h" @@ -133,6 +134,9 @@ public: OldClientContext ctx(opCtx, nss.ns()); BackgroundOperation::assertNoBgOpInProgForNs(nss.ns()); + invariant(collection->uuid()); + IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( + collection->uuid().get()); log() << "compact " << nss.ns() << " begin, options: " << compactOptions; diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 1e8ac1b4a25..3d3c125a056 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -48,6 +48,7 @@ #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/logical_clock.h" #include "mongo/db/op_observer.h" #include "mongo/db/service_context.h" @@ -141,6 +142,9 @@ public: } BackgroundOperation::assertNoBgOpInProgForNs(toReIndexNss.ns()); + invariant(collection->uuid()); + IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( + collection->uuid().get()); // This is necessary to set up CurOp and update the Top stats. OldClientContext ctx(opCtx, toReIndexNss.ns()); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index dd933d76470..217db0ed3d5 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -52,6 +52,7 @@ #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/insert.h" @@ -176,15 +177,20 @@ void dropTempCollections(OperationContext* cleanupOpCtx, [cleanupOpCtx, &tempNamespace] { AutoGetDb autoDb(cleanupOpCtx, tempNamespace.db(), MODE_X); if (auto db = autoDb.getDb()) { - WriteUnitOfWork wunit(cleanupOpCtx); - uassert(ErrorCodes::PrimarySteppedDown, - str::stream() << "no longer primary while dropping temporary " - "collection for mapReduce: " - << tempNamespace.ns(), - repl::ReplicationCoordinator::get(cleanupOpCtx) - ->canAcceptWritesFor(cleanupOpCtx, tempNamespace)); - uassertStatusOK(db->dropCollection(cleanupOpCtx, tempNamespace.ns())); - wunit.commit(); + if (auto collection = db->getCollection(cleanupOpCtx, tempNamespace)) { + uassert(ErrorCodes::PrimarySteppedDown, + str::stream() << "no longer primary while dropping temporary " + "collection for mapReduce: " + << tempNamespace.ns(), + repl::ReplicationCoordinator::get(cleanupOpCtx) + ->canAcceptWritesFor(cleanupOpCtx, tempNamespace)); + BackgroundOperation::assertNoBgOpInProgForNs(tempNamespace.ns()); + IndexBuildsCoordinator::get(cleanupOpCtx) + ->assertNoIndexBuildInProgForCollection(collection->uuid().get()); + WriteUnitOfWork wunit(cleanupOpCtx); + uassertStatusOK(db->dropCollection(cleanupOpCtx, tempNamespace.ns())); + wunit.commit(); + } } }); // Always forget about temporary namespaces, so we don't cache lots of them @@ -196,9 +202,14 @@ void dropTempCollections(OperationContext* cleanupOpCtx, Lock::DBLock lk(cleanupOpCtx, incLong.db(), MODE_X); auto databaseHolder = DatabaseHolder::get(cleanupOpCtx); if (auto db = databaseHolder->getDb(cleanupOpCtx, incLong.ns())) { - WriteUnitOfWork wunit(cleanupOpCtx); - uassertStatusOK(db->dropCollection(cleanupOpCtx, incLong.ns())); - wunit.commit(); + if (auto collection = db->getCollection(cleanupOpCtx, incLong)) { + BackgroundOperation::assertNoBgOpInProgForNs(incLong.ns()); + IndexBuildsCoordinator::get(cleanupOpCtx) + ->assertNoIndexBuildInProgForCollection(collection->uuid().get()); + WriteUnitOfWork wunit(cleanupOpCtx); + uassertStatusOK(db->dropCollection(cleanupOpCtx, incLong.ns())); + wunit.commit(); + } } }); diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp index fe2a048b153..7107a370ce0 100644 --- a/src/mongo/db/commands/rename_collection_cmd.cpp +++ b/src/mongo/db/commands/rename_collection_cmd.cpp @@ -80,14 +80,6 @@ public: return CommandHelpers::parseNsFullyQualified(cmdObj); } - static void dropCollection(OperationContext* opCtx, Database* db, StringData collName) { - WriteUnitOfWork wunit(opCtx); - if (db->dropCollection(opCtx, collName).isOK()) { - // ignoring failure case - wunit.commit(); - } - } - virtual bool errmsgRun(OperationContext* opCtx, const string& dbname, const BSONObj& cmdObj, diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 99c3b94f1e7..29a3be76ea2 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -41,6 +41,7 @@ #include "mongo/db/commands.h" #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/db_raii.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/op_observer.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/service_context.h" @@ -169,6 +170,10 @@ public: } } + BackgroundOperation::assertNoBgOpInProgForNs(fullNs.ns()); + IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( + collection->uuid().get()); + collection->cappedTruncateAfter(opCtx, end, inc); return true; |