summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-06-02 18:59:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-08 10:51:13 +0000
commit365bc0d0c03c6e4b6e6964a72b260b25c4e5b936 (patch)
tree795213941ddf9b351d2bd87e798ab8ffefc302dc /src/mongo/db
parent3850ee3c8c71bcf55080ab212aee81f542e94f2b (diff)
downloadmongo-365bc0d0c03c6e4b6e6964a72b260b25c4e5b936.tar.gz
SERVER-66520 add index build UUID to BackgroundOperationInProgress message
(cherry picked from commit d6a12bacdc9ebee0f4813d3f0a81252aa4f519bb)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/active_index_builds.cpp14
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp40
-rw-r--r--src/mongo/db/index_builds_coordinator_mongod_test.cpp20
3 files changed, 53 insertions, 21 deletions
diff --git a/src/mongo/db/active_index_builds.cpp b/src/mongo/db/active_index_builds.cpp
index 017ca49ecc8..d6a7f5afabf 100644
--- a/src/mongo/db/active_index_builds.cpp
+++ b/src/mongo/db/active_index_builds.cpp
@@ -28,6 +28,8 @@
*/
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage
+#include <fmt/format.h>
+
#include "mongo/db/active_index_builds.h"
#include "mongo/db/catalog/index_builds_manager.h"
#include "mongo/logv2/log.h"
@@ -63,10 +65,14 @@ void ActiveIndexBuilds::waitForAllIndexBuildsToStopForShutdown(OperationContext*
void ActiveIndexBuilds::assertNoIndexBuildInProgress() const {
stdx::unique_lock<Latch> lk(_mutex);
- uassert(ErrorCodes::BackgroundOperationInProgressForDatabase,
- str::stream() << "cannot perform operation: there are currently "
- << _allIndexBuilds.size() << " index builds running.",
- _allIndexBuilds.size() == 0);
+ if (!_allIndexBuilds.empty()) {
+ auto firstIndexBuild = _allIndexBuilds.cbegin()->second;
+ uasserted(ErrorCodes::BackgroundOperationInProgressForDatabase,
+ fmt::format("cannot perform operation: there are currently {} index builds "
+ "running. Found index build: {}",
+ _allIndexBuilds.size(),
+ firstIndexBuild->buildUUID.toString()));
+ }
}
void ActiveIndexBuilds::waitUntilAnIndexBuildFinishes(OperationContext* opCtx) {
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 71d89d8325c..643e5942d98 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -29,10 +29,10 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage
-#include "mongo/platform/basic.h"
-
#include "mongo/db/index_builds_coordinator.h"
+#include <fmt/format.h>
+
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/commit_quorum_options.h"
#include "mongo/db/catalog/database_holder.h"
@@ -1572,19 +1572,39 @@ void IndexBuildsCoordinator::assertNoIndexBuildInProgress() const {
void IndexBuildsCoordinator::assertNoIndexBuildInProgForCollection(
const UUID& collectionUUID) const {
+ boost::optional<UUID> firstIndexBuildUUID;
+ auto indexBuilds = activeIndexBuilds.filterIndexBuilds([&](const auto& replState) {
+ auto isIndexBuildForCollection = (collectionUUID == replState.collectionUUID);
+ if (isIndexBuildForCollection && !firstIndexBuildUUID) {
+ firstIndexBuildUUID = replState.buildUUID;
+ };
+ return isIndexBuildForCollection;
+ });
+
uassert(ErrorCodes::BackgroundOperationInProgressForNamespace,
- str::stream() << "cannot perform operation: an index build is currently running for "
- "collection with UUID: "
- << collectionUUID,
- !inProgForCollection(collectionUUID));
+ fmt::format("cannot perform operation: an index build is currently running for "
+ "collection with UUID: {}. Found index build: {}",
+ collectionUUID.toString(),
+ firstIndexBuildUUID->toString()),
+ indexBuilds.empty());
}
void IndexBuildsCoordinator::assertNoBgOpInProgForDb(StringData db) const {
+ boost::optional<UUID> firstIndexBuildUUID;
+ auto indexBuilds = activeIndexBuilds.filterIndexBuilds([&](const auto& replState) {
+ auto isIndexBuildForCollection = (db == replState.dbName);
+ if (isIndexBuildForCollection && !firstIndexBuildUUID) {
+ firstIndexBuildUUID = replState.buildUUID;
+ };
+ return isIndexBuildForCollection;
+ });
+
uassert(ErrorCodes::BackgroundOperationInProgressForDatabase,
- str::stream() << "cannot perform operation: an index build is currently running for "
- "database "
- << db,
- !inProgForDb(db));
+ fmt::format("cannot perform operation: an index build is currently running for "
+ "database {}. Found index build: {}",
+ db,
+ firstIndexBuildUUID->toString()),
+ indexBuilds.empty());
}
void IndexBuildsCoordinator::awaitNoIndexBuildInProgressForCollection(OperationContext* opCtx,
diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp
index 3f920324329..f2e3b862e00 100644
--- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp
+++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp
@@ -81,6 +81,9 @@ void IndexBuildsCoordinatorMongodTest::setUp() {
}
void IndexBuildsCoordinatorMongodTest::tearDown() {
+ // Resume index builds left running by test failures so that shutdown() will not block.
+ _indexBuildsCoord->sleepIndexBuilds_forTestOnly(false);
+
_indexBuildsCoord->shutdown(operationContext());
_indexBuildsCoord.reset();
// All databases are dropped during tear down.
@@ -151,24 +154,27 @@ TEST_F(IndexBuildsCoordinatorMongodTest, Registration) {
_indexBuildsCoord->sleepIndexBuilds_forTestOnly(true);
// Register an index build on _testFooNss.
+ auto testFoo1BuildUUID = UUID::gen();
auto testFoo1Future =
assertGet(_indexBuildsCoord->startIndexBuild(operationContext(),
_testFooNss.db().toString(),
_testFooUUID,
makeSpecs(_testFooNss, {"a", "b"}),
- UUID::gen(),
+ testFoo1BuildUUID,
IndexBuildProtocol::kTwoPhase,
_indexBuildOptions));
ASSERT_EQ(_indexBuildsCoord->numInProgForDb(_testFooNss.db()), 1);
ASSERT(_indexBuildsCoord->inProgForCollection(_testFooUUID));
ASSERT(_indexBuildsCoord->inProgForDb(_testFooNss.db()));
- ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID),
- AssertionException,
- ErrorCodes::BackgroundOperationInProgressForNamespace);
- ASSERT_THROWS_CODE(_indexBuildsCoord->assertNoBgOpInProgForDb(_testFooNss.db()),
- AssertionException,
- ErrorCodes::BackgroundOperationInProgressForDatabase);
+ ASSERT_THROWS_WITH_CHECK(
+ _indexBuildsCoord->assertNoIndexBuildInProgForCollection(_testFooUUID),
+ ExceptionFor<ErrorCodes::BackgroundOperationInProgressForNamespace>,
+ [&](const auto& ex) { ASSERT_STRING_CONTAINS(ex.reason(), testFoo1BuildUUID.toString()); });
+ ASSERT_THROWS_WITH_CHECK(
+ _indexBuildsCoord->assertNoBgOpInProgForDb(_testFooNss.db()),
+ ExceptionFor<ErrorCodes::BackgroundOperationInProgressForDatabase>,
+ [&](const auto& ex) { ASSERT_STRING_CONTAINS(ex.reason(), testFoo1BuildUUID.toString()); });
// Register a second index build on _testFooNss.
auto testFoo2Future =