diff options
author | Benety Goh <benety@mongodb.com> | 2019-01-31 19:43:19 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-01-31 19:43:34 -0500 |
commit | 066d681d4c0377da30aa0fc262826d67e9b1ad69 (patch) | |
tree | 32b7374588544d04332fea07d4cd17a4a65f0dd2 | |
parent | 9606de0f0f3166b9c8fcff033f2476af2937f685 (diff) | |
download | mongo-066d681d4c0377da30aa0fc262826d67e9b1ad69.tar.gz |
SERVER-37643 update IndexBuildsCoordinator and IndexBuildsManager interfaces.
rename IndexBuildsCoordinator::buildIndex() to startIndexBuild()
add ReplIndexBuildState::dbName and use in IndexBuildsCoordinator registration
add IndexBuildsManager::isBackgroundBuilding()
remove unused IndexBuildsManager::finishConstraintPhase()
add IndexBuildsManager::drainBackgroundWrites()
remove nss argument from IndexBuildsManager::setUpIndexBuild()
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.h | 23 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/collection_index_builds_tracker.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 2 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.h | 2 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod_test.cpp | 86 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.h | 6 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.cpp | 13 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.h | 2 |
13 files changed, 110 insertions, 98 deletions
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index f908235ff68..b3d68b44f4d 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -49,7 +49,6 @@ IndexBuildsManager::~IndexBuildsManager() { Status IndexBuildsManager::setUpIndexBuild(OperationContext* opCtx, Collection* collection, - const NamespaceString& nss, const std::vector<BSONObj>& specs, const UUID& buildUUID) { _registerIndexBuild(opCtx, collection, buildUUID); @@ -76,7 +75,7 @@ Status IndexBuildsManager::startBuildingIndex(const UUID& buildUUID) { return Status::OK(); } -Status IndexBuildsManager::finishbBuildingPhase(const UUID& buildUUID) { +Status IndexBuildsManager::drainBackgroundWrites(const UUID& buildUUID) { auto multiIndexBlockPtr = _getBuilder(buildUUID); // TODO: verify that the index builder is in the expected state. @@ -85,7 +84,7 @@ Status IndexBuildsManager::finishbBuildingPhase(const UUID& buildUUID) { return Status::OK(); } -Status IndexBuildsManager::checkIndexConstraintViolations(const UUID& buildUUID) { +Status IndexBuildsManager::finishBuildingPhase(const UUID& buildUUID) { auto multiIndexBlockPtr = _getBuilder(buildUUID); // TODO: verify that the index builder is in the expected state. @@ -94,7 +93,7 @@ Status IndexBuildsManager::checkIndexConstraintViolations(const UUID& buildUUID) return Status::OK(); } -Status IndexBuildsManager::finishConstraintPhase(const UUID& buildUUID) { +Status IndexBuildsManager::checkIndexConstraintViolations(const UUID& buildUUID) { auto multiIndexBlockPtr = _getBuilder(buildUUID); // TODO: verify that the index builder is in the expected state. @@ -143,6 +142,11 @@ void IndexBuildsManager::tearDownIndexBuild(const UUID& buildUUID) { _unregisterIndexBuild(buildUUID); } +bool IndexBuildsManager::isBackgroundBuilding(const UUID& buildUUID) { + auto builder = _getBuilder(buildUUID); + return builder->isBackgroundBuilding(); +} + void IndexBuildsManager::verifyNoIndexBuilds_forTestOnly() { invariant(_builders.empty()); } diff --git a/src/mongo/db/catalog/index_builds_manager.h b/src/mongo/db/catalog/index_builds_manager.h index 809af63a466..84db234fbe9 100644 --- a/src/mongo/db/catalog/index_builds_manager.h +++ b/src/mongo/db/catalog/index_builds_manager.h @@ -67,7 +67,6 @@ public: */ Status setUpIndexBuild(OperationContext* opCtx, Collection* collection, - const NamespaceString& nss, const std::vector<BSONObj>& specs, const UUID& buildUUID); @@ -91,12 +90,18 @@ public: Status startBuildingIndex(const UUID& buildUUID); /** + * Document inserts observed during the scanning/insertion phase of an index build are not + * added but are instead stored in a temporary buffer until this function is invoked. + */ + Status drainBackgroundWrites(const UUID& buildUUID); + + /** * Persists information in the index catalog entry to reflect the successful completion of the * scanning/insertion phase. * * TODO: Not yet implemented. */ - Status finishbBuildingPhase(const UUID& buildUUID); + Status finishBuildingPhase(const UUID& buildUUID); /** * Runs the index constraint violation checking phase of the index build.. @@ -106,14 +111,6 @@ public: Status checkIndexConstraintViolations(const UUID& buildUUID); /** - * Persists information in the index catalog entry to reflect the successful completion of the - * index constraint violation checking phase.. - * - * TODO: Not yet implemented. - */ - Status finishConstraintPhase(const UUID& buildUUID); - - /** * Persists information in the index catalog entry that the index is ready for use, as well as * updating the in-memory index catalog entry for this index to ready. * @@ -153,6 +150,12 @@ public: void tearDownIndexBuild(const UUID& buildUUID); /** + * Returns true if the index build supports background writes while building an index. This is + * true for the kHybrid and kBackground methods. + */ + bool isBackgroundBuilding(const UUID& buildUUID); + + /** * Checks via invariant that the manager has no index builds presently. */ void verifyNoIndexBuilds_forTestOnly(); diff --git a/src/mongo/db/catalog/index_builds_manager_test.cpp b/src/mongo/db/catalog/index_builds_manager_test.cpp index 30d6aa5dc94..10326c77dd3 100644 --- a/src/mongo/db/catalog/index_builds_manager_test.cpp +++ b/src/mongo/db/catalog/index_builds_manager_test.cpp @@ -85,11 +85,8 @@ std::vector<BSONObj> makeSpecs(const NamespaceString& nss, std::vector<std::stri TEST_F(IndexBuildsManagerTest, IndexBuildsManagerSetUpAndTearDown) { AutoGetCollection autoColl(operationContext(), _nss, MODE_X); - ASSERT_OK(_indexBuildsManager.setUpIndexBuild(operationContext(), - autoColl.getCollection(), - _nss, - makeSpecs(_nss, {"a", "b"}), - _buildUUID)); + ASSERT_OK(_indexBuildsManager.setUpIndexBuild( + operationContext(), autoColl.getCollection(), makeSpecs(_nss, {"a", "b"}), _buildUUID)); _indexBuildsManager.tearDownIndexBuild(_buildUUID); } diff --git a/src/mongo/db/collection_index_builds_tracker.cpp b/src/mongo/db/collection_index_builds_tracker.cpp index 58b3fef7b1b..9ef10722691 100644 --- a/src/mongo/db/collection_index_builds_tracker.cpp +++ b/src/mongo/db/collection_index_builds_tracker.cpp @@ -49,7 +49,10 @@ void CollectionIndexBuildsTracker::addIndexBuild( invariant(replIndexBuildState->indexNames.size()); for (auto& indexName : replIndexBuildState->indexNames) { // Ensure that a new entry is added. - invariant(_buildStateByIndexName.emplace(indexName, replIndexBuildState).second); + invariant(_buildStateByIndexName.emplace(indexName, replIndexBuildState).second, + str::stream() << "index build state for " << indexName + << " already exists. Collection: " + << replIndexBuildState->collectionUUID); } } diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index b36916bf7fd..d0ccfa9ef41 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -287,20 +287,13 @@ Status IndexBuildsCoordinator::_registerIndexBuild( OperationContext* opCtx, std::shared_ptr<ReplIndexBuildState> replIndexBuildState) { stdx::unique_lock<stdx::mutex> lk(_mutex); - NamespaceString nss = - UUIDCatalog::get(opCtx).lookupNSSByUUID(replIndexBuildState->collectionUUID); - if (!nss.isValid()) { - return Status(ErrorCodes::NamespaceNotFound, - "The collection has been dropped since the index build began."); - } - auto itns = _disallowedCollections.find(replIndexBuildState->collectionUUID); - auto itdb = _disallowedDbs.find(nss.db()); + auto itdb = _disallowedDbs.find(replIndexBuildState->dbName); if (itns != _disallowedCollections.end() || itdb != _disallowedDbs.end()) { return Status(ErrorCodes::CannotCreateIndex, - str::stream() << "Collection '" << nss.toString() - << "' is in the process of being dropped. New index builds are " - "not currently allowed."); + str::stream() << "Collection ( " << replIndexBuildState->collectionUUID + << " ) is in the process of being dropped. New index builds " + "are not currently allowed."); } // Check whether any indexes are already being built with the same index name(s). (Duplicate @@ -311,17 +304,21 @@ Status IndexBuildsCoordinator::_registerIndexBuild( if (collIndexBuildsIt->second->hasIndexBuildState(lk, name)) { return Status(ErrorCodes::IndexKeySpecsConflict, str::stream() << "There's already an index with name '" << name - << "' being built on the collection"); + << "' being built on the collection: " + << " ( " + << replIndexBuildState->collectionUUID + << " )"); } } } // Register the index build. - auto dbIndexBuilds = _databaseIndexBuilds[nss.db()]; + auto dbIndexBuilds = _databaseIndexBuilds[replIndexBuildState->dbName]; if (!dbIndexBuilds) { - _databaseIndexBuilds[nss.db()] = std::make_shared<DatabaseIndexBuildsTracker>(); - dbIndexBuilds = _databaseIndexBuilds[nss.db()]; + _databaseIndexBuilds[replIndexBuildState->dbName] = + std::make_shared<DatabaseIndexBuildsTracker>(); + dbIndexBuilds = _databaseIndexBuilds[replIndexBuildState->dbName]; } dbIndexBuilds->addIndexBuild(lk, replIndexBuildState); @@ -338,15 +335,11 @@ void IndexBuildsCoordinator::_unregisterIndexBuild( WithLock lk, OperationContext* opCtx, std::shared_ptr<ReplIndexBuildState> replIndexBuildState) { - NamespaceString nss = - UUIDCatalog::get(opCtx).lookupNSSByUUID(replIndexBuildState->collectionUUID); - invariant(!nss.isEmpty()); - - auto dbIndexBuilds = _databaseIndexBuilds[nss.db()]; + auto dbIndexBuilds = _databaseIndexBuilds[replIndexBuildState->dbName]; invariant(dbIndexBuilds); dbIndexBuilds->removeIndexBuild(lk, replIndexBuildState->buildUUID); if (dbIndexBuilds->getNumberOfIndexBuilds(lk) == 0) { - _databaseIndexBuilds.erase(nss.db()); + _databaseIndexBuilds.erase(replIndexBuildState->dbName); } auto collIndexBuildsIt = _collectionIndexBuilds.find(replIndexBuildState->collectionUUID); diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index d6987f24864..ec61577268c 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -97,7 +97,7 @@ public: * * Returns an error status if there are any errors setting up the index build. */ - virtual StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + virtual StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> startIndexBuild( OperationContext* opCtx, CollectionUUID collectionUUID, const std::vector<BSONObj>& specs, diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 54789c9cba8..3dd3a1abfde 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -33,6 +33,7 @@ #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" @@ -79,10 +80,10 @@ void IndexBuildsCoordinatorMongod::shutdown() { } StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> -IndexBuildsCoordinatorMongod::buildIndex(OperationContext* opCtx, - CollectionUUID collectionUUID, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) { +IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, + CollectionUUID collectionUUID, + const std::vector<BSONObj>& specs, + const UUID& buildUUID) { std::vector<std::string> indexNames; for (auto& spec : specs) { std::string name = spec.getStringField(IndexDescriptor::kIndexNameFieldName); @@ -95,8 +96,10 @@ IndexBuildsCoordinatorMongod::buildIndex(OperationContext* opCtx, indexNames.push_back(name); } + auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(collectionUUID); + auto dbName = nss.db().toString(); auto replIndexBuildState = - std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, indexNames, specs); + std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, dbName, indexNames, specs); Status status = _registerIndexBuild(opCtx, replIndexBuildState); if (!status.isOK()) { diff --git a/src/mongo/db/index_builds_coordinator_mongod.h b/src/mongo/db/index_builds_coordinator_mongod.h index efca8bb628c..fc84ce9d04b 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.h +++ b/src/mongo/db/index_builds_coordinator_mongod.h @@ -69,7 +69,7 @@ public: * * Returns an error status if there are any errors setting up the index build. */ - StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> startIndexBuild( OperationContext* opCtx, CollectionUUID collectionUUID, const std::vector<BSONObj>& specs, diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index 0509dc66487..e0ea84738ad 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -103,14 +103,14 @@ TEST_F(IndexBuildsCoordinatorMongodTest, CannotBuildIndexWithSameIndexName) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(true); // Register an index build on _testFooNss. - auto testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( + auto testFoo1Future = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); // Attempt and fail to register an index build on _testFooNss with the same index name, while // the prior build is still running. ASSERT_EQ(ErrorCodes::IndexKeySpecsConflict, _indexBuildsCoord - ->buildIndex( + ->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"b"}), UUID::gen()) .getStatus()); @@ -126,7 +126,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(true); // Register an index build on _testFooNss. - auto testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( + auto testFoo1Future = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testFooNss.db()), 1); @@ -140,7 +140,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { ErrorCodes::BackgroundOperationInProgressForDatabase); // Register a second index build on _testFooNss. - auto testFoo2Future = assertGet(_indexBuildsCoord->buildIndex( + auto testFoo2Future = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"c", "d"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testFooNss.db()), 2); @@ -154,7 +154,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { ErrorCodes::BackgroundOperationInProgressForDatabase); // Register an index build on a different collection _testBarNss. - auto testBarFuture = assertGet(_indexBuildsCoord->buildIndex( + auto testBarFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testBarUUID, makeSpecs(_testBarNss, {"x", "y"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testBarNss.db()), 3); @@ -169,10 +169,10 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { // Register an index build on a collection in a different database _othertestFoo. auto othertestFooFuture = - assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooUUID, - makeSpecs(_othertestFooNss, {"r", "s"}), - UUID::gen())); + assertGet(_indexBuildsCoord->startIndexBuild(operationContext(), + _othertestFooUUID, + makeSpecs(_othertestFooNss, {"r", "s"}), + UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_othertestFooNss.db()), 1); ASSERT(_indexBuildsCoord->inProgForCollection(_othertestFooUUID)); @@ -227,20 +227,20 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { // Registering an index build on _testFooNss should fail. ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord - ->buildIndex(operationContext(), - _testFooUUID, - makeSpecs(_testFooNss, {"a", "b"}), - UUID::gen()) + ->startIndexBuild(operationContext(), + _testFooUUID, + makeSpecs(_testFooNss, {"a", "b"}), + UUID::gen()) .getStatus()); // Registering index builds on other collections and databases should still succeed. - auto testBarFuture = assertGet(_indexBuildsCoord->buildIndex( + auto testBarFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testBarUUID, makeSpecs(_testBarNss, {"c", "d"}), UUID::gen())); auto othertestFooFuture = - assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooUUID, - makeSpecs(_othertestFooNss, {"e", "f"}), - UUID::gen())); + assertGet(_indexBuildsCoord->startIndexBuild(operationContext(), + _othertestFooUUID, + makeSpecs(_othertestFooNss, {"e", "f"}), + UUID::gen())); _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); @@ -254,7 +254,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { { // Check that the scoped object correctly cleared. - auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( + auto testFooFuture = assertGet(_indexBuildsCoord->startIndexBuild( operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); @@ -270,25 +270,25 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { // Registering an index build on any collection in the 'test' database should fail. ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord - ->buildIndex(operationContext(), - _testFooUUID, - makeSpecs(_testFooNss, {"a", "b"}), - UUID::gen()) + ->startIndexBuild(operationContext(), + _testFooUUID, + makeSpecs(_testFooNss, {"a", "b"}), + UUID::gen()) .getStatus()); ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord - ->buildIndex(operationContext(), - _testBarUUID, - makeSpecs(_testBarNss, {"c", "d"}), - UUID::gen()) + ->startIndexBuild(operationContext(), + _testBarUUID, + makeSpecs(_testBarNss, {"c", "d"}), + UUID::gen()) .getStatus()); // Registering index builds on another database should still succeed. auto othertestFooFuture = - assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooUUID, - makeSpecs(_othertestFooNss, {"e", "f"}), - UUID::gen())); + assertGet(_indexBuildsCoord->startIndexBuild(operationContext(), + _othertestFooUUID, + makeSpecs(_othertestFooNss, {"g", "h"}), + UUID::gen())); _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); @@ -299,8 +299,8 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { { // Check that the scoped object correctly cleared. - auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + 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); @@ -315,25 +315,25 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord - ->buildIndex(operationContext(), - _testFooUUID, - makeSpecs(_testFooNss, {"a", "b"}), - UUID::gen()) + ->startIndexBuild(operationContext(), + _testFooUUID, + makeSpecs(_testFooNss, {"a", "b"}), + UUID::gen()) .getStatus()); } ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord - ->buildIndex(operationContext(), - _testFooUUID, - makeSpecs(_testFooNss, {"a", "b"}), - UUID::gen()) + ->startIndexBuild(operationContext(), + _testFooUUID, + makeSpecs(_testFooNss, {"a", "b"}), + UUID::gen()) .getStatus()); } { // Check that the scoped object correctly cleared. - auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + 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); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 6eac921e114..e669040ed0a 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -287,7 +287,7 @@ Status startIndexBuild(OperationContext* opCtx, return statusWithIndexes.getStatus(); } return IndexBuildsCoordinator::get(opCtx) - ->buildIndex(opCtx, collUUID, statusWithIndexes.getValue(), indexBuildUUID) + ->startIndexBuild(opCtx, collUUID, statusWithIndexes.getValue(), indexBuildUUID) .getStatus(); } diff --git a/src/mongo/db/repl_index_build_state.h b/src/mongo/db/repl_index_build_state.h index aa7ddd26830..57f4a4c1d92 100644 --- a/src/mongo/db/repl_index_build_state.h +++ b/src/mongo/db/repl_index_build_state.h @@ -55,10 +55,12 @@ namespace mongo { struct ReplIndexBuildState { ReplIndexBuildState(const UUID& indexBuildUUID, const UUID& collUUID, + const std::string& dbName, const std::vector<std::string> names, const std::vector<BSONObj>& specs) : buildUUID(indexBuildUUID), collectionUUID(collUUID), + dbName(dbName), indexNames(names), indexSpecs(specs) { // Verify that the given index names and index specs match. @@ -76,6 +78,10 @@ struct ReplIndexBuildState { // the collection UUID is used to maintain correct association. const UUID collectionUUID; + // Identifies the database containing the index being built. Unlike collections, databases + // cannot be renamed. + const std::string dbName; + // The names of the indexes being built. const std::vector<std::string> indexNames; diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.cpp b/src/mongo/embedded/index_builds_coordinator_embedded.cpp index 72437ac9f09..e27fe71c201 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.cpp +++ b/src/mongo/embedded/index_builds_coordinator_embedded.cpp @@ -33,6 +33,7 @@ #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" @@ -44,10 +45,10 @@ namespace mongo { void IndexBuildsCoordinatorEmbedded::shutdown() {} StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> -IndexBuildsCoordinatorEmbedded::buildIndex(OperationContext* opCtx, - CollectionUUID collectionUUID, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) { +IndexBuildsCoordinatorEmbedded::startIndexBuild(OperationContext* opCtx, + CollectionUUID collectionUUID, + const std::vector<BSONObj>& specs, + const UUID& buildUUID) { std::vector<std::string> indexNames; for (auto& spec : specs) { std::string name = spec.getStringField(IndexDescriptor::kIndexNameFieldName); @@ -60,8 +61,10 @@ IndexBuildsCoordinatorEmbedded::buildIndex(OperationContext* opCtx, indexNames.push_back(name); } + auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(collectionUUID); + auto dbName = nss.db().toString(); auto replIndexBuildState = - std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, indexNames, specs); + std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, dbName, indexNames, specs); Status status = _registerIndexBuild(opCtx, replIndexBuildState); if (!status.isOK()) { diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.h b/src/mongo/embedded/index_builds_coordinator_embedded.h index 5d9d96e16a1..b2ed40104cd 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.h +++ b/src/mongo/embedded/index_builds_coordinator_embedded.h @@ -56,7 +56,7 @@ public: */ void shutdown() override; - StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> startIndexBuild( OperationContext* opCtx, CollectionUUID collectionUUID, const std::vector<BSONObj>& specs, |