diff options
author | Benety Goh <benety@mongodb.com> | 2023-02-10 14:35:23 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-14 20:37:06 +0000 |
commit | f8768543817db200e98be399dd2520e190ba3955 (patch) | |
tree | 7f23e86acd9fbbc750ca13ee7c1532af815e9540 | |
parent | d3b2ad3244be249a7abe70fabea2e97d174da1d5 (diff) | |
download | mongo-f8768543817db200e98be399dd2520e190ba3955.tar.gz |
SERVER-73858 add IndexBuildsCoordinator::isCreateIndexesErrorSafeToIgnore()
(cherry picked from commit 944b024917b8ce7179bab74b357d4bad71e2e33a)
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index a35a9b45aaf..2ef6e6ace00 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -516,6 +516,14 @@ std::vector<std::string> IndexBuildsCoordinator::extractIndexNames( return indexNames; } +bool IndexBuildsCoordinator::isCreateIndexesErrorSafeToIgnore( + const Status& status, IndexBuildsManager::IndexConstraints indexConstraints) { + return (status == ErrorCodes::IndexAlreadyExists || + ((status == ErrorCodes::IndexOptionsConflict || + status == ErrorCodes::IndexKeySpecsConflict) && + IndexBuildsManager::IndexConstraints::kRelax == indexConstraints)); +} + StatusWith<std::pair<long long, long long>> IndexBuildsCoordinator::rebuildIndexesForRecovery( OperationContext* opCtx, const NamespaceString& nss, @@ -1804,10 +1812,7 @@ void IndexBuildsCoordinator::createIndex(OperationContext* opCtx, opCtx, collection, {spec}, buildUUID, onInitFn, options)); } catch (DBException& ex) { const auto& status = ex.toStatus(); - if (status == ErrorCodes::IndexAlreadyExists || - ((status == ErrorCodes::IndexOptionsConflict || - status == ErrorCodes::IndexKeySpecsConflict) && - IndexBuildsManager::IndexConstraints::kRelax == indexConstraints)) { + if (IndexBuildsCoordinator::isCreateIndexesErrorSafeToIgnore(status, indexConstraints)) { LOGV2_DEBUG(4718200, 1, "Ignoring indexing error", @@ -2171,10 +2176,8 @@ IndexBuildsCoordinator::PostSetupAction IndexBuildsCoordinator::_setUpIndexBuild opCtx, collection, replState->buildUUID, MultiIndexBlock::kNoopOnCleanUpFn); const auto& status = ex.toStatus(); - if (status == ErrorCodes::IndexAlreadyExists || - ((status == ErrorCodes::IndexOptionsConflict || - status == ErrorCodes::IndexKeySpecsConflict) && - options.indexConstraints == IndexBuildsManager::IndexConstraints::kRelax)) { + if (IndexBuildsCoordinator::isCreateIndexesErrorSafeToIgnore(status, + options.indexConstraints)) { LOGV2_DEBUG(20662, 1, "Ignoring indexing error: {error}", diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index 73fa65b3d22..e386308d776 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -125,6 +125,16 @@ public: static std::vector<std::string> extractIndexNames(const std::vector<BSONObj>& specs); /** + * Returns true if an index creation error is safe to ignore. + * Consolidates the checking for the multiple scenarios where we may create indexes. + * - createIndexes command on the primary; + * - during oplog application (both empty and non-empty collection cases); and + * - single-phase index creation for internal collections. + */ + static bool isCreateIndexesErrorSafeToIgnore( + const Status& status, IndexBuildsManager::IndexConstraints indexConstraints); + + /** * Sets up the in-memory and durable state of the index build. When successful, returns after * the index build has started and the first catalog write has been made, and if called on a * primary, when the startIndexBuild oplog entry has been written. |