diff options
-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 2cd9604a5cf..4c9dd0d1c94 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -517,6 +517,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, @@ -1805,10 +1813,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", @@ -2172,10 +2177,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. |