diff options
Diffstat (limited to 'src/mongo/db/commands/create_indexes.cpp')
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index ba8eb767daa..3ea9f94aea4 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -61,6 +61,7 @@ #include "mongo/db/s/database_sharding_state.h" #include "mongo/db/server_options.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/platform/compiler.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/log.h" @@ -413,8 +414,9 @@ BSONObj runCreateIndexesOnNewCollection(OperationContext* opCtx, if (MONGO_unlikely(hangBeforeCreateIndexesCollectionCreate.shouldFail())) { // Simulate a scenario where a conflicting collection creation occurs // mid-index build. - log() << "Hanging create collection due to failpoint " - "'hangBeforeCreateIndexesCollectionCreate'"; + LOGV2(20437, + "Hanging create collection due to failpoint " + "'hangBeforeCreateIndexesCollectionCreate'"); hangBeforeCreateIndexesCollectionCreate.pauseWhileSet(); } @@ -557,7 +559,7 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx, auto protocol = IndexBuildsCoordinator::supportsTwoPhaseIndexBuild() ? IndexBuildProtocol::kTwoPhase : IndexBuildProtocol::kSinglePhase; - log() << "Registering index build: " << buildUUID; + LOGV2(20438, "Registering index build: {buildUUID}", "buildUUID"_attr = buildUUID); ReplIndexBuildState::IndexCatalogStats stats; IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions = {commitQuorum}; @@ -568,17 +570,24 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx, auto deadline = opCtx->getDeadline(); // Date_t::max() means no deadline. if (deadline == Date_t::max()) { - log() << "Waiting for index build to complete: " << buildUUID; + LOGV2(20439, + "Waiting for index build to complete: {buildUUID}", + "buildUUID"_attr = buildUUID); } else { - log() << "Waiting for index build to complete: " << buildUUID - << " (deadline: " << deadline << ")"; + LOGV2(20440, + "Waiting for index build to complete: {buildUUID} (deadline: {deadline})", + "buildUUID"_attr = buildUUID, + "deadline"_attr = deadline); } // Throws on error. try { stats = buildIndexFuture.get(opCtx); } catch (const ExceptionForCat<ErrorCategory::Interruption>& interruptionEx) { - log() << "Index build interrupted: " << buildUUID << ": " << interruptionEx; + LOGV2(20441, + "Index build interrupted: {buildUUID}: {interruptionEx}", + "buildUUID"_attr = buildUUID, + "interruptionEx"_attr = interruptionEx); hangBeforeIndexBuildAbortOnInterrupt.pauseWhileSet(); @@ -588,7 +597,9 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx, // background and will complete when this node receives a commitIndexBuild oplog // entry from the new primary. if (ErrorCodes::InterruptedDueToReplStateChange == interruptionEx.code()) { - log() << "Index build continuing in background: " << buildUUID; + LOGV2(20442, + "Index build continuing in background: {buildUUID}", + "buildUUID"_attr = buildUUID); throw; } @@ -621,18 +632,22 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx, Timestamp(), str::stream() << "Index build interrupted: " << buildUUID << ": " << interruptionEx.toString()); - log() << "Index build aborted: " << buildUUID; + LOGV2(20443, "Index build aborted: {buildUUID}", "buildUUID"_attr = buildUUID); throw; } catch (const ExceptionForCat<ErrorCategory::NotMasterError>& ex) { - log() << "Index build interrupted due to change in replication state: " << buildUUID - << ": " << ex; + LOGV2(20444, + "Index build interrupted due to change in replication state: {buildUUID}: {ex}", + "buildUUID"_attr = buildUUID, + "ex"_attr = ex); // The index build will continue to run in the background and will complete when this // node receives a commitIndexBuild oplog entry from the new primary. if (IndexBuildProtocol::kTwoPhase == protocol) { - log() << "Index build continuing in background: " << buildUUID; + LOGV2(20445, + "Index build continuing in background: {buildUUID}", + "buildUUID"_attr = buildUUID); throw; } @@ -644,24 +659,32 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx, Timestamp(), str::stream() << "Index build interrupted due to change in replication state: " << buildUUID << ": " << ex.toString()); - log() << "Index build aborted due to NotMaster error: " << buildUUID; + LOGV2(20446, + "Index build aborted due to NotMaster error: {buildUUID}", + "buildUUID"_attr = buildUUID); throw; } - log() << "Index build completed: " << buildUUID; + LOGV2(20447, "Index build completed: {buildUUID}", "buildUUID"_attr = buildUUID); } catch (DBException& ex) { // If the collection is dropped after the initial checks in this function (before the // AutoStatsTracker is created), the IndexBuildsCoordinator (either startIndexBuild() or // the the task running the index build) may return NamespaceNotFound. This is not // considered an error and the command should return success. if (ErrorCodes::NamespaceNotFound == ex.code()) { - log() << "Index build failed: " << buildUUID << ": collection dropped: " << ns; + LOGV2(20448, + "Index build failed: {buildUUID}: collection dropped: {ns}", + "buildUUID"_attr = buildUUID, + "ns"_attr = ns); return true; } // All other errors should be forwarded to the caller with index build information included. - log() << "Index build failed: " << buildUUID << ": " << ex.toStatus(); + LOGV2(20449, + "Index build failed: {buildUUID}: {ex_toStatus}", + "buildUUID"_attr = buildUUID, + "ex_toStatus"_attr = ex.toStatus()); ex.addContext(str::stream() << "Index build failed: " << buildUUID << ": Collection " << ns << " ( " << *collectionUUID << " )"); @@ -734,12 +757,13 @@ public: } if (shouldLogMessageOnAlreadyBuildingError) { auto bsonElem = cmdObj.getField(kIndexesFieldName); - log() - << "Received a request to create indexes: '" << bsonElem - << "', but found that at least one of the indexes is already being built, '" - << ex.toStatus() - << "'. This request will wait for the pre-existing index build to finish " - "before proceeding."; + LOGV2(20450, + "Received a request to create indexes: '{bsonElem}', but found that at " + "least one of the indexes is already being built, '{ex_toStatus}'. This " + "request will wait for the pre-existing index build to finish " + "before proceeding.", + "bsonElem"_attr = bsonElem, + "ex_toStatus"_attr = ex.toStatus()); shouldLogMessageOnAlreadyBuildingError = false; } // Unset the response fields so we do not write duplicate fields. |