diff options
author | Benety Goh <benety@mongodb.com> | 2019-02-01 13:00:32 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-02-01 13:00:32 -0500 |
commit | 9be581f05602f7956ea8f501cbc774a6172c40f9 (patch) | |
tree | c0e3e7f501ef4d17c1a5779309886fe654171d77 | |
parent | 6c336b11e9f7665837211f89a428c4eb25617f43 (diff) | |
download | mongo-9be581f05602f7956ea8f501cbc774a6172c40f9.tar.gz |
SERVER-37643 implement IndexBuildsCoordinator::_runIndexBuild()
This provides a common implementation for _runIndexBuild in
IndexBuildsCoordinatorMongod and IndexBuildsCoordinatorEmbedded.
This commit also moves fail points from the createIndexes command to the
IndexBuildsCoordinator.
-rw-r--r-- | src/mongo/db/SConscript | 9 | ||||
-rw-r--r-- | src/mongo/db/commands/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 278 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 11 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 36 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.h | 5 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod_test.cpp | 46 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.cpp | 34 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.h | 3 |
10 files changed, 323 insertions, 105 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 4ece86d1ee3..ad4e1b37163 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -933,6 +933,7 @@ env.Library( ], LIBDEPS_PRIVATE=[ "$BUILD_DIR/mongo/db/catalog/commit_quorum_options", + '$BUILD_DIR/mongo/db/catalog/uuid_catalog', ], ) @@ -948,6 +949,14 @@ env.Library( '$BUILD_DIR/mongo/db/catalog_raii', "$BUILD_DIR/mongo/db/catalog/index_builds_manager", ], + LIBDEPS_PRIVATE=[ + 'db_raii', + '$BUILD_DIR/mongo/db/catalog/uuid_catalog', + '$BUILD_DIR/mongo/db/concurrency/lock_manager', + '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', + '$BUILD_DIR/mongo/db/s/sharding_api_d', + '$BUILD_DIR/mongo/util/fail_point', + ], ) env.CppUnitTest( diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 2cf363c4714..7bc9fe55b69 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -261,6 +261,7 @@ env.Library( '$BUILD_DIR/mongo/db/command_can_run_here', '$BUILD_DIR/mongo/db/commands', '$BUILD_DIR/mongo/db/curop_failpoint_helpers', + '$BUILD_DIR/mongo/db/index_builds_coordinator_interface', '$BUILD_DIR/mongo/db/ops/write_ops_exec', '$BUILD_DIR/mongo/db/pipeline/mongo_process_interface', '$BUILD_DIR/mongo/db/query_exec', diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 44f8bb228d3..f3238ab69a1 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -50,6 +50,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/op_observer.h" #include "mongo/db/ops/insert.h" #include "mongo/db/repl/repl_client_info.h" @@ -66,10 +67,6 @@ namespace mongo { -MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildFirstDrain); -MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildSecondDrain); -MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildDumpsInsertsFromBulk); - namespace { const StringData kIndexesFieldName = "indexes"_sd; diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 98ddd272158..c610e4f9c0d 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -33,17 +33,33 @@ #include "mongo/db/index_builds_coordinator.h" +#include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/catalog_raii.h" +#include "mongo/db/concurrency/locker.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/op_observer.h" #include "mongo/db/operation_context.h" +#include "mongo/db/repl/replication_coordinator.h" +#include "mongo/db/s/collection_sharding_state.h" +#include "mongo/db/s/database_sharding_state.h" #include "mongo/db/service_context.h" +#include "mongo/s/shard_key_pattern.h" +#include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" namespace mongo { +MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildFirstDrain); +MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildSecondDrain); +MONGO_FAIL_POINT_DEFINE(hangAfterIndexBuildDumpsInsertsFromBulk); + namespace { +constexpr auto kUniqueFieldName = "unique"_sd; +constexpr auto kKeyFieldName = "key"_sd; + /** * Returns the collection UUID for the given 'nss', or a NamespaceNotFound error. * @@ -60,6 +76,42 @@ StatusWith<UUID> getCollectionUUID(OperationContext* opCtx, const NamespaceStrin } /** + * Returns total number of indexes in collection. + */ +int getNumIndexesTotal(OperationContext* opCtx, Collection* collection) { + const auto& nss = collection->ns(); + invariant(opCtx->lockState()->isCollectionLockedForMode(nss.ns(), MODE_S), + str::stream() << "Unable to get index count because collection was not locked for " + "reading: " + << nss); + + auto indexCatalog = collection->getIndexCatalog(); + invariant(indexCatalog, str::stream() << "Collection is missing index catalog: " << nss.ns()); + + return indexCatalog->numIndexesTotal(opCtx); +} + +/** + * Checks if unique index specification is compatible with sharding configuration. + */ +void checkShardKeyRestrictions(OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& newIdxKey) { + invariant(opCtx->lockState()->isCollectionLockedForMode(nss.ns(), MODE_X)); + + const auto metadata = CollectionShardingState::get(opCtx, nss)->getCurrentMetadata(); + if (!metadata->isSharded()) + return; + + const ShardKeyPattern shardKeyPattern(metadata->getKeyPattern()); + uassert(ErrorCodes::CannotCreateIndex, + str::stream() << "cannot create unique index over " << newIdxKey + << " with shard key pattern " + << shardKeyPattern.toBSON(), + shardKeyPattern.isUniqueIndexCompatible(newIdxKey)); +} + +/** * Aborts the index build identified by the provided 'replIndexBuildState'. * * Sets a signal on the coordinator's repl index build state if the builder does not yet exist in @@ -352,6 +404,232 @@ void IndexBuildsCoordinator::_unregisterIndexBuild( invariant(_allIndexBuilds.erase(replIndexBuildState->buildUUID)); } +void IndexBuildsCoordinator::_runIndexBuild(OperationContext* opCtx, + const UUID& buildUUID) noexcept { + auto replState = [&] { + stdx::unique_lock<stdx::mutex> lk(_mutex); + auto it = _allIndexBuilds.find(buildUUID); + invariant(it != _allIndexBuilds.end()); + return it->second; + }(); + + const auto& collectionUUID = replState->collectionUUID; + NamespaceString nss; + auto status = Status::OK(); + ReplIndexBuildState::IndexCatalogStats indexCatalogStats; + bool mustTearDown = false; + + try { + auto& uuidCatalog = UUIDCatalog::get(opCtx); + nss = uuidCatalog.lookupNSSByUUID(collectionUUID); + log() << "Index builds manager starting: " << buildUUID << ": " << nss << " (" + << collectionUUID << ")"; + + uassert(ErrorCodes::NamespaceNotFound, + str::stream() << "Collection dropped: " << collectionUUID, + !nss.isEmpty()); + + // Do not use AutoGetOrCreateDb because we may relock the database in mode IX. + Lock::DBLock dbLock(opCtx, nss.db(), MODE_X); + + // Allow the strong lock acquisition above to be interrupted, but from this point forward do + // not allow locks or re-locks to be interrupted. + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); + + if (!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss)) { + uasserted(ErrorCodes::NotMaster, + str::stream() << "Not primary while creating indexes in " << nss.ns() << " (" + << collectionUUID + << ")"); + } + + auto collection = uuidCatalog.lookupCollectionByUUID(collectionUUID); + uassert(ErrorCodes::NamespaceNotFound, + str::stream() << "Collection not found for index build: " << buildUUID << ": " + << nss.ns() + << " (" + << collectionUUID + << ")", + collection); + + indexCatalogStats.numIndexesBefore = getNumIndexesTotal(opCtx, collection); + + auto specsWithCollationDefaults = uassertStatusOK( + collection->addCollationDefaultsToIndexSpecsForCreate(opCtx, replState->indexSpecs)); + + auto indexCatalog = collection->getIndexCatalog(); + auto specsToBuild = indexCatalog->removeExistingIndexes( + opCtx, specsWithCollationDefaults, /*throwOnError=*/true); + + // Exit early if all the indexes requested are present in the catalog. + uassert(ErrorCodes::IndexAlreadyExists, "no indexes to build", !specsToBuild.empty()); + + for (const BSONObj& specToBuild : specsToBuild) { + if (specToBuild[kUniqueFieldName].trueValue()) { + checkShardKeyRestrictions(opCtx, nss, specToBuild[kKeyFieldName].Obj()); + } + } + + { + stdx::unique_lock<stdx::mutex> lk(_mutex); + while (_sleepForTest) { + lk.unlock(); + sleepmillis(100); + lk.lock(); + } + } + + mustTearDown = true; + uassertStatusOK( + _indexBuildsManager.setUpIndexBuild(opCtx, collection, specsToBuild, buildUUID)); + + // If we're a background index, replace exclusive db lock with an intent lock, so that + // other readers and writers can proceed during this phase. + if (_indexBuildsManager.isBackgroundBuilding(buildUUID)) { + opCtx->recoveryUnit()->abandonSnapshot(); + dbLock.relockWithMode(MODE_IX); + } + + // Collection scan and insert into index, followed by a drain of writes received in the + // background. + { + Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_IX); + uassertStatusOK(_indexBuildsManager.startBuildingIndex(buildUUID)); + } + + if (MONGO_FAIL_POINT(hangAfterIndexBuildDumpsInsertsFromBulk)) { + log() << "Hanging after dumping inserts from bulk builder"; + MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangAfterIndexBuildDumpsInsertsFromBulk); + } + + // Perform the first drain while holding an intent lock. + { + opCtx->recoveryUnit()->abandonSnapshot(); + Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_IS); + + uassertStatusOK(_indexBuildsManager.drainBackgroundWrites(buildUUID)); + } + + if (MONGO_FAIL_POINT(hangAfterIndexBuildFirstDrain)) { + log() << "Hanging after index build first drain"; + MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangAfterIndexBuildFirstDrain); + } + + // Perform the second drain while stopping writes on the collection. + { + opCtx->recoveryUnit()->abandonSnapshot(); + Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_S); + + uassertStatusOK(_indexBuildsManager.drainBackgroundWrites(buildUUID)); + } + + if (MONGO_FAIL_POINT(hangAfterIndexBuildSecondDrain)) { + log() << "Hanging after index build second drain"; + MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangAfterIndexBuildSecondDrain); + } + + // Need to return db lock back to exclusive, to complete the index build. + if (_indexBuildsManager.isBackgroundBuilding(buildUUID)) { + opCtx->recoveryUnit()->abandonSnapshot(); + dbLock.relockWithMode(MODE_X); + + auto databaseHolder = DatabaseHolder::get(opCtx); + auto db = databaseHolder->getDb(opCtx, nss.db()); + if (db) { + DatabaseShardingState::get(db).checkDbVersion(opCtx); + } + + invariant(db, + str::stream() << "Databse not found to complete index build: " << buildUUID + << ": " + << nss.ns() + << " (" + << collectionUUID + << ")"); + invariant(db->getCollection(opCtx, nss), + str::stream() << "Collection not found to complete index build: " << buildUUID + << ": " + << nss.ns() + << " (" + << collectionUUID + << ")"); + } + + // Perform the third and final drain after releasing a shared lock and reacquiring an + // exclusive lock on the database. + uassertStatusOK(_indexBuildsManager.drainBackgroundWrites(buildUUID)); + + // Index constraint checking phase. + uassertStatusOK(_indexBuildsManager.checkIndexConstraintViolations(buildUUID)); + + // Commit index build. + auto onCommitFn = [opCtx, &nss, &collectionUUID](const BSONObj& spec) { + opCtx->getServiceContext()->getOpObserver()->onCreateIndex( + opCtx, nss, collectionUUID, spec, false); + }; + uassertStatusOK(_indexBuildsManager.commitIndexBuild(opCtx, nss, buildUUID, onCommitFn)); + + indexCatalogStats.numIndexesAfter = getNumIndexesTotal(opCtx, collection); + log() << "Index builds manager completed successfully: " << buildUUID << ": " << nss + << " ( " << collectionUUID + << " ). Index specs requested: " << replState->indexSpecs.size() + << ". Indexes in catalog before build: " << indexCatalogStats.numIndexesBefore + << ". Indexes in catalog after build: " << indexCatalogStats.numIndexesAfter; + } catch (const DBException& ex) { + status = ex.toStatus(); + if (ErrorCodes::IndexAlreadyExists == status) { + log() << "Index builds manager has no indexes to build because indexes already exist: " + << buildUUID << ": " << nss << " ( " << collectionUUID << " )"; + status = Status::OK(); + indexCatalogStats.numIndexesAfter = indexCatalogStats.numIndexesBefore; + } else { + log() << "Index builds manager failed: " << buildUUID << ": " << nss << " ( " + << collectionUUID << " ): " << status; + } + } + + // Index build is registered in manager regardless of IndexBuildsManager::setUpIndexBuild() + // result. + if (status.isOK()) { + // A successful index build means that all the requested indexes are now part of the + // catalog. + if (mustTearDown) { + _indexBuildsManager.tearDownIndexBuild(buildUUID); + } + } else if (mustTearDown) { + // If the index build fails, there's cleanup to do. This requires a MODE_X lock. + // Must have exclusive DB lock before we clean up the index build via MultiIndexBlock's + // destructor. + try { + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); + Lock::DBLock dbLock(opCtx, nss.db(), MODE_X); + _indexBuildsManager.tearDownIndexBuild(buildUUID); + } catch (DBException& ex) { + ex.addContext(str::stream() + << "Index builds manager failed to clean up partially built index: " + << buildUUID + << ": " + << nss + << " ( " + << collectionUUID + << " )"); + fassertNoTrace(51058, ex.toStatus()); + } + } + + stdx::unique_lock<stdx::mutex> lk(_mutex); + + _unregisterIndexBuild(lk, opCtx, replState); + + if (status.isOK()) { + replState->sharedPromise.emplaceValue(indexCatalogStats); + } else { + replState->sharedPromise.setError(status); + } + + return; +} + void IndexBuildsCoordinator::_stopIndexBuildsOnDatabase(StringData dbName) { stdx::unique_lock<stdx::mutex> lk(_mutex); diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index ff49ec539cb..be2266b6186 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -44,6 +44,7 @@ #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" #include "mongo/util/concurrency/with_lock.h" +#include "mongo/util/fail_point_service.h" #include "mongo/util/future.h" #include "mongo/util/net/hostandport.h" #include "mongo/util/uuid.h" @@ -306,9 +307,9 @@ protected: std::shared_ptr<ReplIndexBuildState> replIndexBuildState); /** - * TODO: not yet implemented. + * Runs the index build on the caller thread. */ - virtual void _runIndexBuild(OperationContext* opCtx, const UUID& buildUUID) noexcept = 0; + virtual void _runIndexBuild(OperationContext* opCtx, const UUID& buildUUID) noexcept; // Protects the below state. mutable stdx::mutex _mutex; @@ -405,4 +406,10 @@ private: UUID _collectionUUID; }; +// These fail points are used to control index build progress. Declared here to be shared +// temporarily between createIndexes command and IndexBuildsCoordinator. +MONGO_FAIL_POINT_DECLARE(hangAfterIndexBuildFirstDrain); +MONGO_FAIL_POINT_DECLARE(hangAfterIndexBuildSecondDrain); +MONGO_FAIL_POINT_DECLARE(hangAfterIndexBuildDumpsInsertsFromBulk); + } // namespace mongo diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 3dd3a1abfde..6b3677ee604 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -34,9 +34,9 @@ #include "mongo/db/index_builds_coordinator_mongod.h" #include "mongo/db/catalog/uuid_catalog.h" -#include "mongo/db/catalog_raii.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -165,40 +165,6 @@ Status IndexBuildsCoordinatorMongod::setCommitQuorum(const NamespaceString& nss, return Status::OK(); } -void IndexBuildsCoordinatorMongod::_runIndexBuild(OperationContext* opCtx, - const UUID& buildUUID) noexcept { - auto replState = [&] { - stdx::unique_lock<stdx::mutex> lk(_mutex); - auto it = _allIndexBuilds.find(buildUUID); - invariant(it != _allIndexBuilds.end()); - return it->second; - }(); - - { - stdx::unique_lock<stdx::mutex> lk(_mutex); - while (_sleepForTest) { - lk.unlock(); - sleepmillis(100); - lk.lock(); - } - } - - // TODO: create scoped object to create the index builder, then destroy the builder, set the - // promises and unregister the build. - - // TODO: implement. - - stdx::unique_lock<stdx::mutex> lk(_mutex); - - _unregisterIndexBuild(lk, opCtx, replState); - - // TODO(SERVER-37643): Fill in index catalog stats. - ReplIndexBuildState::IndexCatalogStats indexCatalogStats; - replState->sharedPromise.emplaceValue(indexCatalogStats); - - return; -} - Status IndexBuildsCoordinatorMongod::_finishScanningPhase() { // TODO: implement. return Status::OK(); diff --git a/src/mongo/db/index_builds_coordinator_mongod.h b/src/mongo/db/index_builds_coordinator_mongod.h index fc84ce9d04b..fe62eb70323 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.h +++ b/src/mongo/db/index_builds_coordinator_mongod.h @@ -107,11 +107,6 @@ private: /** * TODO: not yet implemented. */ - void _runIndexBuild(OperationContext* opCtx, const UUID& buildUUID) noexcept override; - - /** - * TODO: not yet implemented. - */ Status _finishScanningPhase(); /** diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index e0ea84738ad..7f22c59bf5b 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -116,8 +116,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, CannotBuildIndexWithSameIndexName) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); auto indexCatalogStats = unittest::assertGet(testFoo1Future.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); } // Incrementally registering index builds and checking both that the registration was successful and @@ -187,20 +187,22 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); auto indexCatalogStats = unittest::assertGet(testFoo1Future.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_GTE(indexCatalogStats.numIndexesBefore, 1); + ASSERT_GT(indexCatalogStats.numIndexesAfter, 1); + ASSERT_LTE(indexCatalogStats.numIndexesAfter, 5); indexCatalogStats = unittest::assertGet(testFoo2Future.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_GTE(indexCatalogStats.numIndexesBefore, 1); + ASSERT_GT(indexCatalogStats.numIndexesAfter, 1); + ASSERT_LTE(indexCatalogStats.numIndexesAfter, 5); indexCatalogStats = unittest::assertGet(testBarFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID); _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testBarUUID); @@ -245,11 +247,11 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); auto indexCatalogStats = unittest::assertGet(testBarFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); } { @@ -257,8 +259,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { auto testFooFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(1, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(3, indexCatalogStats.numIndexesAfter); } { @@ -293,8 +295,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); auto indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(3, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(5, indexCatalogStats.numIndexesAfter); } { @@ -302,8 +304,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { auto testFooFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"c", "d"}), UUID::gen())); auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(3, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(5, indexCatalogStats.numIndexesAfter); } { @@ -335,8 +337,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { auto testFooFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"e", "f"}), UUID::gen())); auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); - ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); - ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + ASSERT_EQ(5, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(7, indexCatalogStats.numIndexesAfter); } } diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.cpp b/src/mongo/embedded/index_builds_coordinator_embedded.cpp index e27fe71c201..08d6ffd311a 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.cpp +++ b/src/mongo/embedded/index_builds_coordinator_embedded.cpp @@ -34,7 +34,6 @@ #include "mongo/embedded/index_builds_coordinator_embedded.h" #include "mongo/db/catalog/uuid_catalog.h" -#include "mongo/db/catalog_raii.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/util/log.h" @@ -105,37 +104,4 @@ Status IndexBuildsCoordinatorEmbedded::setCommitQuorum(const NamespaceString& ns MONGO_UNREACHABLE; } -void IndexBuildsCoordinatorEmbedded::_runIndexBuild(OperationContext* opCtx, - const UUID& buildUUID) noexcept { - auto replState = [&] { - stdx::unique_lock<stdx::mutex> lk(_mutex); - auto it = _allIndexBuilds.find(buildUUID); - invariant(it != _allIndexBuilds.end()); - return it->second; - }(); - - { - stdx::unique_lock<stdx::mutex> lk(_mutex); - while (_sleepForTest) { - lk.unlock(); - sleepmillis(100); - lk.lock(); - } - } - - // TODO: create scoped object to create the index builder, then destroy the builder, set the - // promises and unregister the build. - - // TODO: implement. - - stdx::unique_lock<stdx::mutex> lk(_mutex); - - _unregisterIndexBuild(lk, opCtx, replState); - - ReplIndexBuildState::IndexCatalogStats indexCatalogStats; - replState->sharedPromise.emplaceValue(indexCatalogStats); - - return; -} - } // namespace mongo diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.h b/src/mongo/embedded/index_builds_coordinator_embedded.h index b2ed40104cd..76f13c811ea 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.h +++ b/src/mongo/embedded/index_builds_coordinator_embedded.h @@ -75,9 +75,6 @@ public: Status setCommitQuorum(const NamespaceString& nss, const std::vector<StringData>& indexNames, const CommitQuorumOptions& newCommitQuorum) override; - -private: - void _runIndexBuild(OperationContext* opCtx, const UUID& buildUUID) noexcept override; }; } // namespace mongo |