diff options
author | Benety Goh <benety@mongodb.com> | 2020-04-08 14:57:41 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-14 20:16:12 +0000 |
commit | 46c6d2c03435ec008b2e7f3afdb301d3177c3dda (patch) | |
tree | 54c9a394c5d1d1b090b6d7b175703b5f78ac7ffb | |
parent | df0569383344d8f7d5b3c8a43d3693322c16a026 (diff) | |
download | mongo-46c6d2c03435ec008b2e7f3afdb301d3177c3dda.tar.gz |
SERVER-47252 IndexBuildsCoordinator shutdown and index build wait functions accept OpCtx
(cherry picked from commit 80499062d182e9f4a29957d6fde0189ec4851f84)
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/catalog/drop_database.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/catalog/drop_indexes.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 9 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.h | 2 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/idempotency_test_fixture.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/rollback_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/service_context_d_test_fixture.cpp | 13 | ||||
-rw-r--r-- | src/mongo/dbtests/storage_timestamp_tests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/embedded/embedded.cpp | 2 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.cpp | 2 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.h | 2 |
17 files changed, 36 insertions, 26 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 60f5ae79b57..a0deed258c7 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -173,7 +173,7 @@ Status _abortIndexBuildsAndDropCollection(OperationContext* opCtx, collLock = boost::none; autoDb = boost::none; - indexBuildsCoord->awaitNoIndexBuildInProgressForCollection(collectionUUID); + indexBuildsCoord->awaitNoIndexBuildInProgressForCollection(opCtx, collectionUUID); // Take an exclusive lock to finish the collection drop. autoDb.emplace(opCtx, startingNss.db(), MODE_IX); diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index 823343c641c..5e0f097bc3f 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -197,7 +197,7 @@ Status _dropDatabase(OperationContext* opCtx, const std::string& dbName, bool ab // to process the abort signal. Holding a lock here will cause the index builders to // block indefinitely. autoDB = boost::none; - indexBuildsCoord->awaitNoBgOpInProgForDb(dbName); + indexBuildsCoord->awaitNoBgOpInProgForDb(opCtx, dbName); if (MONGO_unlikely(dropDatabaseHangAfterWaitingForIndexBuilds.shouldFail())) { LOGV2(4612300, diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp index b76c2d582b8..2478502551b 100644 --- a/src/mongo/db/catalog/drop_indexes.cpp +++ b/src/mongo/db/catalog/drop_indexes.cpp @@ -345,7 +345,7 @@ Status dropIndexes(OperationContext* opCtx, } else if (abortedIndexBuilders.size() > 1) { // Only the "*" wildcard can abort multiple index builders. invariant(isWildcard); - indexBuildsCoord->awaitNoIndexBuildInProgressForCollection(collectionUUID); + indexBuildsCoord->awaitNoIndexBuildInProgressForCollection(opCtx, collectionUUID); } // Take an exclusive lock on the collection now to be able to perform index catalog writes diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index fb18605b15d..fd31a4fe14e 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -1166,7 +1166,7 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { // Shuts down the thread pool and waits for index builds to finish. // Depends on setKillAllOperations() above to interrupt the index build operations. - IndexBuildsCoordinator::get(serviceContext)->shutdown(); + IndexBuildsCoordinator::get(serviceContext)->shutdown(opCtx); // No new readers can come in after the releasing the RSTL, as previously before releasing // the RSTL, we made sure that all new operations will be immediately interrupted by setting diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 99e11412343..6966088ad13 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -538,7 +538,7 @@ std::string IndexBuildsCoordinator::_indexBuildActionToString(IndexBuildAction a MONGO_UNREACHABLE; } -void IndexBuildsCoordinator::waitForAllIndexBuildsToStopForShutdown() { +void IndexBuildsCoordinator::waitForAllIndexBuildsToStopForShutdown(OperationContext* opCtx) { stdx::unique_lock<Latch> lk(_mutex); // All index builds should have been signaled to stop via the ServiceContext. @@ -1206,8 +1206,8 @@ void IndexBuildsCoordinator::awaitNoIndexBuildInProgressForCollection(OperationC opCtx->waitForConditionOrInterrupt(_indexBuildsCondVar, lk, noIndexBuildsPred); } -void IndexBuildsCoordinator::awaitNoIndexBuildInProgressForCollection( - const UUID& collectionUUID) const { +void IndexBuildsCoordinator::awaitNoIndexBuildInProgressForCollection(OperationContext* opCtx, + const UUID& collectionUUID) { stdx::unique_lock<Latch> lk(_mutex); auto collIndexBuildsIt = _collectionIndexBuilds.find(collectionUUID); @@ -1222,7 +1222,7 @@ void IndexBuildsCoordinator::awaitNoIndexBuildInProgressForCollection( invariant(collIndexBuildsSharedPtr->getNumberOfIndexBuilds(lk) == 0); } -void IndexBuildsCoordinator::awaitNoBgOpInProgForDb(StringData db) const { +void IndexBuildsCoordinator::awaitNoBgOpInProgForDb(OperationContext* opCtx, StringData db) { stdx::unique_lock<Latch> lk(_mutex); auto dbIndexBuildsIt = _databaseIndexBuilds.find(db); diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index 20b4e44e544..9cda3fd0c74 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -94,7 +94,7 @@ public: /** * Executes tasks that must be done prior to destruction of the instance. */ - virtual void shutdown() = 0; + virtual void shutdown(OperationContext* opCtx) = 0; /** * Stores a coordinator on the specified service context. May only be called once for the @@ -194,7 +194,7 @@ public: * i.e. when the server is not accepting user requests and no internal operations are * concurrently starting new index builds. */ - void waitForAllIndexBuildsToStopForShutdown(); + void waitForAllIndexBuildsToStopForShutdown(OperationContext* opCtx); /** * Signals all of the index builds on the specified collection to abort and then waits until the @@ -373,12 +373,13 @@ public: void awaitNoIndexBuildInProgressForCollection(OperationContext* opCtx, const UUID& collectionUUID, IndexBuildProtocol protocol); - void awaitNoIndexBuildInProgressForCollection(const UUID& collectionUUID) const; + void awaitNoIndexBuildInProgressForCollection(OperationContext* opCtx, + const UUID& collectionUUID); /** * Waits for all index builds on a specified database to finish. */ - void awaitNoBgOpInProgForDb(StringData db) const; + void awaitNoBgOpInProgForDb(OperationContext* opCtx, StringData db); /** * Called by the replication coordinator when a replica set reconfig occurs, which could affect diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index ae4ffbf7ea1..35c60108c4e 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -105,12 +105,12 @@ IndexBuildsCoordinatorMongod::IndexBuildsCoordinatorMongod() }); } -void IndexBuildsCoordinatorMongod::shutdown() { +void IndexBuildsCoordinatorMongod::shutdown(OperationContext* opCtx) { // Stop new scheduling. _threadPool.shutdown(); // Wait for all active builds to stop. - waitForAllIndexBuildsToStopForShutdown(); + waitForAllIndexBuildsToStopForShutdown(opCtx); // Wait for active threads to finish. _threadPool.join(); diff --git a/src/mongo/db/index_builds_coordinator_mongod.h b/src/mongo/db/index_builds_coordinator_mongod.h index 6c2a89a7c72..86ee624e48b 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.h +++ b/src/mongo/db/index_builds_coordinator_mongod.h @@ -60,7 +60,7 @@ public: * Shuts down the thread pool, signals interrupt to all index builds, then waits for all of the * threads to finish. */ - void shutdown() override; + void shutdown(OperationContext* opCtx) override; /** * Sets up the in-memory and persisted state of the index build, then passes the build off to an diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index fc78c50798b..f3ec00571cf 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -86,7 +86,7 @@ void IndexBuildsCoordinatorMongodTest::setUp() { void IndexBuildsCoordinatorMongodTest::tearDown() { _indexBuildsCoord->verifyNoIndexBuilds_forTestOnly(); - _indexBuildsCoord->shutdown(); + _indexBuildsCoord->shutdown(operationContext()); _indexBuildsCoord.reset(); // All databases are dropped during tear down. CatalogTestFixture::tearDown(); diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index c6ea408d821..a4198d995c0 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -580,7 +580,7 @@ CollectionState IdempotencyTest::validate(const NamespaceString& nss) { if (collUUID) { // Allow in-progress indexes to complete before validating collection contents. IndexBuildsCoordinator::get(_opCtx.get()) - ->awaitNoIndexBuildInProgressForCollection(collUUID.get()); + ->awaitNoIndexBuildInProgressForCollection(_opCtx.get(), collUUID.get()); } { diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index ad6956aecc3..7084bc6efbd 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1508,7 +1508,7 @@ Status applyCommand_inlock(OperationContext* opCtx, Lock::TempRelease release(opCtx->lockState()); BackgroundOperation::awaitNoBgOpInProgForDb(nss.db()); - IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(nss.db()); + IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, nss.db()); opCtx->recoveryUnit()->abandonSnapshot(); opCtx->checkForInterrupt(); @@ -1542,7 +1542,7 @@ Status applyCommand_inlock(OperationContext* opCtx, } BackgroundOperation::awaitNoBgOpInProgForNs(ns); IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection( - swUUID.get()); + opCtx, swUUID.get()); opCtx->recoveryUnit()->abandonSnapshot(); opCtx->checkForInterrupt(); diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 733bec6f0a3..84f9b75ae03 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -374,7 +374,7 @@ void RollbackImpl::_stopAndWaitForIndexBuilds(OperationContext* opCtx) { (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator), "db"_attr = db); BackgroundOperation::awaitNoBgOpInProgForDb(db); - IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(db); + IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, db); } } diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp index d48597710cc..be754d5227f 100644 --- a/src/mongo/db/service_context_d_test_fixture.cpp +++ b/src/mongo/db/service_context_d_test_fixture.cpp @@ -91,8 +91,6 @@ ServiceContextMongoDTest::ServiceContextMongoDTest(std::string engine, RepairAct } ServiceContextMongoDTest::~ServiceContextMongoDTest() { - IndexBuildsCoordinator::get(getServiceContext())->shutdown(); - { auto opCtx = getClient()->makeOperationContext(); Lock::GlobalLock glk(opCtx.get(), MODE_X); @@ -116,6 +114,17 @@ void ServiceContextMongoDTest::setUp() { } void ServiceContextMongoDTest::tearDown() { + { + // Some tests set the current OperationContext but do not release it until destruction. + ServiceContext::UniqueOperationContext uniqueOpCtx; + auto opCtx = getClient()->getOperationContext(); + if (!opCtx) { + uniqueOpCtx = getClient()->makeOperationContext(); + opCtx = uniqueOpCtx.get(); + } + IndexBuildsCoordinator::get(opCtx)->shutdown(opCtx); + } + CollectionShardingStateFactory::clear(getServiceContext()); ServiceContextTest::tearDown(); diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index ab5076a5cfa..cd064e00b9c 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -1412,7 +1412,7 @@ public: ASSERT_EQ(lastTime.getTimestamp(), insertTime2.asTimestamp()); // Wait for the index build to finish before making any assertions. - IndexBuildsCoordinator::get(_opCtx)->awaitNoIndexBuildInProgressForCollection(uuid); + IndexBuildsCoordinator::get(_opCtx)->awaitNoIndexBuildInProgressForCollection(_opCtx, uuid); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp index 252a9a0fac7..8001b821549 100644 --- a/src/mongo/embedded/embedded.cpp +++ b/src/mongo/embedded/embedded.cpp @@ -169,7 +169,7 @@ void shutdown(ServiceContext* srvContext) { LogicalSessionCache::set(serviceContext, nullptr); repl::ReplicationCoordinator::get(serviceContext)->shutdown(shutdownOpCtx.get()); - IndexBuildsCoordinator::get(serviceContext)->shutdown(); + IndexBuildsCoordinator::get(serviceContext)->shutdown(shutdownOpCtx.get()); // Global storage engine may not be started in all cases before we exit if (serviceContext->getStorageEngine()) { diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.cpp b/src/mongo/embedded/index_builds_coordinator_embedded.cpp index 02b4b3378e7..36fb9b0725e 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.cpp +++ b/src/mongo/embedded/index_builds_coordinator_embedded.cpp @@ -40,7 +40,7 @@ namespace mongo { -void IndexBuildsCoordinatorEmbedded::shutdown() {} +void IndexBuildsCoordinatorEmbedded::shutdown(OperationContext* opCtx) {} StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> IndexBuildsCoordinatorEmbedded::startIndexBuild(OperationContext* opCtx, diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.h b/src/mongo/embedded/index_builds_coordinator_embedded.h index 06f39bba115..613a44c9d2a 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.h +++ b/src/mongo/embedded/index_builds_coordinator_embedded.h @@ -54,7 +54,7 @@ public: /** * Does nothing. */ - void shutdown() override; + void shutdown(OperationContext* opCtx) override; StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> startIndexBuild( OperationContext* opCtx, |