diff options
author | Benety Goh <benety@mongodb.com> | 2019-01-18 13:45:34 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-01-18 13:45:34 -0500 |
commit | 94ca845476a61c9a97ae119bb4d0bf2a045fe16f (patch) | |
tree | ca1394ff459376572881e295c35822e31b96dc05 /src/mongo | |
parent | be38d61492a125883dbdc111f331661a24b09e35 (diff) | |
download | mongo-94ca845476a61c9a97ae119bb4d0bf2a045fe16f.tar.gz |
SERVER-37643 refine IndexBuildsCoordinator and IndexBuildsManager interfaces to support createIndexes refactor
extend IndexBuildsCoordinatorMongodTest::createCollection() to accept collection UUID
IndexBuildsCoordinator::buildIndex() returns index catalog stats
IndexBuildsCoordinator::buildIndex() accepts collection UUID instead of namespace
IndexBuildsManager::commitIndexBuild() accepts callback for index builds
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.h | 7 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 13 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.h | 9 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod_test.cpp | 165 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.h | 6 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.cpp | 18 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.h | 9 |
9 files changed, 143 insertions, 108 deletions
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index e6d2b402861..f908235ff68 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -103,7 +103,10 @@ Status IndexBuildsManager::finishConstraintPhase(const UUID& buildUUID) { return Status::OK(); } -Status IndexBuildsManager::commitIndexBuild(const UUID& buildUUID) { +Status IndexBuildsManager::commitIndexBuild(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& buildUUID, + OnCommitFn onCommitFn) { auto multiIndexBlockPtr = _getBuilder(buildUUID); // TODO: verify that the index builder is in the expected state. diff --git a/src/mongo/db/catalog/index_builds_manager.h b/src/mongo/db/catalog/index_builds_manager.h index eb388b84d6c..809af63a466 100644 --- a/src/mongo/db/catalog/index_builds_manager.h +++ b/src/mongo/db/catalog/index_builds_manager.h @@ -36,6 +36,7 @@ #include "mongo/base/disallow_copying.h" #include "mongo/db/catalog/multi_index_block.h" #include "mongo/db/namespace_string.h" +#include "mongo/stdx/functional.h" #include "mongo/stdx/mutex.h" namespace mongo { @@ -118,7 +119,11 @@ public: * * TODO: Not yet implemented. */ - Status commitIndexBuild(const UUID& buildUUID); + using OnCommitFn = stdx::function<void(const BSONObj& spec)>; + Status commitIndexBuild(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& buildUUID, + OnCommitFn onCommitFn); /** * Signals the index build to be aborted and returns without waiting for completion. diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index 09833b664e1..d7e90547e11 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -34,6 +34,7 @@ #include <vector> #include "mongo/base/string_data.h" +#include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/index_builds_manager.h" #include "mongo/db/collection_index_builds_tracker.h" #include "mongo/db/database_index_builds_tracker.h" @@ -90,12 +91,16 @@ public: * Sets up the in-memory and persisted state of the index build. A Future is returned upon which * the user can await the build result. * + * On a successful index build, calling Future::get(), or Future::getNoThrows(), returns index + * catalog statistics. + * * Returns an error status if there are any errors setting up the index build. */ - virtual StatusWith<SharedSemiFuture<void>> buildIndex(OperationContext* opCtx, - const NamespaceString& nss, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) = 0; + virtual StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + OperationContext* opCtx, + CollectionUUID collectionUUID, + const std::vector<BSONObj>& specs, + const UUID& buildUUID) = 0; /** * TODO: not yet implemented. diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index eb7c6281e4e..d74647a5dae 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -78,11 +78,11 @@ void IndexBuildsCoordinatorMongod::shutdown() { _threadPool.join(); } -StatusWith<SharedSemiFuture<void>> IndexBuildsCoordinatorMongod::buildIndex( - OperationContext* opCtx, - const NamespaceString& nss, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) { +StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> +IndexBuildsCoordinatorMongod::buildIndex(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,11 +95,6 @@ StatusWith<SharedSemiFuture<void>> IndexBuildsCoordinatorMongod::buildIndex( indexNames.push_back(name); } - UUID collectionUUID = [&] { - AutoGetCollection autoColl(opCtx, nss, MODE_IS); - return autoColl.getCollection()->uuid().get(); - }(); - auto replIndexBuildState = std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, indexNames, specs); @@ -187,7 +182,9 @@ void IndexBuildsCoordinatorMongod::_runIndexBuild(OperationContext* opCtx, _unregisterIndexBuild(lk, opCtx, replState); - replState->sharedPromise.emplaceValue(); + // TODO(SERVER-37643): Fill in index catalog stats. + ReplIndexBuildState::IndexCatalogStats indexCatalogStats; + replState->sharedPromise.emplaceValue(indexCatalogStats); return; } diff --git a/src/mongo/db/index_builds_coordinator_mongod.h b/src/mongo/db/index_builds_coordinator_mongod.h index 57fcb2e9054..a3fc80d90a7 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.h +++ b/src/mongo/db/index_builds_coordinator_mongod.h @@ -69,10 +69,11 @@ public: * * Returns an error status if there are any errors setting up the index build. */ - StatusWith<SharedSemiFuture<void>> buildIndex(OperationContext* opCtx, - const NamespaceString& nss, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) override; + StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + OperationContext* opCtx, + CollectionUUID collectionUUID, + const std::vector<BSONObj>& specs, + const UUID& buildUUID) override; void signalChangeToPrimaryMode() override; void signalChangeToSecondaryMode() override; diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index 9080c1add23..0509dc66487 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -32,6 +32,7 @@ #include "mongo/db/index_builds_coordinator_mongod.h" #include "mongo/db/catalog/catalog_test_fixture.h" +#include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" @@ -50,19 +51,25 @@ private: void tearDown() override; public: - void createCollection(const NamespaceString& nss); + /** + * Creates a collection with a default CollectionsOptions and the given UUID. + */ + void createCollection(const NamespaceString& nss, CollectionUUID uuid); + const CollectionUUID _testFooUUID = UUID::gen(); const NamespaceString _testFooNss = NamespaceString("test.foo"); + const CollectionUUID _testBarUUID = UUID::gen(); const NamespaceString _testBarNss = NamespaceString("test.bar"); + const CollectionUUID _othertestFooUUID = UUID::gen(); const NamespaceString _othertestFooNss = NamespaceString("othertest.foo"); std::unique_ptr<IndexBuildsCoordinator> _indexBuildsCoord; }; void IndexBuildsCoordinatorMongodTest::setUp() { CatalogTestFixture::setUp(); - createCollection(_testFooNss); - createCollection(_testBarNss); - createCollection(_othertestFooNss); + createCollection(_testFooNss, _testFooUUID); + createCollection(_testBarNss, _testBarUUID); + createCollection(_othertestFooNss, _othertestFooUUID); _indexBuildsCoord = std::make_unique<IndexBuildsCoordinatorMongod>(); } @@ -74,15 +81,11 @@ void IndexBuildsCoordinatorMongodTest::tearDown() { CatalogTestFixture::tearDown(); } -void IndexBuildsCoordinatorMongodTest::createCollection(const NamespaceString& nss) { - ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, CollectionOptions())); -} - -UUID getCollectionUUID(OperationContext* opCtx, const NamespaceString& nss) { - AutoGetCollection autoColl(opCtx, nss, MODE_IS); - Collection* coll = autoColl.getCollection(); - ASSERT(coll); - return coll->uuid().get(); +void IndexBuildsCoordinatorMongodTest::createCollection(const NamespaceString& nss, + CollectionUUID uuid) { + CollectionOptions options; + options.uuid = uuid; + ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, options)); } std::vector<BSONObj> makeSpecs(const NamespaceString& nss, std::vector<std::string> keys) { @@ -100,19 +103,21 @@ TEST_F(IndexBuildsCoordinatorMongodTest, CannotBuildIndexWithSameIndexName) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(true); // Register an index build on _testFooNss. - SharedSemiFuture<void> testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + auto testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( + 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( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"b"}), UUID::gen()) + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"b"}), UUID::gen()) .getStatus()); _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); - ASSERT_OK(testFoo1Future.getNoThrow()); + auto indexCatalogStats = unittest::assertGet(testFoo1Future.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); } // Incrementally registering index builds and checking both that the registration was successful and @@ -121,14 +126,13 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(true); // Register an index build on _testFooNss. - UUID testFooUUID = getCollectionUUID(operationContext(), _testFooNss); - SharedSemiFuture<void> testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + auto testFoo1Future = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testFooNss.db()), 1); - ASSERT(_indexBuildsCoord->inProgForCollection(testFooUUID)); + ASSERT(_indexBuildsCoord->inProgForCollection(_testFooUUID)); ASSERT(_indexBuildsCoord->inProgForDb(_testFooNss.db())); - ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(testFooUUID), + ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID), AssertionException, ErrorCodes::BackgroundOperationInProgressForNamespace); ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoBgOpInProgForDb(_testFooNss.db()), @@ -136,13 +140,13 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { ErrorCodes::BackgroundOperationInProgressForDatabase); // Register a second index build on _testFooNss. - SharedSemiFuture<void> testFoo2Future = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"c", "d"}), UUID::gen())); + auto testFoo2Future = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"c", "d"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testFooNss.db()), 2); - ASSERT(_indexBuildsCoord->inProgForCollection(testFooUUID)); + ASSERT(_indexBuildsCoord->inProgForCollection(_testFooUUID)); ASSERT(_indexBuildsCoord->inProgForDb(_testFooNss.db())); - ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(testFooUUID), + ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID), AssertionException, ErrorCodes::BackgroundOperationInProgressForNamespace); ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoBgOpInProgForDb(_testFooNss.db()), @@ -150,14 +154,13 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { ErrorCodes::BackgroundOperationInProgressForDatabase); // Register an index build on a different collection _testBarNss. - UUID testBarUUID = getCollectionUUID(operationContext(), _testBarNss); - SharedSemiFuture<void> testBarFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testBarNss, makeSpecs(_testBarNss, {"x", "y"}), UUID::gen())); + auto testBarFuture = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testBarUUID, makeSpecs(_testBarNss, {"x", "y"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testBarNss.db()), 3); - ASSERT(_indexBuildsCoord->inProgForCollection(testBarUUID)); + ASSERT(_indexBuildsCoord->inProgForCollection(_testBarUUID)); ASSERT(_indexBuildsCoord->inProgForDb(_testBarNss.db())); - ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(testBarUUID), + ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testBarUUID), AssertionException, ErrorCodes::BackgroundOperationInProgressForNamespace); ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoBgOpInProgForDb(_testBarNss.db()), @@ -165,17 +168,16 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { ErrorCodes::BackgroundOperationInProgressForDatabase); // Register an index build on a collection in a different database _othertestFoo. - UUID othertestFooUUID = getCollectionUUID(operationContext(), _othertestFooNss); - SharedSemiFuture<void> othertestFooFuture = + auto othertestFooFuture = assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooNss, + _othertestFooUUID, makeSpecs(_othertestFooNss, {"r", "s"}), UUID::gen())); ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_othertestFooNss.db()), 1); - ASSERT(_indexBuildsCoord->inProgForCollection(othertestFooUUID)); + ASSERT(_indexBuildsCoord->inProgForCollection(_othertestFooUUID)); ASSERT(_indexBuildsCoord->inProgForDb(_othertestFooNss.db())); - ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(othertestFooUUID), + ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(_othertestFooUUID), AssertionException, ErrorCodes::BackgroundOperationInProgressForNamespace); ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoBgOpInProgForDb(_othertestFooNss.db()), @@ -184,14 +186,25 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); - ASSERT_OK(testFoo1Future.getNoThrow()); - ASSERT_OK(testFoo2Future.getNoThrow()); - ASSERT_OK(testBarFuture.getNoThrow()); - ASSERT_OK(othertestFooFuture.getNoThrow()); + auto indexCatalogStats = unittest::assertGet(testFoo1Future.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + + indexCatalogStats = unittest::assertGet(testFoo2Future.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); - _indexBuildsCoord->assertNoIndexBuildInProgForCollection(testFooUUID); - _indexBuildsCoord->assertNoIndexBuildInProgForCollection(testBarUUID); - _indexBuildsCoord->assertNoIndexBuildInProgForCollection(othertestFooUUID); + indexCatalogStats = unittest::assertGet(testBarFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + + indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + + _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID); + _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testBarUUID); + _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_othertestFooUUID); _indexBuildsCoord->assertNoBgOpInProgForDb(_testFooNss.db()); _indexBuildsCoord->assertNoBgOpInProgForDb(_othertestFooNss.db()); @@ -205,43 +218,47 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) { // ScopedStopNewCollectionIndexBuilds and ScopedStopNewDatabaseIndexBuilds are present on a // collection or database name. TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { - UUID testFooUUID = getCollectionUUID(operationContext(), _testFooNss); - { _indexBuildsCoord->sleepIndexBuilds_forTestOnly(true); // Create a scoped object to block new index builds ONLY on _testFooNss. - ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), testFooUUID); + ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), _testFooUUID); // Registering an index build on _testFooNss should fail. ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord ->buildIndex(operationContext(), - _testFooNss, + _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen()) .getStatus()); // Registering index builds on other collections and databases should still succeed. - SharedSemiFuture<void> testBarFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testBarNss, makeSpecs(_testBarNss, {"c", "d"}), UUID::gen())); - SharedSemiFuture<void> othertestFooFuture = + auto testBarFuture = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testBarUUID, makeSpecs(_testBarNss, {"c", "d"}), UUID::gen())); + auto othertestFooFuture = assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooNss, + _othertestFooUUID, makeSpecs(_othertestFooNss, {"e", "f"}), UUID::gen())); _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); - ASSERT_OK(testBarFuture.getNoThrow()); - ASSERT_OK(othertestFooFuture.getNoThrow()); + auto indexCatalogStats = unittest::assertGet(testBarFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); + indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); } { // Check that the scoped object correctly cleared. - SharedSemiFuture<void> testFooFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); - ASSERT_OK(testFooFuture.getNoThrow()); + auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); } { @@ -254,48 +271,52 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord ->buildIndex(operationContext(), - _testFooNss, + _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen()) .getStatus()); ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord ->buildIndex(operationContext(), - _testBarNss, + _testBarUUID, makeSpecs(_testBarNss, {"c", "d"}), UUID::gen()) .getStatus()); // Registering index builds on another database should still succeed. - SharedSemiFuture<void> othertestFooFuture = + auto othertestFooFuture = assertGet(_indexBuildsCoord->buildIndex(operationContext(), - _othertestFooNss, + _othertestFooUUID, makeSpecs(_othertestFooNss, {"e", "f"}), UUID::gen())); _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false); - ASSERT_OK(othertestFooFuture.getNoThrow()); + auto indexCatalogStats = unittest::assertGet(othertestFooFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); } { // Check that the scoped object correctly cleared. - SharedSemiFuture<void> testFooFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); - ASSERT_OK(testFooFuture.getNoThrow()); + auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); + auto indexCatalogStats = unittest::assertGet(testFooFuture.getNoThrow()); + ASSERT_EQ(0, indexCatalogStats.numIndexesBefore); + ASSERT_EQ(0, indexCatalogStats.numIndexesAfter); } { // Test concurrency of multiple scoped objects to block an index builds. - ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), testFooUUID); + ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), _testFooUUID); { - ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), testFooUUID); + ScopedStopNewCollectionIndexBuilds scopedStop(_indexBuildsCoord.get(), _testFooUUID); ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord ->buildIndex(operationContext(), - _testFooNss, + _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen()) .getStatus()); @@ -303,7 +324,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { ASSERT_EQ(ErrorCodes::CannotCreateIndex, _indexBuildsCoord ->buildIndex(operationContext(), - _testFooNss, + _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen()) .getStatus()); @@ -311,9 +332,11 @@ TEST_F(IndexBuildsCoordinatorMongodTest, DisallowNewBuildsOnNamespace) { { // Check that the scoped object correctly cleared. - SharedSemiFuture<void> testFooFuture = assertGet(_indexBuildsCoord->buildIndex( - operationContext(), _testFooNss, makeSpecs(_testFooNss, {"a", "b"}), UUID::gen())); - ASSERT_OK(testFooFuture.getNoThrow()); + auto testFooFuture = assertGet(_indexBuildsCoord->buildIndex( + operationContext(), _testFooUUID, makeSpecs(_testFooNss, {"a", "b"}), 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_index_build_state.h b/src/mongo/db/repl_index_build_state.h index a075757feaa..aa7ddd26830 100644 --- a/src/mongo/db/repl_index_build_state.h +++ b/src/mongo/db/repl_index_build_state.h @@ -104,7 +104,11 @@ struct ReplIndexBuildState { // Communicates the final outcome of the index build to any callers waiting upon the associated // SharedSemiFuture(s). - SharedPromise<void> sharedPromise; + using IndexCatalogStats = struct { + int numIndexesBefore = 0; + int numIndexesAfter = 0; + }; + SharedPromise<IndexCatalogStats> sharedPromise; // There is a period of time where the index build is registered on the coordinator, but an // index builder does not yet exist. Since a signal cannot be set on the index builder at that diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.cpp b/src/mongo/embedded/index_builds_coordinator_embedded.cpp index 5e3b3ed172b..aa161e947e1 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.cpp +++ b/src/mongo/embedded/index_builds_coordinator_embedded.cpp @@ -43,11 +43,11 @@ namespace mongo { void IndexBuildsCoordinatorEmbedded::shutdown() {} -StatusWith<SharedSemiFuture<void>> IndexBuildsCoordinatorEmbedded::buildIndex( - OperationContext* opCtx, - const NamespaceString& nss, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) { +StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> +IndexBuildsCoordinatorEmbedded::buildIndex(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,11 +60,6 @@ StatusWith<SharedSemiFuture<void>> IndexBuildsCoordinatorEmbedded::buildIndex( indexNames.push_back(name); } - UUID collectionUUID = [&] { - AutoGetCollection autoColl(opCtx, nss, MODE_IS); - return autoColl.getCollection()->uuid().get(); - }(); - auto replIndexBuildState = std::make_shared<ReplIndexBuildState>(buildUUID, collectionUUID, indexNames, specs); @@ -128,7 +123,8 @@ void IndexBuildsCoordinatorEmbedded::_runIndexBuild(OperationContext* opCtx, _unregisterIndexBuild(lk, opCtx, replState); - replState->sharedPromise.emplaceValue(); + ReplIndexBuildState::IndexCatalogStats indexCatalogStats; + replState->sharedPromise.emplaceValue(indexCatalogStats); return; } diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.h b/src/mongo/embedded/index_builds_coordinator_embedded.h index 5dfbc739bd1..a5d2b9b207a 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.h +++ b/src/mongo/embedded/index_builds_coordinator_embedded.h @@ -56,10 +56,11 @@ public: */ void shutdown() override; - StatusWith<SharedSemiFuture<void>> buildIndex(OperationContext* opCtx, - const NamespaceString& nss, - const std::vector<BSONObj>& specs, - const UUID& buildUUID) override; + StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> buildIndex( + OperationContext* opCtx, + CollectionUUID collectionUUID, + const std::vector<BSONObj>& specs, + const UUID& buildUUID) override; /** * None of the following functions should ever be called on an embedded server node. |