diff options
author | Gabriel Russell <gabriel.russell@mongodb.com> | 2020-02-13 11:49:46 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-13 18:16:35 +0000 |
commit | a84c09a19720b73cedb2e8ef7c5cfeedfa1c9761 (patch) | |
tree | 85ac46cd5f4ea6d5134560bf764fb9e6cf11fe4e /src/mongo/db | |
parent | 6df40e01f7b6899affc4536e7e73a35802cabf98 (diff) | |
download | mongo-a84c09a19720b73cedb2e8ef7c5cfeedfa1c9761.tar.gz |
SERVER-45869 automatically converted structured logging
Diffstat (limited to 'src/mongo/db')
292 files changed, 8016 insertions, 3648 deletions
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp index f996254981d..603cf4c924c 100644 --- a/src/mongo/db/auth/authorization_manager_impl.cpp +++ b/src/mongo/db/auth/authorization_manager_impl.cpp @@ -51,6 +51,7 @@ #include "mongo/db/auth/user_management_commands_parser.h" #include "mongo/db/global_settings.h" #include "mongo/db/mongod_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -413,7 +414,7 @@ StatusWith<UserHandle> AuthorizationManagerImpl::acquireUser(OperationContext* o auto cachedUser = _userCache.acquire(opCtx, userName); invariant(cachedUser); - LOG(1) << "Returning user " << userName << " from cache"; + LOGV2_DEBUG(20226, 1, "Returning user {userName} from cache", "userName"_attr = userName); return cachedUser; } catch (const DBException& ex) { return ex.toStatus(); @@ -442,7 +443,7 @@ void AuthorizationManagerImpl::updatePinnedUsersList(std::vector<UserName> names bool noUsersToPin = _usersToPin->empty(); _pinnedUsersCond.notify_one(); if (noUsersToPin) { - LOG(1) << "There were no users to pin, not starting tracker thread"; + LOGV2_DEBUG(20227, 1, "There were no users to pin, not starting tracker thread"); return; } @@ -456,7 +457,7 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try { Client::initThread("PinnedUsersTracker"); std::list<UserHandle> pinnedUsers; std::vector<UserName> usersToPin; - LOG(1) << "Starting pinned users tracking thread"; + LOGV2_DEBUG(20228, 1, "Starting pinned users tracking thread"); while (true) { auto opCtx = cc().makeOperationContext(); @@ -485,13 +486,22 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try { if (!user.isValid() || !shouldPin) { if (!shouldPin) { - LOG(2) << "Unpinning user " << user->getName(); + LOGV2_DEBUG(20229, + 2, + "Unpinning user {user_getName}", + "user_getName"_attr = user->getName()); } else { - LOG(2) << "Pinned user no longer valid, will re-pin " << user->getName(); + LOGV2_DEBUG(20230, + 2, + "Pinned user no longer valid, will re-pin {user_getName}", + "user_getName"_attr = user->getName()); } it = pinnedUsers.erase(it); } else { - LOG(3) << "Pinned user is still valid and pinned " << user->getName(); + LOGV2_DEBUG(20231, + 3, + "Pinned user is still valid and pinned {user_getName}", + "user_getName"_attr = user->getName()); ++it; } } @@ -506,42 +516,45 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try { auto swUser = acquireUser(opCtx.get(), userName); if (swUser.isOK()) { - LOG(2) << "Pinned user " << userName; + LOGV2_DEBUG(20232, 2, "Pinned user {userName}", "userName"_attr = userName); pinnedUsers.emplace_back(std::move(swUser.getValue())); } else { const auto& status = swUser.getStatus(); // If the user is not found, then it might just not exist yet. Skip this user for // now. if (status != ErrorCodes::UserNotFound) { - warning() << "Unable to fetch pinned user " << userName.toString() << ": " - << status; + LOGV2_WARNING(20239, + "Unable to fetch pinned user {userName}: {status}", + "userName"_attr = userName.toString(), + "status"_attr = status); } else { - LOG(2) << "Pinned user not found: " << userName; + LOGV2_DEBUG( + 20233, 2, "Pinned user not found: {userName}", "userName"_attr = userName); } } } } } catch (const ExceptionFor<ErrorCodes::InterruptedAtShutdown>&) { - LOG(1) << "Ending pinned users tracking thread"; + LOGV2_DEBUG(20234, 1, "Ending pinned users tracking thread"); return; } void AuthorizationManagerImpl::invalidateUserByName(OperationContext* opCtx, const UserName& userName) { - LOG(2) << "Invalidating user " << userName; + LOGV2_DEBUG(20235, 2, "Invalidating user {userName}", "userName"_attr = userName); _authSchemaVersionCache.invalidateAll(); _userCache.invalidate(userName); } void AuthorizationManagerImpl::invalidateUsersFromDB(OperationContext* opCtx, StringData dbname) { - LOG(2) << "Invalidating all users from database " << dbname; + LOGV2_DEBUG(20236, 2, "Invalidating all users from database {dbname}", "dbname"_attr = dbname); _authSchemaVersionCache.invalidateAll(); _userCache.invalidateIf( [&](const UserName& user, const User*) { return user.getDB() == dbname; }); } void AuthorizationManagerImpl::invalidateUserCache(OperationContext* opCtx) { - LOG(2) << "Invalidating user cache"; + LOGV2_DEBUG(20237, 2, "Invalidating user cache"); _authSchemaVersionCache.invalidateAll(); _userCache.invalidateAll(); } @@ -603,7 +616,7 @@ AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl( boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::lookup(OperationContext* opCtx, const UserName& userName) { - LOG(1) << "Getting user " << userName << " from disk"; + LOGV2_DEBUG(20238, 1, "Getting user {userName} from disk", "userName"_attr = userName); // Number of times to retry a user document that fetches due to transient AuthSchemaIncompatible // errors. These errors should only ever occur during and shortly after schema upgrades. diff --git a/src/mongo/db/auth/authorization_session_impl.cpp b/src/mongo/db/auth/authorization_session_impl.cpp index 941f3b84cf8..c0beeb758aa 100644 --- a/src/mongo/db/auth/authorization_session_impl.cpp +++ b/src/mongo/db/auth/authorization_session_impl.cpp @@ -53,6 +53,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/pipeline/aggregation_request.h" #include "mongo/db/pipeline/lite_parsed_pipeline.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -139,8 +140,11 @@ Status AuthorizationSessionImpl::addAndAuthorizeUser(OperationContext* opCtx, Status restrictionStatus = restrictionSet.validate(RestrictionEnvironment::get(*opCtx->getClient())); if (!restrictionStatus.isOK()) { - log() << "Failed to acquire user '" << userName - << "' because of unmet authentication restrictions: " << restrictionStatus.reason(); + LOGV2(20240, + "Failed to acquire user '{userName}' because of unmet authentication restrictions: " + "{restrictionStatus_reason}", + "userName"_attr = userName, + "restrictionStatus_reason"_attr = restrictionStatus.reason()); return AuthorizationManager::authenticationFailedStatus; } @@ -553,9 +557,11 @@ bool AuthorizationSessionImpl::isAuthorizedToCreateRole( return true; } } - log() << "Not authorized to create the first role in the system '" << args.roleName - << "' using the localhost exception. The user needs to acquire the role through " - "external authentication first."; + LOGV2(20241, + "Not authorized to create the first role in the system '{args_roleName}' using the " + "localhost exception. The user needs to acquire the role through " + "external authentication first.", + "args_roleName"_attr = args.roleName); } return false; @@ -765,45 +771,56 @@ void AuthorizationSessionImpl::_refreshUserInfoAsNeeded(OperationContext* opCtx) Status restrictionStatus = restrictionSet.validate( RestrictionEnvironment::get(*opCtx->getClient())); if (!restrictionStatus.isOK()) { - log() << "Removed user " << name - << " with unmet authentication restrictions from session cache of" - << " user information. Restriction failed because: " - << restrictionStatus.reason(); + LOGV2(20242, + "Removed user {name} with unmet authentication restrictions from " + "session cache of user information. Restriction failed because: " + "{restrictionStatus_reason}", + "name"_attr = name, + "restrictionStatus_reason"_attr = restrictionStatus.reason()); // If we remove from the UserSet, we cannot increment the iterator. continue; } } catch (...) { - log() << "Evaluating authentication restrictions for " << name - << " resulted in an unknown exception. Removing user from the" - << " session cache."; + LOGV2(20243, + "Evaluating authentication restrictions for {name} resulted in an " + "unknown exception. Removing user from the session cache.", + "name"_attr = name); continue; } // Success! Replace the old User object with the updated one. removeGuard.dismiss(); _authenticatedUsers.replaceAt(it, std::move(updatedUser)); - LOG(1) << "Updated session cache of user information for " << name; + LOGV2_DEBUG(20244, + 1, + "Updated session cache of user information for {name}", + "name"_attr = name); break; } case ErrorCodes::UserNotFound: { // User does not exist anymore; remove it from _authenticatedUsers. - log() << "Removed deleted user " << name - << " from session cache of user information."; + LOGV2(20245, + "Removed deleted user {name} from session cache of user information.", + "name"_attr = name); continue; // No need to advance "it" in this case. } case ErrorCodes::UnsupportedFormat: { // An auth subsystem has explicitly indicated a failure. - log() << "Removed user " << name - << " from session cache of user information because of refresh failure:" - << " '" << status << "'."; + LOGV2(20246, + "Removed user {name} from session cache of user information because of " + "refresh failure: '{status}'.", + "name"_attr = name, + "status"_attr = status); continue; // No need to advance "it" in this case. } default: // Unrecognized error; assume that it's transient, and continue working with the // out-of-date privilege data. - warning() << "Could not fetch updated user privilege information for " << name - << "; continuing to use old information. Reason is " - << redact(status); + LOGV2_WARNING(20247, + "Could not fetch updated user privilege information for {name}; " + "continuing to use old information. Reason is {status}", + "name"_attr = name, + "status"_attr = redact(status)); removeGuard.dismiss(); break; } diff --git a/src/mongo/db/auth/authz_session_external_state_server_common.cpp b/src/mongo/db/auth/authz_session_external_state_server_common.cpp index b9829fde37e..9b29806013b 100644 --- a/src/mongo/db/auth/authz_session_external_state_server_common.cpp +++ b/src/mongo/db/auth/authz_session_external_state_server_common.cpp @@ -38,6 +38,7 @@ #include "mongo/base/status.h" #include "mongo/db/auth/enable_localhost_auth_bypass_parameter_gen.h" #include "mongo/db/client.h" +#include "mongo/logv2/log.h" #include "mongo/util/debug_util.h" #include "mongo/util/log.h" @@ -70,9 +71,9 @@ void AuthzSessionExternalStateServerCommon::_checkShouldAllowLocalhost(Operation _allowLocalhost = !_authzManager->hasAnyPrivilegeDocuments(opCtx); if (_allowLocalhost) { std::call_once(checkShouldAllowLocalhostOnceFlag, []() { - log() << "note: no users configured in admin.system.users, allowing localhost " - "access" - << std::endl; + LOGV2(20248, + "note: no users configured in admin.system.users, allowing localhost " + "access"); }); } } diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp index a6276d3fec9..22403e23303 100644 --- a/src/mongo/db/auth/sasl_commands.cpp +++ b/src/mongo/db/auth/sasl_commands.cpp @@ -53,6 +53,7 @@ #include "mongo/db/commands/authentication_commands.h" #include "mongo/db/server_options.h" #include "mongo/db/stats/counters.h" +#include "mongo/logv2/log.h" #include "mongo/util/base64.h" #include "mongo/util/log.h" #include "mongo/util/sequence_util.h" @@ -187,10 +188,15 @@ Status doSaslStep(OperationContext* opCtx, StatusWith<std::string> swResponse = mechanism.step(opCtx, payload); if (!swResponse.isOK()) { - log() << "SASL " << mechanism.mechanismName() << " authentication failed for " - << mechanism.getPrincipalName() << " on " << mechanism.getAuthenticationDatabase() - << " from client " << opCtx->getClient()->getRemote().toString() << " ; " - << redact(swResponse.getStatus()); + LOGV2(20249, + "SASL {mechanism_mechanismName} authentication failed for " + "{mechanism_getPrincipalName} on {mechanism_getAuthenticationDatabase} from client " + "{opCtx_getClient_getRemote} ; {swResponse_getStatus}", + "mechanism_mechanismName"_attr = mechanism.mechanismName(), + "mechanism_getPrincipalName"_attr = mechanism.getPrincipalName(), + "mechanism_getAuthenticationDatabase"_attr = mechanism.getAuthenticationDatabase(), + "opCtx_getClient_getRemote"_attr = opCtx->getClient()->getRemote().toString(), + "swResponse_getStatus"_attr = redact(swResponse.getStatus())); sleepmillis(saslGlobalParams.authFailedDelay.load()); // All the client needs to know is that authentication has failed. @@ -211,9 +217,14 @@ Status doSaslStep(OperationContext* opCtx, } if (!serverGlobalParams.quiet.load()) { - log() << "Successfully authenticated as principal " << mechanism.getPrincipalName() - << " on " << mechanism.getAuthenticationDatabase() << " from client " - << opCtx->getClient()->session()->remote(); + LOGV2(20250, + "Successfully authenticated as principal {mechanism_getPrincipalName} on " + "{mechanism_getAuthenticationDatabase} from client " + "{opCtx_getClient_session_remote}", + "mechanism_getPrincipalName"_attr = mechanism.getPrincipalName(), + "mechanism_getAuthenticationDatabase"_attr = + mechanism.getAuthenticationDatabase(), + "opCtx_getClient_session_remote"_attr = opCtx->getClient()->session()->remote()); } if (session->isSpeculative()) { authCounter.incSpeculativeAuthenticateSuccessful(mechanism.mechanismName().toString()); diff --git a/src/mongo/db/auth/sasl_mechanism_registry.cpp b/src/mongo/db/auth/sasl_mechanism_registry.cpp index 741dde39126..5c07d4e2eac 100644 --- a/src/mongo/db/auth/sasl_mechanism_registry.cpp +++ b/src/mongo/db/auth/sasl_mechanism_registry.cpp @@ -35,6 +35,7 @@ #include "mongo/base/init.h" #include "mongo/db/auth/sasl_options.h" #include "mongo/db/auth/user.h" +#include "mongo/logv2/log.h" #include "mongo/util/icu.h" #include "mongo/util/log.h" #include "mongo/util/net/socket_utils.h" @@ -108,8 +109,9 @@ void SASLServerMechanismRegistry::advertiseMechanismNamesForUser(OperationContex if (!swUser.isOK()) { auto& status = swUser.getStatus(); if (status.code() == ErrorCodes::UserNotFound) { - log() << "Supported SASL mechanisms requested for unknown user '" << userName - << "'"; + LOGV2(20251, + "Supported SASL mechanisms requested for unknown user '{userName}'", + "userName"_attr = userName); return; } uassertStatusOK(status); diff --git a/src/mongo/db/auth/sasl_scram_test.cpp b/src/mongo/db/auth/sasl_scram_test.cpp index 23c6c548f3c..4b2ec0b84d5 100644 --- a/src/mongo/db/auth/sasl_scram_test.cpp +++ b/src/mongo/db/auth/sasl_scram_test.cpp @@ -47,6 +47,7 @@ #include "mongo/db/auth/sasl_mechanism_registry.h" #include "mongo/db/auth/sasl_scram_server_conversation.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/base64.h" #include "mongo/util/log.h" @@ -270,12 +271,12 @@ protected: public: void run() { - log() << "SCRAM-SHA-1 variant"; + LOGV2(20252, "SCRAM-SHA-1 variant"); saslServerSession = std::make_unique<SaslSCRAMSHA1ServerMechanism>("test"); _digestPassword = true; Test::run(); - log() << "SCRAM-SHA-256 variant"; + LOGV2(20253, "SCRAM-SHA-256 variant"); saslServerSession = std::make_unique<SaslSCRAMSHA256ServerMechanism>("test"); _digestPassword = false; Test::run(); diff --git a/src/mongo/db/auth/security_key.cpp b/src/mongo/db/auth/security_key.cpp index fe310befdf2..5fb3d1badd4 100644 --- a/src/mongo/db/auth/security_key.cpp +++ b/src/mongo/db/auth/security_key.cpp @@ -52,6 +52,7 @@ #include "mongo/db/auth/security_file.h" #include "mongo/db/auth/user.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/icu.h" #include "mongo/util/log.h" #include "mongo/util/password_digest.h" @@ -70,15 +71,20 @@ public: boost::optional<User::CredentialData> generate(const std::string& password) { if (password.size() < kMinKeyLength || password.size() > kMaxKeyLength) { - error() << " security key in " << _filename << " has length " << password.size() - << ", must be between 6 and 1024 chars"; + LOGV2_ERROR(20255, + " security key in {filename} has length {password_size}, must be between 6 " + "and 1024 chars", + "filename"_attr = _filename, + "password_size"_attr = password.size()); return boost::none; } auto swSaslPassword = icuSaslPrep(password); if (!swSaslPassword.isOK()) { - error() << "Could not prep security key file for SCRAM-SHA-256: " - << swSaslPassword.getStatus(); + LOGV2_ERROR( + 20256, + "Could not prep security key file for SCRAM-SHA-256: {swSaslPassword_getStatus}", + "swSaslPassword_getStatus"_attr = swSaslPassword.getStatus()); return boost::none; } const auto passwordDigest = mongo::createPasswordDigest( @@ -109,7 +115,9 @@ private: target.storedKey = source[scram::kStoredKeyFieldName].String(); target.serverKey = source[scram::kServerKeyFieldName].String(); if (!target.isValid()) { - error() << "Could not generate valid credentials from key in " << _filename; + LOGV2_ERROR(20257, + "Could not generate valid credentials from key in {filename}", + "filename"_attr = _filename); return false; } @@ -128,15 +136,20 @@ using std::string; bool setUpSecurityKey(const string& filename) { auto swKeyStrings = mongo::readSecurityFile(filename); if (!swKeyStrings.isOK()) { - log() << swKeyStrings.getStatus().reason(); + LOGV2(20254, + "{swKeyStrings_getStatus_reason}", + "swKeyStrings_getStatus_reason"_attr = swKeyStrings.getStatus().reason()); return false; } auto keyStrings = std::move(swKeyStrings.getValue()); if (keyStrings.size() > 2) { - error() << "Only two keys are supported in the security key file, " << keyStrings.size() - << " are specified in " << filename; + LOGV2_ERROR(20258, + "Only two keys are supported in the security key file, {keyStrings_size} are " + "specified in {filename}", + "keyStrings_size"_attr = keyStrings.size(), + "filename"_attr = filename); return false; } diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp index 771194c14c6..d301173441e 100644 --- a/src/mongo/db/auth/user_cache_invalidator_job.cpp +++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp @@ -42,6 +42,7 @@ #include "mongo/db/auth/user_cache_invalidator_job_parameters_gen.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/logv2/log.h" #include "mongo/platform/compiler.h" #include "mongo/platform/mutex.h" #include "mongo/rpc/get_status_from_command_result.h" @@ -63,7 +64,11 @@ public: void setInterval(Seconds interval) { { stdx::lock_guard<Latch> twiddle(_mutex); - LOG(5) << "setInterval: old=" << _interval << ", new=" << interval; + LOGV2_DEBUG(20259, + 5, + "setInterval: old={interval}, new={interval2}", + "interval"_attr = _interval, + "interval2"_attr = interval); _interval = interval; } _condition.notify_all(); @@ -94,15 +99,19 @@ public: Date_t now = Date_t::now(); Date_t expiry = _last + _interval; - LOG(5) << "wait: now=" << now << ", expiry=" << expiry; + LOGV2_DEBUG(20260, + 5, + "wait: now={now}, expiry={expiry}", + "now"_attr = now, + "expiry"_attr = expiry); if (now >= expiry) { _last = now; - LOG(5) << "wait: done"; + LOGV2_DEBUG(20261, 5, "wait: done"); return true; } - LOG(5) << "wait: blocking"; + LOGV2_DEBUG(20262, 5, "wait: blocking"); MONGO_IDLE_THREAD_BLOCK; _condition.wait_until(lock, expiry.toSystemTimePoint()); } @@ -165,13 +174,15 @@ void UserCacheInvalidator::initialize(OperationContext* opCtx) { } if (currentGeneration.getStatus().code() == ErrorCodes::CommandNotFound) { - warning() << "_getUserCacheGeneration command not found while fetching initial user " - "cache generation from the config server(s). This most likely means you are " - "running an outdated version of mongod on the config servers"; + LOGV2_WARNING(20264, + "_getUserCacheGeneration command not found while fetching initial user " + "cache generation from the config server(s). This most likely means you are " + "running an outdated version of mongod on the config servers"); } else { - warning() << "An error occurred while fetching initial user cache generation from " - "config servers: " - << currentGeneration.getStatus(); + LOGV2_WARNING(20265, + "An error occurred while fetching initial user cache generation from " + "config servers: {currentGeneration_getStatus}", + "currentGeneration_getStatus"_attr = currentGeneration.getStatus()); } _previousCacheGeneration = OID(); } @@ -184,26 +195,35 @@ void UserCacheInvalidator::run() { auto opCtx = cc().makeOperationContext(); StatusWith<OID> currentGeneration = getCurrentCacheGeneration(opCtx.get()); if (!currentGeneration.isOK()) { - warning() << "An error occurred while fetching current user cache generation " - "to check if user cache needs invalidation: " - << currentGeneration.getStatus(); + LOGV2_WARNING( + 20266, + "An error occurred while fetching current user cache generation " + "to check if user cache needs invalidation: {currentGeneration_getStatus}", + "currentGeneration_getStatus"_attr = currentGeneration.getStatus()); // When in doubt, invalidate the cache try { _authzManager->invalidateUserCache(opCtx.get()); } catch (const DBException& e) { - warning() << "Error invalidating user cache: " << e.toStatus(); + LOGV2_WARNING(20267, + "Error invalidating user cache: {e_toStatus}", + "e_toStatus"_attr = e.toStatus()); } continue; } if (currentGeneration.getValue() != _previousCacheGeneration) { - log() << "User cache generation changed from " << _previousCacheGeneration << " to " - << currentGeneration.getValue() << "; invalidating user cache"; + LOGV2(20263, + "User cache generation changed from {previousCacheGeneration} to " + "{currentGeneration_getValue}; invalidating user cache", + "previousCacheGeneration"_attr = _previousCacheGeneration, + "currentGeneration_getValue"_attr = currentGeneration.getValue()); try { _authzManager->invalidateUserCache(opCtx.get()); } catch (const DBException& e) { - warning() << "Error invalidating user cache: " << e.toStatus(); + LOGV2_WARNING(20268, + "Error invalidating user cache: {e_toStatus}", + "e_toStatus"_attr = e.toStatus()); } _previousCacheGeneration = currentGeneration.getValue(); diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp index 3df128c471f..97010dc6ac3 100644 --- a/src/mongo/db/catalog/catalog_control.cpp +++ b/src/mongo/db/catalog/catalog_control.cpp @@ -43,6 +43,7 @@ #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/namespace_string.h" #include "mongo/db/rebuild_indexes.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -72,8 +73,13 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) { // If there's a minimum visible, invariant there's also a UUID. invariant(!minVisible || uuid); if (uuid && minVisible) { - LOG(1) << "closeCatalog: preserving min visible timestamp. Collection: " - << coll->ns() << " UUID: " << uuid << " TS: " << minVisible; + LOGV2_DEBUG(20269, + 1, + "closeCatalog: preserving min visible timestamp. Collection: {coll_ns} " + "UUID: {uuid} TS: {minVisible}", + "coll_ns"_attr = coll->ns(), + "uuid"_attr = uuid, + "minVisible"_attr = minVisible); minVisibleTimestampMap[*uuid] = *minVisible; } } @@ -87,14 +93,14 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) { // to work before acquiring locks, and might otherwise spuriously regard a UUID as unknown // while reloading the catalog. CollectionCatalog::get(opCtx).onCloseCatalog(opCtx); - LOG(1) << "closeCatalog: closing collection catalog"; + LOGV2_DEBUG(20270, 1, "closeCatalog: closing collection catalog"); // Close all databases. - log() << "closeCatalog: closing all databases"; + LOGV2(20271, "closeCatalog: closing all databases"); databaseHolder->closeAll(opCtx); // Close the storage engine's catalog. - log() << "closeCatalog: closing storage engine catalog"; + LOGV2(20272, "closeCatalog: closing storage engine catalog"); opCtx->getServiceContext()->getStorageEngine()->closeCatalog(opCtx); reopenOnFailure.dismiss(); @@ -105,11 +111,11 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib invariant(opCtx->lockState()->isW()); // Load the catalog in the storage engine. - log() << "openCatalog: loading storage engine catalog"; + LOGV2(20273, "openCatalog: loading storage engine catalog"); auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); storageEngine->loadCatalog(opCtx); - log() << "openCatalog: reconciling catalog and idents"; + LOGV2(20274, "openCatalog: reconciling catalog and idents"); auto reconcileResult = fassert(40688, storageEngine->reconcileCatalogAndIdents(opCtx)); // Determine which indexes need to be rebuilt. rebuildIndexesOnCollection() requires that all @@ -149,8 +155,10 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib invariant(collection, str::stream() << "couldn't get collection " << collNss.toString()); for (const auto& indexName : entry.second.first) { - log() << "openCatalog: rebuilding index: collection: " << collNss.toString() - << ", index: " << indexName; + LOGV2(20275, + "openCatalog: rebuilding index: collection: {collNss}, index: {indexName}", + "collNss"_attr = collNss.toString(), + "indexName"_attr = indexName); } std::vector<BSONObj> indexSpecs = entry.second.second; @@ -165,7 +173,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib opCtx, reconcileResult.indexBuildsToRestart); // Open all databases and repopulate the CollectionCatalog. - log() << "openCatalog: reopening all databases"; + LOGV2(20276, "openCatalog: reopening all databases"); auto databaseHolder = DatabaseHolder::get(opCtx); std::vector<std::string> databasesToOpen = storageEngine->listDatabases(); for (auto&& dbName : databasesToOpen) { @@ -189,7 +197,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib // If this is the oplog collection, re-establish the replication system's cached pointer // to the oplog. if (collNss.isOplog()) { - log() << "openCatalog: updating cached oplog pointer"; + LOGV2(20277, "openCatalog: updating cached oplog pointer"); collection->establishOplogCollectionForLogging(opCtx); } } @@ -199,7 +207,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib // catalog. Clear the pre-closing state. CollectionCatalog::get(opCtx).onOpenCatalog(opCtx); opCtx->getServiceContext()->incrementCatalogGeneration(); - log() << "openCatalog: finished reloading collection catalog"; + LOGV2(20278, "openCatalog: finished reloading collection catalog"); } } // namespace catalog } // namespace mongo diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 5ad39981d44..f73b63b3da5 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -56,6 +56,7 @@ #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -384,7 +385,7 @@ Status _collModInternal(OperationContext* opCtx, std::make_unique<CollModResultChange>(oldExpireSecs, newExpireSecs, result)); if (MONGO_unlikely(assertAfterIndexUpdate.shouldFail())) { - log() << "collMod - assertAfterIndexUpdate fail point enabled."; + LOGV2(20307, "collMod - assertAfterIndexUpdate fail point enabled."); uasserted(50970, "trigger rollback after the index update"); } } diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index 2907e940f3c..47dea8b1ad5 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -37,6 +37,7 @@ #include "mongo/db/concurrency/lock_manager_defs.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/storage/recovery_unit.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/uuid.h" @@ -384,12 +385,18 @@ void CollectionCatalog::registerCollection(CollectionUUID uuid, std::unique_ptr< auto ns = (*coll)->ns(); stdx::lock_guard<Latch> lock(_catalogLock); if (_collections.find(ns) != _collections.end()) { - log() << "Conflicted creating a collection. ns: " << (*coll)->ns() << " (" - << (*coll)->uuid() << ")."; + LOGV2(20279, + "Conflicted creating a collection. ns: {coll_ns} ({coll_uuid}).", + "coll_ns"_attr = (*coll)->ns(), + "coll_uuid"_attr = (*coll)->uuid()); throw WriteConflictException(); } - LOG(1) << "Registering collection " << ns << " with UUID " << uuid; + LOGV2_DEBUG(20280, + 1, + "Registering collection {ns} with UUID {uuid}", + "ns"_attr = ns, + "uuid"_attr = uuid); auto dbName = ns.db().toString(); auto dbIdPair = std::make_pair(dbName, uuid); @@ -419,7 +426,11 @@ std::unique_ptr<Collection> CollectionCatalog::deregisterCollection(CollectionUU auto dbName = ns.db().toString(); auto dbIdPair = std::make_pair(dbName, uuid); - LOG(1) << "Deregistering collection " << ns << " with UUID " << uuid; + LOGV2_DEBUG(20281, + 1, + "Deregistering collection {ns} with UUID {uuid}", + "ns"_attr = ns, + "uuid"_attr = uuid); // Make sure collection object exists. invariant(_collections.find(ns) != _collections.end()); @@ -447,14 +458,18 @@ std::unique_ptr<RecoveryUnit::Change> CollectionCatalog::makeFinishDropCollectio void CollectionCatalog::deregisterAllCollections() { stdx::lock_guard<Latch> lock(_catalogLock); - LOG(0) << "Deregistering all the collections"; + LOGV2(20282, "Deregistering all the collections"); for (auto& entry : _catalog) { auto uuid = entry.first; auto ns = entry.second->ns(); auto dbName = ns.db().toString(); auto dbIdPair = std::make_pair(dbName, uuid); - LOG(1) << "Deregistering collection " << ns << " with UUID " << uuid; + LOGV2_DEBUG(20283, + 1, + "Deregistering collection {ns} with UUID {uuid}", + "ns"_attr = ns, + "uuid"_attr = uuid); entry.second.reset(); } diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp index 13d91880c82..803c11cdd79 100644 --- a/src/mongo/db/catalog/collection_compact.cpp +++ b/src/mongo/db/catalog/collection_compact.cpp @@ -41,6 +41,7 @@ #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/operation_context.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -103,7 +104,10 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx, recordStore = collection->getRecordStore(); } - log(LogComponent::kCommand) << "compact " << collectionNss << " begin"; + LOGV2_OPTIONS(20284, + {logComponentV1toV2(LogComponent::kCommand)}, + "compact {collectionNss} begin", + "collectionNss"_attr = collectionNss); auto oldTotalSize = recordStore->storageSize(opCtx) + collection->getIndexSize(opCtx); auto indexCatalog = collection->getIndexCatalog(); @@ -119,8 +123,11 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx, auto totalSizeDiff = oldTotalSize - recordStore->storageSize(opCtx) - collection->getIndexSize(opCtx); - log() << "compact " << collectionNss << " bytes freed: " << totalSizeDiff; - log() << "compact " << collectionNss << " end"; + LOGV2(20285, + "compact {collectionNss} bytes freed: {totalSizeDiff}", + "collectionNss"_attr = collectionNss, + "totalSizeDiff"_attr = totalSizeDiff); + LOGV2(20286, "compact {collectionNss} end", "collectionNss"_attr = collectionNss); return totalSizeDiff; } diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index ff5a81d6f48..cf1864f7f22 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -71,6 +71,7 @@ #include "mongo/db/update/update_driver.h" #include "mongo/db/auth/user_document_parser.h" // XXX-ANDY +#include "mongo/logv2/log.h" #include "mongo/rpc/object_check.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -114,7 +115,7 @@ Status checkFailCollectionInsertsFailPoint(const NamespaceString& ns, const BSON const std::string msg = str::stream() << "Failpoint (failCollectionInserts) has been enabled (" << data << "), so rejecting insert (first doc): " << firstDoc; - log() << msg; + LOGV2(20287, "{msg}", "msg"_attr = msg); s = {ErrorCodes::FailPointEnabled, msg}; }, [&](const BSONObj& data) { @@ -142,9 +143,11 @@ std::unique_ptr<CollatorInterface> parseCollation(OperationContext* opCtx, // integration, shut down the server. Errors other than IncompatibleCollationVersion should not // be possible, so these are an invariant rather than fassert. if (collator == ErrorCodes::IncompatibleCollationVersion) { - log() << "Collection " << nss - << " has a default collation which is incompatible with this version: " - << collationSpec; + LOGV2(20288, + "Collection {nss} has a default collation which is incompatible with this version: " + "{collationSpec}", + "nss"_attr = nss, + "collationSpec"_attr = collationSpec); fassertFailedNoTrace(40144); } invariant(collator.getStatus()); @@ -297,8 +300,11 @@ void CollectionImpl::init(OperationContext* opCtx) { parseValidator(opCtx, _validatorDoc, MatchExpressionParser::kAllowAllSpecialFeatures); if (!_swValidator.isOK()) { // Log an error and startup warning if the collection validator is malformed. - warning() << "Collection " << _ns - << " has malformed validator: " << _swValidator.getStatus() << startupWarningsLog; + LOGV2_WARNING_OPTIONS(20293, + {logv2::LogTag::kStartupWarnings}, + "Collection {ns} has malformed validator: {swValidator_getStatus}", + "ns"_attr = _ns, + "swValidator_getStatus"_attr = _swValidator.getStatus()); } _validationAction = uassertStatusOK(_parseValidationAction(collectionOptions.validationAction)); _validationLevel = uassertStatusOK(_parseValidationLevel(collectionOptions.validationLevel)); @@ -370,8 +376,10 @@ Status CollectionImpl::checkValidation(OperationContext* opCtx, const BSONObj& d return Status::OK(); if (_validationAction == ValidationAction::WARN) { - warning() << "Document would fail validation" - << " collection: " << ns() << " doc: " << redact(document); + LOGV2_WARNING(20294, + "Document would fail validation collection: {ns} doc: {document}", + "ns"_attr = ns(), + "document"_attr = redact(document)); return Status::OK(); } @@ -491,8 +499,11 @@ Status CollectionImpl::insertDocuments(OperationContext* opCtx, whenFirst += " when first _id is "; whenFirst += firstIdElem.str(); } - log() << "hangAfterCollectionInserts fail point enabled for " << _ns << whenFirst - << ". Blocking until fail point is disabled."; + LOGV2(20289, + "hangAfterCollectionInserts fail point enabled for {ns}{whenFirst}. Blocking " + "until fail point is disabled.", + "ns"_attr = _ns, + "whenFirst"_attr = whenFirst); hangAfterCollectionInserts.pauseWhileSet(opCtx); }, [&](const BSONObj& data) { @@ -544,8 +555,10 @@ Status CollectionImpl::insertDocumentForBulkLoader(OperationContext* opCtx, status = onRecordInserted(loc.getValue()); if (MONGO_unlikely(failAfterBulkLoadDocInsert.shouldFail())) { - log() << "Failpoint failAfterBulkLoadDocInsert enabled for " << _ns.ns() - << ". Throwing WriteConflictException."; + LOGV2(20290, + "Failpoint failAfterBulkLoadDocInsert enabled for {ns_ns}. Throwing " + "WriteConflictException.", + "ns_ns"_attr = _ns.ns()); throw WriteConflictException(); } @@ -669,7 +682,7 @@ void CollectionImpl::deleteDocument(OperationContext* opCtx, bool noWarn, Collection::StoreDeletedDoc storeDeletedDoc) { if (isCapped()) { - log() << "failing remove on a capped ns " << _ns; + LOGV2(20291, "failing remove on a capped ns {ns}", "ns"_attr = _ns); uasserted(10089, "cannot remove from a capped collection"); return; } @@ -870,8 +883,14 @@ bool CollectionImpl::isEmpty(OperationContext* opCtx) const { bob.appendNumber("fastCount", static_cast<long long>(fastCount)); bob.append("cursor", str::stream() << (cursorEmptyCollRes ? "0" : ">=1")); - LOG(2) << "Detected erroneous fast count for collection " << ns() << "(" << uuid() << ") [" - << getRecordStore()->getIdent() << "]. Record count reported by: " << bob.obj(); + LOGV2_DEBUG(20292, + 2, + "Detected erroneous fast count for collection {ns}({uuid}) " + "[{getRecordStore_getIdent}]. Record count reported by: {bob_obj}", + "ns"_attr = ns(), + "uuid"_attr = uuid(), + "getRecordStore_getIdent"_attr = getRecordStore()->getIdent(), + "bob_obj"_attr = bob.obj()); } return cursorEmptyCollRes; diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp index df087f66649..8cce0049db4 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -44,6 +44,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -92,9 +93,12 @@ std::map<std::string, int64_t> _validateIndexesInternalStructure( const IndexDescriptor* descriptor = entry->descriptor(); const IndexAccessMethod* iam = entry->accessMethod(); - log(LogComponent::kIndex) << "validating the internal structure of index " - << descriptor->indexName() << " on collection " - << descriptor->parentNS(); + LOGV2_OPTIONS(20295, + {logComponentV1toV2(LogComponent::kIndex)}, + "validating the internal structure of index {descriptor_indexName} on " + "collection {descriptor_parentNS}", + "descriptor_indexName"_attr = descriptor->indexName(), + "descriptor_parentNS"_attr = descriptor->parentNS()); ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexName()]; @@ -129,8 +133,12 @@ void _validateIndexes(OperationContext* opCtx, const IndexDescriptor* descriptor = index->descriptor(); - log(LogComponent::kIndex) << "validating index consistency " << descriptor->indexName() - << " on collection " << descriptor->parentNS(); + LOGV2_OPTIONS(20296, + {logComponentV1toV2(LogComponent::kIndex)}, + "validating index consistency {descriptor_indexName} on collection " + "{descriptor_parentNS}", + "descriptor_indexName"_attr = descriptor->indexName(), + "descriptor_parentNS"_attr = descriptor->parentNS()); ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexName()]; int64_t numTraversedKeys; @@ -188,7 +196,9 @@ void _gatherIndexEntryErrors(OperationContext* opCtx, ValidateResults* result) { indexConsistency->setSecondPhase(); - log(LogComponent::kIndex) << "Starting to traverse through all the document key sets."; + LOGV2_OPTIONS(20297, + {logComponentV1toV2(LogComponent::kIndex)}, + "Starting to traverse through all the document key sets."); // During the second phase of validation, iterate through each documents key set and only record // the keys that were inconsistent during the first phase of validation. @@ -198,8 +208,12 @@ void _gatherIndexEntryErrors(OperationContext* opCtx, indexValidator->traverseRecordStore(opCtx, &tempValidateResults, &tempBuilder); } - log(LogComponent::kIndex) << "Finished traversing through all the document key sets."; - log(LogComponent::kIndex) << "Starting to traverse through all the indexes."; + LOGV2_OPTIONS(20298, + {logComponentV1toV2(LogComponent::kIndex)}, + "Finished traversing through all the document key sets."); + LOGV2_OPTIONS(20299, + {logComponentV1toV2(LogComponent::kIndex)}, + "Starting to traverse through all the indexes."); // Iterate through all the indexes in the collection and only record the index entry keys that // had inconsistencies during the first phase. @@ -208,8 +222,10 @@ void _gatherIndexEntryErrors(OperationContext* opCtx, const IndexDescriptor* descriptor = index->descriptor(); - log(LogComponent::kIndex) << "Traversing through the index entries for index " - << descriptor->indexName() << "."; + LOGV2_OPTIONS(20300, + {logComponentV1toV2(LogComponent::kIndex)}, + "Traversing through the index entries for index {descriptor_indexName}.", + "descriptor_indexName"_attr = descriptor->indexName()); indexValidator->traverseIndex(opCtx, index.get(), @@ -217,7 +233,9 @@ void _gatherIndexEntryErrors(OperationContext* opCtx, /*ValidateResults=*/nullptr); } - log(LogComponent::kIndex) << "Finished traversing through all the indexes."; + LOGV2_OPTIONS(20301, + {logComponentV1toV2(LogComponent::kIndex)}, + "Finished traversing through all the indexes."); indexConsistency->addIndexEntryErrors(indexNsResultsMap, result); } @@ -296,8 +314,12 @@ void _reportInvalidResults(OperationContext* opCtx, const string uuidString) { _reportValidationResults( opCtx, validateState, indexNsResultsMap, keysPerIndex, results, output); - log(LogComponent::kIndex) << "Validation complete for collection " << validateState->nss() - << uuidString << ". Corruption found."; + LOGV2_OPTIONS( + 20302, + {logComponentV1toV2(LogComponent::kIndex)}, + "Validation complete for collection {validateState_nss}{uuidString}. Corruption found.", + "validateState_nss"_attr = validateState->nss(), + "uuidString"_attr = uuidString); } template <typename T> @@ -469,7 +491,11 @@ Status validate(OperationContext* opCtx, validateState.initializeCursors(opCtx); // Validate the record store. - log(LogComponent::kIndex) << "validating collection " << validateState.nss() << uuidString; + LOGV2_OPTIONS(20303, + {logComponentV1toV2(LogComponent::kIndex)}, + "validating collection {validateState_nss}{uuidString}", + "validateState_nss"_attr = validateState.nss(), + "uuidString"_attr = uuidString); IndexConsistency indexConsistency(opCtx, &validateState); ValidateAdaptor indexValidator(&indexConsistency, &validateState, &indexNsResultsMap); @@ -492,7 +518,7 @@ Status validate(OperationContext* opCtx, if (MONGO_unlikely(pauseCollectionValidationWithLock.shouldFail())) { _validationIsPausedForTest.store(true); - log() << "Failpoint 'pauseCollectionValidationWithLock' activated."; + LOGV2(20304, "Failpoint 'pauseCollectionValidationWithLock' activated."); pauseCollectionValidationWithLock.pauseWhileSet(); _validationIsPausedForTest.store(false); } @@ -518,9 +544,11 @@ Status validate(OperationContext* opCtx, results); if (indexConsistency.haveEntryMismatch()) { - log(LogComponent::kIndex) - << "Index inconsistencies were detected on collection " << validateState.nss() - << ". Starting the second phase of index validation to gather concise errors."; + LOGV2_OPTIONS(20305, + {logComponentV1toV2(LogComponent::kIndex)}, + "Index inconsistencies were detected on collection {validateState_nss}. " + "Starting the second phase of index validation to gather concise errors.", + "validateState_nss"_attr = validateState.nss()); _gatherIndexEntryErrors(opCtx, &validateState, &indexConsistency, @@ -559,8 +587,12 @@ Status validate(OperationContext* opCtx, _reportValidationResults( opCtx, &validateState, &indexNsResultsMap, &keysPerIndex, results, output); - log(LogComponent::kIndex) << "Validation complete for collection " << validateState.nss() - << uuidString << ". No corruption found."; + LOGV2_OPTIONS(20306, + {logComponentV1toV2(LogComponent::kIndex)}, + "Validation complete for collection {validateState_nss}{uuidString}. No " + "corruption found.", + "validateState_nss"_attr = validateState.nss(), + "uuidString"_attr = uuidString); output->append("ns", validateState.nss().ns()); } catch (ExceptionFor<ErrorCodes::CursorNotFound>&) { diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index b70f4cd675f..d6c1c767623 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -48,6 +48,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/views/view_catalog.h" #include "mongo/logger/redaction.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -253,9 +254,12 @@ Status createCollectionForApplyOps(OperationContext* opCtx, return Result(Status::OK()); if (currentName && currentName->isDropPendingNamespace()) { - log() << "CMD: create " << newCollName - << " - existing collection with conflicting UUID " << uuid - << " is in a drop-pending state: " << *currentName; + LOGV2(20308, + "CMD: create {newCollName} - existing collection with conflicting UUID " + "{uuid} is in a drop-pending state: {currentName}", + "newCollName"_attr = newCollName, + "uuid"_attr = uuid, + "currentName"_attr = *currentName); return Result(Status(ErrorCodes::NamespaceExists, str::stream() << "existing collection " << currentName->toString() @@ -297,9 +301,12 @@ Status createCollectionForApplyOps(OperationContext* opCtx, } // It is ok to log this because this doesn't happen very frequently. - log() << "CMD: create " << newCollName - << " - renaming existing collection with conflicting UUID " << uuid - << " to temporary collection " << tmpName; + LOGV2(20309, + "CMD: create {newCollName} - renaming existing collection with " + "conflicting UUID {uuid} to temporary collection {tmpName}", + "newCollName"_attr = newCollName, + "uuid"_attr = uuid, + "tmpName"_attr = tmpName); Status status = db->renameCollection(opCtx, newCollName, tmpName, stayTemp); if (!status.isOK()) return Result(status); diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp index 9f20c1f563a..c16c9cf0b0a 100644 --- a/src/mongo/db/catalog/database_holder_impl.cpp +++ b/src/mongo/db/catalog/database_holder_impl.cpp @@ -44,6 +44,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/stats/top.h" #include "mongo/db/storage/storage_engine.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -175,7 +176,7 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) { // Store the name so we have if for after the db object is deleted auto name = db->name(); - LOG(1) << "dropDatabase " << name; + LOGV2_DEBUG(20310, 1, "dropDatabase {name}", "name"_attr = name); invariant(opCtx->lockState()->isDbLockedForMode(name, MODE_X)); @@ -251,7 +252,7 @@ void DatabaseHolderImpl::closeAll(OperationContext* opCtx) { } for (const auto& name : dbs) { - LOG(2) << "DatabaseHolder::closeAll name:" << name; + LOGV2_DEBUG(20311, 2, "DatabaseHolder::closeAll name:{name}", "name"_attr = name); Database* db = _dbs[name]; CollectionCatalog::get(opCtx).onCloseDatabase(opCtx, name); diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 78ce8314d82..f9872364a89 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -73,6 +73,7 @@ #include "mongo/db/storage/storage_options.h" #include "mongo/db/system_index.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/platform/random.h" #include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/util/assert_util.h" @@ -138,7 +139,7 @@ void DatabaseImpl::init(OperationContext* const opCtx) const { Status status = validateDBName(_name); if (!status.isOK()) { - warning() << "tried to open invalid db: " << _name; + LOGV2_WARNING(20325, "tried to open invalid db: {name}", "name"_attr = _name); uasserted(10028, status.toString()); } @@ -159,9 +160,12 @@ void DatabaseImpl::init(OperationContext* const opCtx) const { auto views = ViewCatalog::get(this); Status reloadStatus = views->reload(opCtx, ViewCatalogLookupBehavior::kValidateDurableViews); if (!reloadStatus.isOK()) { - warning() << "Unable to parse views: " << redact(reloadStatus) - << "; remove any invalid views from the " << _viewsName - << " collection to restore server functionality." << startupWarningsLog; + LOGV2_WARNING_OPTIONS(20326, + {logv2::LogTag::kStartupWarnings}, + "Unable to parse views: {reloadStatus}; remove any invalid views " + "from the {viewsName} collection to restore server functionality.", + "reloadStatus"_attr = redact(reloadStatus), + "viewsName"_attr = _viewsName); } } @@ -173,13 +177,17 @@ void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const { WriteUnitOfWork wuow(opCtx); Status status = dropCollection(opCtx, collection->ns(), {}); if (!status.isOK()) { - warning() << "could not drop temp collection '" << collection->ns() - << "': " << redact(status); + LOGV2_WARNING(20327, + "could not drop temp collection '{collection_ns}': {status}", + "collection_ns"_attr = collection->ns(), + "status"_attr = redact(status)); } wuow.commit(); } catch (const WriteConflictException&) { - warning() << "could not drop temp collection '" << collection->ns() - << "' due to WriteConflictException"; + LOGV2_WARNING( + 20328, + "could not drop temp collection '{collection_ns}' due to WriteConflictException", + "collection_ns"_attr = collection->ns()); opCtx->recoveryUnit()->abandonSnapshot(); } return true; @@ -289,8 +297,10 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou } else { output->appendNumber("fsUsedSize", -1); output->appendNumber("fsTotalSize", -1); - log() << "Failed to query filesystem disk stats (code: " << ec.value() - << "): " << ec.message(); + LOGV2(20312, + "Failed to query filesystem disk stats (code: {ec_value}): {ec_message}", + "ec_value"_attr = ec.value(), + "ec_message"_attr = ec.message()); } } } @@ -340,7 +350,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, repl::OpTime dropOpTime) const { invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X)); - LOG(1) << "dropCollection: " << nss; + LOGV2_DEBUG(20313, 1, "dropCollection: {nss}", "nss"_attr = nss); // A valid 'dropOpTime' is not allowed when writes are replicated. if (!dropOpTime.isNull() && opCtx->writesAreReplicated()) { @@ -393,9 +403,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, _dropCollectionIndexes(opCtx, nss, collection); auto commitTimestamp = opCtx->recoveryUnit()->getCommitTimestamp(); - log() << "dropCollection: " << nss << " (" << uuid - << ") - storage engine will take ownership of drop-pending collection with optime " - << dropOpTime << " and commit timestamp " << commitTimestamp; + LOGV2(20314, + "dropCollection: {nss} ({uuid}) - storage engine will take ownership of drop-pending " + "collection with optime {dropOpTime} and commit timestamp {commitTimestamp}", + "nss"_attr = nss, + "uuid"_attr = uuid, + "dropOpTime"_attr = dropOpTime, + "commitTimestamp"_attr = commitTimestamp); if (dropOpTime.isNull()) { // Log oplog entry for collection drop and remove the UUID. dropOpTime = opObserver->onDropCollection( @@ -434,9 +448,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, // Rename collection using drop-pending namespace generated from drop optime. auto dpns = nss.makeDropPendingNamespace(dropOpTime); const bool stayTemp = true; - log() << "dropCollection: " << nss << " (" << uuid - << ") - renaming to drop-pending collection: " << dpns << " with drop optime " - << dropOpTime; + LOGV2(20315, + "dropCollection: {nss} ({uuid}) - renaming to drop-pending collection: {dpns} with drop " + "optime {dropOpTime}", + "nss"_attr = nss, + "uuid"_attr = uuid, + "dpns"_attr = dpns, + "dropOpTime"_attr = dropOpTime); { Lock::CollectionLock collLk(opCtx, dpns, MODE_X); fassert(40464, renameCollection(opCtx, nss, dpns, stayTemp)); @@ -453,19 +471,22 @@ void DatabaseImpl::_dropCollectionIndexes(OperationContext* opCtx, const NamespaceString& nss, Collection* collection) const { invariant(_name == nss.db()); - LOG(1) << "dropCollection: " << nss << " - dropAllIndexes start"; + LOGV2_DEBUG(20316, 1, "dropCollection: {nss} - dropAllIndexes start", "nss"_attr = nss); collection->getIndexCatalog()->dropAllIndexes(opCtx, true); invariant(DurableCatalog::get(opCtx)->getTotalIndexCount(opCtx, collection->getCatalogId()) == 0); - LOG(1) << "dropCollection: " << nss << " - dropAllIndexes done"; + LOGV2_DEBUG(20317, 1, "dropCollection: {nss} - dropAllIndexes done", "nss"_attr = nss); } Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx, const NamespaceString& nss, Collection* collection) const { UUID uuid = collection->uuid(); - log() << "Finishing collection drop for " << nss << " (" << uuid << ")."; + LOGV2(20318, + "Finishing collection drop for {nss} ({uuid}).", + "nss"_attr = nss, + "uuid"_attr = uuid); auto status = DurableCatalog::get(opCtx)->dropCollection(opCtx, collection->getCatalogId()); if (!status.isOK()) @@ -514,8 +535,11 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx, << toNss); } - log() << "renameCollection: renaming collection " << collToRename->uuid() << " from " << fromNss - << " to " << toNss; + LOGV2(20319, + "renameCollection: renaming collection {collToRename_uuid} from {fromNss} to {toNss}", + "collToRename_uuid"_attr = collToRename->uuid(), + "fromNss"_attr = fromNss, + "toNss"_attr = toNss); Top::get(opCtx->getServiceContext()).collectionDropped(fromNss); @@ -623,7 +647,7 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx, if (!canAcceptWrites) { std::string msg = str::stream() << "Attempted to create a new collection " << nss << " without a UUID"; - severe() << msg; + LOGV2_FATAL(20329, "{msg}", "msg"_attr = msg); uasserted(ErrorCodes::InvalidOptions, msg); } else { optionsWithUUID.uuid.emplace(CollectionUUID::gen()); @@ -658,8 +682,13 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx, _checkCanCreateCollection(opCtx, nss, optionsWithUUID); audit::logCreateCollection(&cc(), nss.ns()); - log() << "createCollection: " << nss << " with " << (generatedUUID ? "generated" : "provided") - << " UUID: " << optionsWithUUID.uuid.get() << " and options: " << options.toBSON(); + LOGV2(20320, + "createCollection: {nss} with {generatedUUID_generated_provided} UUID: " + "{optionsWithUUID_uuid_get} and options: {options}", + "nss"_attr = nss, + "generatedUUID_generated_provided"_attr = (generatedUUID ? "generated" : "provided"), + "optionsWithUUID_uuid_get"_attr = optionsWithUUID.uuid.get(), + "options"_attr = options.toBSON()); // Create Collection object auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); @@ -781,7 +810,10 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext* CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) { if (nss.isDropPendingNamespace()) { auto dropOpTime = fassert(40459, nss.getDropPendingNamespaceOpTime()); - log() << "Found drop-pending namespace " << nss << " with drop optime " << dropOpTime; + LOGV2(20321, + "Found drop-pending namespace {nss} with drop optime {dropOpTime}", + "nss"_attr = nss, + "dropOpTime"_attr = dropOpTime); repl::DropPendingCollectionReaper::get(opCtx)->addDropPendingNamespace( opCtx, dropOpTime, nss); } @@ -796,11 +828,15 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext* if (coll->getIndexCatalog()->findIdIndex(opCtx)) continue; - log() << "WARNING: the collection '" << nss << "' lacks a unique index on _id." - << " This index is needed for replication to function properly" << startupWarningsLog; - log() << "\t To fix this, you need to create a unique index on _id." - << " See http://dochub.mongodb.org/core/build-replica-set-indexes" - << startupWarningsLog; + LOGV2_OPTIONS(20322, + {logv2::LogTag::kStartupWarnings}, + "WARNING: the collection '{nss}' lacks a unique index on _id. This index is " + "needed for replication to function properly", + "nss"_attr = nss); + LOGV2_OPTIONS(20323, + {logv2::LogTag::kStartupWarnings}, + "\t To fix this, you need to create a unique index on _id. See " + "http://dochub.mongodb.org/core/build-replica-set-indexes"); } } @@ -809,7 +845,11 @@ Status DatabaseImpl::userCreateNS(OperationContext* opCtx, CollectionOptions collectionOptions, bool createDefaultIndexes, const BSONObj& idIndex) const { - LOG(1) << "create collection " << nss << ' ' << collectionOptions.toBSON(); + LOGV2_DEBUG(20324, + 1, + "create collection {nss} {collectionOptions}", + "nss"_attr = nss, + "collectionOptions"_attr = collectionOptions.toBSON()); if (!NamespaceString::validCollectionComponent(nss.ns())) return Status(ErrorCodes::InvalidNamespace, str::stream() << "invalid ns: " << nss); diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index f973c1257bd..1f18d42eec0 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -45,6 +45,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/service_context.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -74,8 +75,9 @@ Status _dropView(OperationContext* opCtx, Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X); if (MONGO_unlikely(hangDuringDropCollection.shouldFail())) { - log() << "hangDuringDropCollection fail point enabled. Blocking until fail point is " - "disabled."; + LOGV2(20330, + "hangDuringDropCollection fail point enabled. Blocking until fail point is " + "disabled."); hangDuringDropCollection.pauseWhileSet(); } @@ -116,8 +118,9 @@ Status _dropCollection(OperationContext* opCtx, } if (MONGO_unlikely(hangDuringDropCollection.shouldFail())) { - log() << "hangDuringDropCollection fail point enabled. Blocking until fail point is " - "disabled."; + LOGV2(20331, + "hangDuringDropCollection fail point enabled. Blocking until fail point is " + "disabled."); hangDuringDropCollection.pauseWhileSet(); } @@ -160,11 +163,11 @@ Status dropCollection(OperationContext* opCtx, const repl::OpTime& dropOpTime, DropCollectionSystemCollectionMode systemCollectionMode) { if (!serverGlobalParams.quiet.load()) { - log() << "CMD: drop " << collectionName; + LOGV2(20332, "CMD: drop {collectionName}", "collectionName"_attr = collectionName); } if (MONGO_unlikely(hangDropCollectionBeforeLockAcquisition.shouldFail())) { - log() << "Hanging drop collection before lock acquisition while fail point is set"; + LOGV2(20333, "Hanging drop collection before lock acquisition while fail point is set"); hangDropCollectionBeforeLockAcquisition.pauseWhileSet(); } return writeConflictRetry(opCtx, "drop", collectionName.ns(), [&] { diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index f598148c68a..7276059b343 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -47,6 +47,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" #include "mongo/db/write_concern_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/duration.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -85,7 +86,7 @@ void _finishDropDatabase(OperationContext* opCtx, }); if (MONGO_unlikely(dropDatabaseHangBeforeInMemoryDrop.shouldFail())) { - log() << "dropDatabase - fail point dropDatabaseHangBeforeInMemoryDrop enabled."; + LOGV2(20334, "dropDatabase - fail point dropDatabaseHangBeforeInMemoryDrop enabled."); dropDatabaseHangBeforeInMemoryDrop.pauseWhileSet(); } @@ -93,8 +94,11 @@ void _finishDropDatabase(OperationContext* opCtx, databaseHolder->dropDb(opCtx, db); dropPendingGuard.dismiss(); - log() << "dropDatabase " << dbName << " - dropped " << numCollections << " collection(s)"; - log() << "dropDatabase " << dbName << " - finished"; + LOGV2(20335, + "dropDatabase {dbName} - dropped {numCollections} collection(s)", + "dbName"_attr = dbName, + "numCollections"_attr = numCollections); + LOGV2(20336, "dropDatabase {dbName} - finished", "dbName"_attr = dbName); } } // namespace @@ -147,7 +151,7 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) { << "The database is currently being dropped. Database: " << dbName); } - log() << "dropDatabase " << dbName << " - starting"; + LOGV2(20337, "dropDatabase {dbName} - starting", "dbName"_attr = dbName); db->setDropPending(opCtx, true); // If Database::dropCollectionEventIfSystem() fails, we should reset the drop-pending state @@ -164,11 +168,17 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) { const auto& nss = collection->ns(); numCollections++; - log() << "dropDatabase " << dbName << " - dropping collection: " << nss; + LOGV2(20338, + "dropDatabase {dbName} - dropping collection: {nss}", + "dbName"_attr = dbName, + "nss"_attr = nss); if (nss.isDropPendingNamespace() && replCoord->isReplEnabled() && opCtx->writesAreReplicated()) { - log() << "dropDatabase " << dbName << " - found drop-pending collection: " << nss; + LOGV2(20339, + "dropDatabase {dbName} - found drop-pending collection: {nss}", + "dbName"_attr = dbName, + "nss"_attr = nss); latestDropPendingOpTime = std::max( latestDropPendingOpTime, uassertStatusOK(nss.getDropPendingNamespaceOpTime())); continue; @@ -264,17 +274,26 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) { const WriteConcernOptions dropDatabaseWriteConcern( WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, wTimeout); - log() << "dropDatabase " << dbName << " waiting for " << awaitOpTime - << " to be replicated at " << dropDatabaseWriteConcern.toBSON() << ". Dropping " - << numCollectionsToDrop << " collection(s), with last collection drop at " - << latestDropPendingOpTime; + LOGV2(20340, + "dropDatabase {dbName} waiting for {awaitOpTime} to be replicated at " + "{dropDatabaseWriteConcern}. Dropping {numCollectionsToDrop} collection(s), with " + "last collection drop at {latestDropPendingOpTime}", + "dbName"_attr = dbName, + "awaitOpTime"_attr = awaitOpTime, + "dropDatabaseWriteConcern"_attr = dropDatabaseWriteConcern.toBSON(), + "numCollectionsToDrop"_attr = numCollectionsToDrop, + "latestDropPendingOpTime"_attr = latestDropPendingOpTime); auto result = replCoord->awaitReplication(opCtx, awaitOpTime, dropDatabaseWriteConcern); // If the user-provided write concern is weaker than majority, this is effectively a no-op. if (result.status.isOK() && !userWriteConcern.usedDefault) { - log() << "dropDatabase " << dbName << " waiting for " << awaitOpTime - << " to be replicated at " << userWriteConcern.toBSON(); + LOGV2(20341, + "dropDatabase {dbName} waiting for {awaitOpTime} to be replicated at " + "{userWriteConcern}", + "dbName"_attr = dbName, + "awaitOpTime"_attr = awaitOpTime, + "userWriteConcern"_attr = userWriteConcern.toBSON()); result = replCoord->awaitReplication(opCtx, awaitOpTime, userWriteConcern); } @@ -286,14 +305,19 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) { << awaitOpTime.toString() << ") to replicate."); } - log() << "dropDatabase " << dbName << " - successfully dropped " << numCollectionsToDrop - << " collection(s) (most recent drop optime: " << awaitOpTime << ") after " - << result.duration << ". dropping database"; + LOGV2(20342, + "dropDatabase {dbName} - successfully dropped {numCollectionsToDrop} collection(s) " + "(most recent drop optime: {awaitOpTime}) after {result_duration}. dropping database", + "dbName"_attr = dbName, + "numCollectionsToDrop"_attr = numCollectionsToDrop, + "awaitOpTime"_attr = awaitOpTime, + "result_duration"_attr = result.duration); } if (MONGO_unlikely(dropDatabaseHangAfterAllCollectionsDrop.shouldFail())) { - log() << "dropDatabase - fail point dropDatabaseHangAfterAllCollectionsDrop enabled. " - "Blocking until fail point is disabled. "; + LOGV2(20343, + "dropDatabase - fail point dropDatabaseHangAfterAllCollectionsDrop enabled. " + "Blocking until fail point is disabled. "); dropDatabaseHangAfterAllCollectionsDrop.pauseWhileSet(); } diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp index 8f29522b82f..1d55cd77d59 100644 --- a/src/mongo/db/catalog/drop_indexes.cpp +++ b/src/mongo/db/catalog/drop_indexes.cpp @@ -46,6 +46,7 @@ #include "mongo/db/repl_set_member_in_standalone_mode.h" #include "mongo/db/service_context.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -222,7 +223,10 @@ Status dropIndexes(OperationContext* opCtx, } if (!serverGlobalParams.quiet.load()) { - LOG(0) << "CMD: dropIndexes " << nss << ": " << cmdObj[kIndexFieldName].toString(false); + LOGV2(20344, + "CMD: dropIndexes {nss}: {cmdObj_kIndexFieldName_false}", + "nss"_attr = nss, + "cmdObj_kIndexFieldName_false"_attr = cmdObj[kIndexFieldName].toString(false)); } // If db/collection does not exist, short circuit and return. diff --git a/src/mongo/db/catalog/index_build_block.cpp b/src/mongo/db/catalog/index_build_block.cpp index 64fb8c10cdd..3cc6bd8f893 100644 --- a/src/mongo/db/catalog/index_build_block.cpp +++ b/src/mongo/db/catalog/index_build_block.cpp @@ -45,6 +45,7 @@ #include "mongo/db/query/collection_query_info.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/ttl_collection_cache.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -178,7 +179,10 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) { invariant(_indexBuildInterceptor->areAllConstraintsChecked(opCtx)); } - log() << "index build: done building index " << _indexName << " on ns " << _nss; + LOGV2(20345, + "index build: done building index {indexName} on ns {nss}", + "indexName"_attr = _indexName, + "nss"_attr = _nss); collection->indexBuildSuccess(opCtx, _indexCatalogEntry); auto svcCtx = opCtx->getClient()->getServiceContext(); diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index 1710718790e..6e88a1985c0 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -40,6 +40,7 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/operation_context.h" #include "mongo/db/storage/write_unit_of_work.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -109,8 +110,13 @@ Status IndexBuildsManager::setUpIndexBuild(OperationContext* opCtx, return ex.toStatus(); } - log() << "Index build initialized: " << buildUUID << ": " << nss << " (" << collection->uuid() - << " ): indexes: " << indexes.size(); + LOGV2( + 20346, + "Index build initialized: {buildUUID}: {nss} ({collection_uuid} ): indexes: {indexes_size}", + "buildUUID"_attr = buildUUID, + "nss"_attr = nss, + "collection_uuid"_attr = collection->uuid(), + "indexes_size"_attr = indexes.size()); return Status::OK(); } @@ -155,12 +161,16 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd auto validStatus = validateBSON(data.data(), data.size(), BSONVersion::kLatest); if (!validStatus.isOK()) { if (repair == RepairData::kNo) { - severe() << "Invalid BSON detected at " << id << ": " - << redact(validStatus); + LOGV2_FATAL(20349, + "Invalid BSON detected at {id}: {validStatus}", + "id"_attr = id, + "validStatus"_attr = redact(validStatus)); fassertFailed(31396); } - warning() << "Invalid BSON detected at " << id << ": " << redact(validStatus) - << ". Deleting."; + LOGV2_WARNING(20348, + "Invalid BSON detected at {id}: {validStatus}. Deleting.", + "id"_attr = id, + "validStatus"_attr = redact(validStatus)); rs->deleteRecord(opCtx, id); } else { numRecords++; @@ -277,7 +287,10 @@ bool IndexBuildsManager::abortIndexBuildWithoutCleanup(OperationContext* opCtx, return false; } - log() << "Index build aborted without cleanup: " << buildUUID << ": " << reason; + LOGV2(20347, + "Index build aborted without cleanup: {buildUUID}: {reason}", + "buildUUID"_attr = buildUUID, + "reason"_attr = reason); std::shared_ptr<MultiIndexBlock> builder = builderIt->second; lk.unlock(); diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp index 3c208009adc..cd2a5f18b32 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp @@ -52,6 +52,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -109,8 +110,12 @@ IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx, MatchExpressionParser::kBanAllSpecialFeatures); invariant(statusWithMatcher.getStatus()); _filterExpression = std::move(statusWithMatcher.getValue()); - LOG(2) << "have filter expression for " << ns() << " " << _descriptor->indexName() << " " - << redact(filter); + LOGV2_DEBUG(20350, + 2, + "have filter expression for {ns} {descriptor_indexName} {filter}", + "ns"_attr = ns(), + "descriptor_indexName"_attr = _descriptor->indexName(), + "filter"_attr = redact(filter)); } } @@ -257,8 +262,12 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx, } if (indexMetadataHasChanged && _queryInfo) { - LOG(1) << ns() << ": clearing plan cache - index " << _descriptor->keyPattern() - << " set to multi key."; + LOGV2_DEBUG( + 20351, + 1, + "{ns}: clearing plan cache - index {descriptor_keyPattern} set to multi key.", + "ns"_attr = ns(), + "descriptor_keyPattern"_attr = _descriptor->keyPattern()); _queryInfo->clearQueryCache(); } }; @@ -288,8 +297,10 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx, auto status = opCtx->recoveryUnit()->setTimestamp(writeTs); if (status.code() == ErrorCodes::BadValue) { - log() << "Temporarily could not timestamp the multikey catalog write, retrying. " - << status.reason(); + LOGV2(20352, + "Temporarily could not timestamp the multikey catalog write, retrying. " + "{status_reason}", + "status_reason"_attr = status.reason()); throw WriteConflictException(); } fassert(31164, status); diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index d1ac7fea2d0..35fc295c73e 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -73,6 +73,7 @@ #include "mongo/db/storage/kv/kv_engine.h" #include "mongo/db/storage/storage_engine_init.h" #include "mongo/db/ttl_collection_cache.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -229,30 +230,40 @@ void IndexCatalogImpl::_logInternalState(OperationContext* opCtx, bool haveIdIndex) { invariant(opCtx->lockState()->isCollectionLockedForMode(_collection->ns(), MODE_X)); - error() << "Internal Index Catalog state: " - << " numIndexesTotal(): " << numIndexesTotal(opCtx) - << " numSystemIndexesEntries: " << numIndexesInCollectionCatalogEntry - << " _readyIndexes.size(): " << _readyIndexes.size() - << " _buildingIndexes.size(): " << _buildingIndexes.size() - << " indexNamesToDrop: " << indexNamesToDrop.size() << " haveIdIndex: " << haveIdIndex; + LOGV2_ERROR( + 20365, + "Internal Index Catalog state: numIndexesTotal(): {numIndexesTotal_opCtx} " + "numSystemIndexesEntries: {numIndexesInCollectionCatalogEntry} _readyIndexes.size(): " + "{readyIndexes_size} _buildingIndexes.size(): {buildingIndexes_size} indexNamesToDrop: " + "{indexNamesToDrop_size} haveIdIndex: {haveIdIndex}", + "numIndexesTotal_opCtx"_attr = numIndexesTotal(opCtx), + "numIndexesInCollectionCatalogEntry"_attr = numIndexesInCollectionCatalogEntry, + "readyIndexes_size"_attr = _readyIndexes.size(), + "buildingIndexes_size"_attr = _buildingIndexes.size(), + "indexNamesToDrop_size"_attr = indexNamesToDrop.size(), + "haveIdIndex"_attr = haveIdIndex); // Report the ready indexes. - error() << "Ready indexes:"; + LOGV2_ERROR(20366, "Ready indexes:"); for (const auto& entry : _readyIndexes) { const IndexDescriptor* desc = entry->descriptor(); - error() << "Index '" << desc->indexName() - << "' with specification: " << redact(desc->infoObj()); + LOGV2_ERROR(20367, + "Index '{desc_indexName}' with specification: {desc_infoObj}", + "desc_indexName"_attr = desc->indexName(), + "desc_infoObj"_attr = redact(desc->infoObj())); } // Report the in-progress indexes. - error() << "In-progress indexes:"; + LOGV2_ERROR(20368, "In-progress indexes:"); for (const auto& entry : _buildingIndexes) { const IndexDescriptor* desc = entry->descriptor(); - error() << "Index '" << desc->indexName() - << "' with specification: " << redact(desc->infoObj()); + LOGV2_ERROR(20369, + "Index '{desc_indexName}' with specification: {desc_infoObj}", + "desc_indexName"_attr = desc->indexName(), + "desc_infoObj"_attr = redact(desc->infoObj())); } - error() << "Internal Collection Catalog Entry state:"; + LOGV2_ERROR(20370, "Internal Collection Catalog Entry state:"); std::vector<std::string> allIndexes; std::vector<std::string> readyIndexes; @@ -260,23 +271,36 @@ void IndexCatalogImpl::_logInternalState(OperationContext* opCtx, durableCatalog->getAllIndexes(opCtx, _collection->getCatalogId(), &allIndexes); durableCatalog->getReadyIndexes(opCtx, _collection->getCatalogId(), &readyIndexes); - error() << "All indexes:"; + LOGV2_ERROR(20371, "All indexes:"); for (const auto& index : allIndexes) { - error() << "Index '" << index << "' with specification: " - << redact(durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index)); + LOGV2_ERROR(20372, + "Index '{index}' with specification: " + "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index}", + "index"_attr = index, + "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index"_attr = redact( + durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index))); } - error() << "Ready indexes:"; + LOGV2_ERROR(20373, "Ready indexes:"); for (const auto& index : readyIndexes) { - error() << "Index '" << index << "' with specification: " - << redact(durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index)); + LOGV2_ERROR(20374, + "Index '{index}' with specification: " + "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index}", + "index"_attr = index, + "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index"_attr = redact( + durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index))); } - error() << "Index names to drop:"; + LOGV2_ERROR(20375, "Index names to drop:"); for (const auto& indexNameToDrop : indexNamesToDrop) { - error() << "Index '" << indexNameToDrop << "' with specification: " - << redact(durableCatalog->getIndexSpec( - opCtx, _collection->getCatalogId(), indexNameToDrop)); + LOGV2_ERROR( + 20376, + "Index '{indexNameToDrop}' with specification: " + "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_indexNameToDrop}", + "indexNameToDrop"_attr = indexNameToDrop, + "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_indexNameToDrop"_attr = + redact(durableCatalog->getIndexSpec( + opCtx, _collection->getCatalogId(), indexNameToDrop))); } } @@ -364,8 +388,12 @@ IndexCatalogEntry* IndexCatalogImpl::createIndexEntry(OperationContext* opCtx, CreateIndexEntryFlags flags) { Status status = _isSpecOk(opCtx, descriptor->infoObj()); if (!status.isOK()) { - severe() << "Found an invalid index " << descriptor->infoObj() << " on the " - << _collection->ns() << " collection: " << redact(status); + LOGV2_FATAL(20378, + "Found an invalid index {descriptor_infoObj} on the {collection_ns} " + "collection: {status}", + "descriptor_infoObj"_attr = descriptor->infoObj(), + "collection_ns"_attr = _collection->ns(), + "status"_attr = redact(status)); fassertFailedNoTrace(28782); } @@ -788,8 +816,13 @@ Status IndexCatalogImpl::_doesSpecConflictWithExisting(OperationContext* opCtx, const IndexDescriptor* desc = findIndexByKeyPatternAndCollationSpec(opCtx, key, collation, includeUnfinishedIndexes); if (desc) { - LOG(2) << "Index already exists with a different name: " << name << " pattern: " << key - << " collation: " << collation; + LOGV2_DEBUG(20353, + 2, + "Index already exists with a different name: {name} pattern: {key} " + "collation: {collation}", + "name"_attr = name, + "key"_attr = key, + "collation"_attr = collation); IndexDescriptor temp(_collection, _getAccessMethodName(key), spec); if (!desc->areIndexOptionsEquivalent(&temp)) @@ -807,7 +840,7 @@ Status IndexCatalogImpl::_doesSpecConflictWithExisting(OperationContext* opCtx, if (numIndexesTotal(opCtx) >= kMaxNumIndexesAllowed) { string s = str::stream() << "add index fails, too many indexes for " << _collection->ns() << " key:" << key; - log() << s; + LOGV2(20354, "{s}", "s"_attr = s); return Status(ErrorCodes::CannotCreateIndex, s); } @@ -875,7 +908,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx, string indexName = indexNamesToDrop[i]; const IndexDescriptor* desc = findIndexByName(opCtx, indexName, true); invariant(desc); - LOG(1) << "\t dropAllIndexes dropping: " << desc->toString(); + LOGV2_DEBUG(20355, 1, "\t dropAllIndexes dropping: {desc}", "desc"_attr = desc->toString()); IndexCatalogEntry* entry = _readyIndexes.find(desc); invariant(entry); @@ -1019,8 +1052,12 @@ void IndexCatalogImpl::deleteIndexFromDisk(OperationContext* opCtx, const string * This is ok, as we may be partially through index creation. */ } else if (!status.isOK()) { - warning() << "couldn't drop index " << indexName << " on collection: " << _collection->ns() - << " because of " << redact(status); + LOGV2_WARNING( + 20364, + "couldn't drop index {indexName} on collection: {collection_ns} because of {status}", + "indexName"_attr = indexName, + "collection_ns"_attr = _collection->ns(), + "status"_attr = redact(status)); } } @@ -1076,7 +1113,7 @@ int IndexCatalogImpl::numIndexesTotal(OperationContext* opCtx) const { } // Ignore the write conflict for read transactions; we will eventually roll back this // transaction anyway. - log() << " Skipping dassert check due to: " << ex; + LOGV2(20356, " Skipping dassert check due to: {ex}", "ex"_attr = ex); } } @@ -1097,17 +1134,19 @@ int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const { // There is a potential inconistency where the index information in the collection catalog // entry and the index catalog differ. Log as much information as possible here. if (itIndexes.size() != completedIndexes.size()) { - log() << "index catalog reports: "; + LOGV2(20357, "index catalog reports: "); for (const IndexDescriptor* i : itIndexes) { - log() << " index: " << i->toString(); + LOGV2(20358, " index: {i}", "i"_attr = i->toString()); } - log() << "collection catalog reports: "; + LOGV2(20359, "collection catalog reports: "); for (auto const& i : completedIndexes) { - log() << " index: " << i; + LOGV2(20360, " index: {i}", "i"_attr = i); } - log() << "collection uuid: " << _collection->uuid(); + LOGV2(20361, + "collection uuid: {collection_uuid}", + "collection_uuid"_attr = _collection->uuid()); invariant(itIndexes.size() == completedIndexes.size(), "The number of ready indexes reported in the collection metadata catalog did " @@ -1484,8 +1523,11 @@ void IndexCatalogImpl::_unindexKeys(OperationContext* opCtx, Status status = index->accessMethod()->removeKeys(opCtx, keys, loc, options, &removed); if (!status.isOK()) { - log() << "Couldn't unindex record " << redact(obj) << " from collection " - << _collection->ns() << ". Status: " << redact(status); + LOGV2(20362, + "Couldn't unindex record {obj} from collection {collection_ns}. Status: {status}", + "obj"_attr = redact(obj), + "collection_ns"_attr = _collection->ns(), + "status"_attr = redact(status)); } if (keysDeletedOut) { @@ -1615,10 +1657,15 @@ Status IndexCatalogImpl::compactIndexes(OperationContext* opCtx) { ++it) { IndexCatalogEntry* entry = it->get(); - LOG(1) << "compacting index: " << entry->descriptor()->toString(); + LOGV2_DEBUG(20363, + 1, + "compacting index: {entry_descriptor}", + "entry_descriptor"_attr = entry->descriptor()->toString()); Status status = entry->accessMethod()->compact(opCtx); if (!status.isOK()) { - error() << "failed to compact index: " << entry->descriptor()->toString(); + LOGV2_ERROR(20377, + "failed to compact index: {entry_descriptor}", + "entry_descriptor"_attr = entry->descriptor()->toString()); return status; } } diff --git a/src/mongo/db/catalog/index_timestamp_helper.cpp b/src/mongo/db/catalog/index_timestamp_helper.cpp index 8686e7af8f8..55e8dd04d74 100644 --- a/src/mongo/db/catalog/index_timestamp_helper.cpp +++ b/src/mongo/db/catalog/index_timestamp_helper.cpp @@ -35,6 +35,7 @@ #include "mongo/db/logical_clock.h" #include "mongo/db/repl/member_state.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -94,10 +95,15 @@ void IndexTimestampHelper::setGhostCommitTimestampForWrite(OperationContext* opC auto status = opCtx->recoveryUnit()->setTimestamp(commitTimestamp); if (status.code() == ErrorCodes::BadValue) { - log() << "Temporarily could not apply ghost commit timestamp. " << status.reason(); + LOGV2(20379, + "Temporarily could not apply ghost commit timestamp. {status_reason}", + "status_reason"_attr = status.reason()); throw WriteConflictException(); } - LOG(1) << "assigning ghost commit timestamp: " << commitTimestamp.toString(); + LOGV2_DEBUG(20380, + 1, + "assigning ghost commit timestamp: {commitTimestamp}", + "commitTimestamp"_attr = commitTimestamp.toString()); fassert(51053, status); } @@ -153,8 +159,9 @@ bool IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(OperationConte auto status = opCtx->recoveryUnit()->setTimestamp( LogicalClock::get(opCtx)->getClusterTime().asTimestamp()); if (status.code() == ErrorCodes::BadValue) { - log() << "Temporarily could not timestamp the index build commit, retrying. " - << status.reason(); + LOGV2(20381, + "Temporarily could not timestamp the index build commit, retrying. {status_reason}", + "status_reason"_attr = status.reason()); throw WriteConflictException(); } fassert(50701, status); diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index 06cf823e09c..b3a7aaf8209 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -54,6 +54,7 @@ #include "mongo/db/storage/storage_options.h" #include "mongo/db/storage/write_unit_of_work.h" #include "mongo/logger/redaction.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -141,7 +142,7 @@ void MultiIndexBlock::cleanUpAfterBuild(OperationContext* opCtx, // Simply get a timestamp to write with here; we can't write to the oplog. repl::UnreplicatedWritesBlock uwb(opCtx); if (!IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(opCtx, nss)) { - log() << "Did not timestamp index abort write."; + LOGV2(20382, "Did not timestamp index abort write."); } } @@ -155,11 +156,16 @@ void MultiIndexBlock::cleanUpAfterBuild(OperationContext* opCtx, } catch (const DBException& e) { if (e.toStatus() == ErrorCodes::ExceededMemoryLimit) continue; - error() << "Caught exception while cleaning up partially built indexes: " << redact(e); + LOGV2_ERROR(20393, + "Caught exception while cleaning up partially built indexes: {e}", + "e"_attr = redact(e)); } catch (const std::exception& e) { - error() << "Caught exception while cleaning up partially built indexes: " << e.what(); + LOGV2_ERROR(20394, + "Caught exception while cleaning up partially built indexes: {e_what}", + "e_what"_attr = e.what()); } catch (...) { - error() << "Caught unknown exception while cleaning up partially built indexes."; + LOGV2_ERROR(20395, + "Caught unknown exception while cleaning up partially built indexes."); } fassertFailed(18644); } @@ -238,9 +244,10 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx, BSONObj info = indexSpecs[i]; if (enableHybrid) { if (info["background"].isBoolean() && !info["background"].Bool()) { - log() - << "ignoring obselete { background: false } index build option because all " - "indexes are built in the background with the hybrid method"; + LOGV2( + 20383, + "ignoring obselete {{ background: false }} index build option because all " + "indexes are built in the background with the hybrid method"); } continue; } @@ -321,11 +328,17 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx, } index.options.fromIndexBuilder = true; - log() << "index build: starting on " << ns << " properties: " << descriptor->toString() - << " using method: " << _method; + LOGV2(20384, + "index build: starting on {ns} properties: {descriptor} using method: {method}", + "ns"_attr = ns, + "descriptor"_attr = descriptor->toString(), + "method"_attr = _method); if (index.bulk) - log() << "build may temporarily use up to " - << eachIndexBuildMaxMemoryUsageBytes / 1024 / 1024 << " megabytes of RAM"; + LOGV2(20385, + "build may temporarily use up to " + "{eachIndexBuildMaxMemoryUsageBytes_1024_1024} megabytes of RAM", + "eachIndexBuildMaxMemoryUsageBytes_1024_1024"_attr = + eachIndexBuildMaxMemoryUsageBytes / 1024 / 1024); index.filterExpression = index.block->getEntry()->getFilterExpression(); @@ -367,7 +380,8 @@ void failPointHangDuringBuild(FailPoint* fp, StringData where, const BSONObj& do fp->executeIf( [&](const BSONObj& data) { int i = doc.getIntField("i"); - log() << "Hanging " << where << " index build of i=" << i; + LOGV2( + 20386, "Hanging {where} index build of i={i}", "where"_attr = where, "i"_attr = i); fp->pauseWhileSet(); }, [&](const BSONObj& data) { @@ -405,13 +419,13 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, if (MONGO_unlikely(hangAfterSettingUpIndexBuild.shouldFail())) { // Hang the build after the BackgroundOperation and curOP info is set up. - log() << "Hanging index build due to failpoint 'hangAfterSettingUpIndexBuild'"; + LOGV2(20387, "Hanging index build due to failpoint 'hangAfterSettingUpIndexBuild'"); hangAfterSettingUpIndexBuild.pauseWhileSet(); } if (MONGO_unlikely(hangAndThenFailIndexBuild.shouldFail())) { // Hang the build after the BackgroundOperation and curOP info is set up. - log() << "Hanging index build due to failpoint 'hangAndThenFailIndexBuild'"; + LOGV2(20388, "Hanging index build due to failpoint 'hangAndThenFailIndexBuild'"); hangAndThenFailIndexBuild.pauseWhileSet(); return {ErrorCodes::InternalError, "Failed index build because of failpoint 'hangAndThenFailIndexBuild'"}; @@ -518,8 +532,9 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, } if (MONGO_unlikely(leaveIndexBuildUnfinishedForShutdown.shouldFail())) { - log() << "Index build interrupted due to 'leaveIndexBuildUnfinishedForShutdown' failpoint. " - "Mimicking shutdown error code."; + LOGV2(20389, + "Index build interrupted due to 'leaveIndexBuildUnfinishedForShutdown' failpoint. " + "Mimicking shutdown error code."); return Status( ErrorCodes::InterruptedAtShutdown, "background index build interrupted due to failpoint. returning a shutdown error."); @@ -530,8 +545,9 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, Locker::LockSnapshot lockInfo; invariant(opCtx->lockState()->saveLockStateAndUnlock(&lockInfo)); - log() << "Hanging index build with no locks due to " - "'hangAfterStartingIndexBuildUnlocked' failpoint"; + LOGV2(20390, + "Hanging index build with no locks due to " + "'hangAfterStartingIndexBuildUnlocked' failpoint"); hangAfterStartingIndexBuildUnlocked.pauseWhileSet(); if (isBackgroundBuilding()) { @@ -546,8 +562,10 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, progress->finished(); - log() << "index build: collection scan done. scanned " << n << " total records in " - << t.seconds() << " seconds"; + LOGV2(20391, + "index build: collection scan done. scanned {n} total records in {t_seconds} seconds", + "n"_attr = n, + "t_seconds"_attr = t.seconds()); Status ret = dumpInsertsFromBulk(opCtx); if (!ret.isOK()) @@ -614,8 +632,11 @@ Status MultiIndexBlock::dumpInsertsFromBulk(OperationContext* opCtx, : _indexes[i].options.dupsAllowed; IndexCatalogEntry* entry = _indexes[i].block->getEntry(); - LOG(1) << "index build: inserting from external sorter into index: " - << entry->descriptor()->indexName(); + LOGV2_DEBUG( + 20392, + 1, + "index build: inserting from external sorter into index: {entry_descriptor_indexName}", + "entry_descriptor_indexName"_attr = entry->descriptor()->indexName()); // SERVER-41918 This call to commitBulk() results in file I/O that may result in an // exception. diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index a8c9cf968da..36b5e941a35 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -58,6 +58,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -172,9 +173,15 @@ Status renameTargetCollectionToTmp(OperationContext* opCtx, wunit.commit(); - log() << "Successfully renamed the target " << targetNs << " (" << targetUUID << ") to " - << tmpName << " so that the source " << sourceNs << " (" << sourceUUID - << ") could be renamed to " << targetNs; + LOGV2(20397, + "Successfully renamed the target {targetNs} ({targetUUID}) to {tmpName} so that the " + "source {sourceNs} ({sourceUUID}) could be renamed to {targetNs2}", + "targetNs"_attr = targetNs, + "targetUUID"_attr = targetUUID, + "tmpName"_attr = tmpName, + "sourceNs"_attr = sourceNs, + "sourceUUID"_attr = sourceUUID, + "targetNs2"_attr = targetNs); return Status::OK(); }); @@ -245,9 +252,13 @@ Status renameCollectionAndDropTarget(OperationContext* opCtx, // 'renameOpTime' must be null because a valid 'renameOpTimeFromApplyOps' implies // replicated writes are not enabled. if (!renameOpTime.isNull()) { - severe() << "renameCollection: " << source << " to " << target - << " (with dropTarget=true) - unexpected renameCollection oplog entry" - << " written to the oplog with optime " << renameOpTime; + LOGV2_FATAL( + 20403, + "renameCollection: {source} to {target} (with dropTarget=true) - unexpected " + "renameCollection oplog entry written to the oplog with optime {renameOpTime}", + "source"_attr = source, + "target"_attr = target, + "renameOpTime"_attr = renameOpTime); fassertFailed(40616); } renameOpTime = renameOpTimeFromApplyOps; @@ -547,8 +558,11 @@ Status renameBetweenDBs(OperationContext* opCtx, } const auto& tmpName = tmpNameResult.getValue(); - log() << "Attempting to create temporary collection: " << tmpName - << " with the contents of collection: " << source; + LOGV2(20398, + "Attempting to create temporary collection: {tmpName} with the contents of collection: " + "{source}", + "tmpName"_attr = tmpName, + "source"_attr = source); Collection* tmpColl = nullptr; { @@ -582,8 +596,13 @@ Status renameBetweenDBs(OperationContext* opCtx, if (!status.isOK()) { // Ignoring failure case when dropping the temporary collection during cleanup because // the rename operation has already failed for another reason. - log() << "Unable to drop temporary collection " << tmpName << " while renaming from " - << source << " to " << target << ": " << status; + LOGV2(20399, + "Unable to drop temporary collection {tmpName} while renaming from {source} to " + "{target}: {status}", + "tmpName"_attr = tmpName, + "source"_attr = source, + "target"_attr = target, + "status"_attr = status); } }); @@ -840,7 +859,11 @@ Status renameCollection(OperationContext* opCtx, const std::string dropTargetMsg = options.dropTarget ? " and drop " + target.toString() + "." : "."; - log() << "renameCollectionForCommand: rename " << source << " to " << target << dropTargetMsg; + LOGV2(20400, + "renameCollectionForCommand: rename {source} to {target}{dropTargetMsg}", + "source"_attr = source, + "target"_attr = target, + "dropTargetMsg"_attr = dropTargetMsg); if (source.db() == target.db()) return renameCollectionWithinDB(opCtx, source, target, options); @@ -936,8 +959,13 @@ Status renameCollectionForApplyOps(OperationContext* opCtx, const std::string dropTargetMsg = uuidToDrop ? " and drop " + uuidToDrop->toString() + "." : "."; const std::string uuidString = uuidToRename ? uuidToRename->toString() : "UUID unknown"; - log() << "renameCollectionForApplyOps: rename " << sourceNss << " (" << uuidString << ") to " - << targetNss << dropTargetMsg; + LOGV2(20401, + "renameCollectionForApplyOps: rename {sourceNss} ({uuidString}) to " + "{targetNss}{dropTargetMsg}", + "sourceNss"_attr = sourceNss, + "uuidString"_attr = uuidString, + "targetNss"_attr = targetNss, + "dropTargetMsg"_attr = dropTargetMsg); if (sourceNss.db() == targetNss.db()) { return renameCollectionWithinDBForApplyOps( @@ -958,8 +986,11 @@ Status renameCollectionForRollback(OperationContext* opCtx, "have the same database. source: " << *source << ". target: " << target); - log() << "renameCollectionForRollback: rename " << *source << " (" << uuid << ") to " << target - << "."; + LOGV2(20402, + "renameCollectionForRollback: rename {source} ({uuid}) to {target}.", + "source"_attr = *source, + "uuid"_attr = uuid, + "target"_attr = target); return renameCollectionWithinDB(opCtx, *source, target, {}); } diff --git a/src/mongo/db/catalog/validate_adaptor.cpp b/src/mongo/db/catalog/validate_adaptor.cpp index 78c4e00239b..18c3157dabd 100644 --- a/src/mongo/db/catalog/validate_adaptor.cpp +++ b/src/mongo/db/catalog/validate_adaptor.cpp @@ -46,6 +46,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/storage/key_string.h" #include "mongo/db/storage/record_store.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/object_check.h" #include "mongo/util/log.h" @@ -278,7 +279,7 @@ void ValidateAdaptor::traverseRecordStore(OperationContext* opCtx, ss << "Reason: Validated size of " << validatedSize << " bytes does not equal the record size of " << dataSize << " bytes"; } - log() << std::string(ss); + LOGV2(20404, "{std_string_ss}", "std_string_ss"_attr = std::string(ss)); // Only log once if (results->valid) { diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index 4abd966b19e..843d7527c9b 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -42,6 +42,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -167,8 +168,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { } catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) { invariant(_background); // End the validation if we can't open a checkpoint cursor on the collection. - log() << "Skipping background validation on collection '" << _nss - << "' because the collection is not yet in a checkpoint: " << ex; + LOGV2(20405, + "Skipping background validation on collection '{nss}' because the collection is not " + "yet in a checkpoint: {ex}", + "nss"_attr = _nss, + "ex"_attr = ex); throw; } @@ -178,8 +182,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { opCtx, _collection->getCatalogId(), &readyDurableIndexes); } catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) { invariant(_background); - log() << "Skipping background validation on collection '" << _nss - << "' because the data is not yet in a checkpoint: " << ex; + LOGV2(20406, + "Skipping background validation on collection '{nss}' because the data is not yet in " + "a checkpoint: {ex}", + "nss"_attr = _nss, + "ex"_attr = ex); throw; } @@ -197,8 +204,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { std::find(readyDurableIndexes.begin(), readyDurableIndexes.end(), desc->indexName()) != readyDurableIndexes.end(); if (_background && !isIndexDurable) { - log() << "Skipping validation on index '" << desc->indexName() << "' in collection '" - << _nss << "' because the index is not yet in a checkpoint."; + LOGV2(20407, + "Skipping validation on index '{desc_indexName}' in collection '{nss}' because " + "the index is not yet in a checkpoint.", + "desc_indexName"_attr = desc->indexName(), + "nss"_attr = _nss); continue; } @@ -211,8 +221,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { opCtx->getServiceContext()->getStorageEngine()->getCatalog()->getIndexIdent( opCtx, _collection->getCatalogId(), desc->indexName()); if (entry->getIdent() != diskIndexIdent) { - log() << "Skipping validation on index '" << desc->indexName() << "' in collection '" - << _nss << "' because the index was recreated and is not yet in a checkpoint."; + LOGV2(20408, + "Skipping validation on index '{desc_indexName}' in collection '{nss}' because " + "the index was recreated and is not yet in a checkpoint.", + "desc_indexName"_attr = desc->indexName(), + "nss"_attr = _nss); continue; } @@ -224,8 +237,12 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { invariant(_background); // This can only happen if the checkpoint has the MDB catalog entry for the index, but // not the corresponding index table. - log() << "Skipping validation on index '" << desc->indexName() << "' in collection '" - << _nss << "' because the index data is not in a checkpoint: " << ex; + LOGV2(20409, + "Skipping validation on index '{desc_indexName}' in collection '{nss}' because " + "the index data is not in a checkpoint: {ex}", + "desc_indexName"_attr = desc->indexName(), + "nss"_attr = _nss, + "ex"_attr = ex); continue; } @@ -235,8 +252,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { opCtx->getServiceContext()->getStorageEngine()->isInIndividuallyCheckpointedIndexesList( diskIndexIdent)) { _indexCursors.erase(desc->indexName()); - log() << "Skipping validation on index '" << desc->indexName() << "' in collection '" - << _nss << "' because the index data is not yet consistent in the checkpoint."; + LOGV2(20410, + "Skipping validation on index '{desc_indexName}' in collection '{nss}' because " + "the index data is not yet consistent in the checkpoint.", + "desc_indexName"_attr = desc->indexName(), + "nss"_attr = _nss); continue; } @@ -261,7 +281,7 @@ void ValidateState::_relockDatabaseAndCollection(OperationContext* opCtx) { _databaseLock.reset(); if (MONGO_unlikely(hangDuringYieldingLocksForValidation.shouldFail())) { - log() << "Hanging on fail point 'hangDuringYieldingLocksForValidation'"; + LOGV2(20411, "Hanging on fail point 'hangDuringYieldingLocksForValidation'"); hangDuringYieldingLocksForValidation.pauseWhileSet(); } diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp index b717c19b2b4..5165baebc55 100644 --- a/src/mongo/db/catalog_raii_test.cpp +++ b/src/mongo/db/catalog_raii_test.cpp @@ -41,6 +41,7 @@ #include "mongo/db/concurrency/lock_state.h" #include "mongo/db/service_context_test_fixture.h" #include "mongo/db/storage/recovery_unit_noop.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" #include "mongo/util/time_support.h" @@ -79,7 +80,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis func(); FAIL("Should have gotten an exception due to timeout"); } catch (const ExceptionFor<ErrorCodes::LockTimeout>& ex) { - log() << ex; + LOGV2(20396, "{ex}", "ex"_attr = ex); Date_t t2 = Date_t::now(); ASSERT_GTE(t2 - t1, timeoutMillis); } diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 3c3f97cd03a..8dd960c2a2c 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -62,6 +62,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -155,7 +156,10 @@ struct Cloner::Fun { if (now - lastLog >= 60) { // report progress if (lastLog) - log() << "clone " << to_collection << ' ' << numSeen; + LOGV2(20412, + "clone {to_collection} {numSeen}", + "to_collection"_attr = to_collection, + "numSeen"_attr = numSeen); lastLog = now; } opCtx->checkForInterrupt(); @@ -216,7 +220,7 @@ struct Cloner::Fun { ss << "Cloner: found corrupt document in " << from_collection.toString() << ": " << redact(status); if (gSkipCorruptDocumentsWhenCloning.load()) { - warning() << ss.ss.str() << "; skipping"; + LOGV2_WARNING(20423, "{ss_ss_str}; skipping", "ss_ss_str"_attr = ss.ss.str()); continue; } msgasserted(28531, ss); @@ -235,8 +239,12 @@ struct Cloner::Fun { Status status = collection->insertDocument(opCtx, InsertStatement(doc), nullOpDebug, true); if (!status.isOK() && status.code() != ErrorCodes::DuplicateKey) { - error() << "error: exception cloning object in " << from_collection << ' ' - << redact(status) << " obj:" << redact(doc); + LOGV2_ERROR( + 20424, + "error: exception cloning object in {from_collection} {status} obj:{doc}", + "from_collection"_attr = from_collection, + "status"_attr = redact(status), + "doc"_attr = redact(doc)); uassertStatusOK(status); } if (status.isOK()) { @@ -246,7 +254,10 @@ struct Cloner::Fun { static Rarely sampler; if (sampler.tick() && (time(nullptr) - saveLast > 60)) { - log() << numSeen << " objects cloned so far from collection " << from_collection; + LOGV2(20413, + "{numSeen} objects cloned so far from collection {from_collection}", + "numSeen"_attr = numSeen, + "from_collection"_attr = from_collection); saveLast = time(nullptr); } } @@ -275,8 +286,14 @@ void Cloner::copy(OperationContext* opCtx, const NamespaceString& to_collection, const CloneOptions& opts, Query query) { - LOG(2) << "\t\tcloning collection " << from_collection << " to " << to_collection << " on " - << _conn->getServerAddress() << " with filter " << redact(query.toString()); + LOGV2_DEBUG(20414, + 2, + "\t\tcloning collection {from_collection} to {to_collection} on " + "{conn_getServerAddress} with filter {query}", + "from_collection"_attr = from_collection, + "to_collection"_attr = to_collection, + "conn_getServerAddress"_attr = _conn->getServerAddress(), + "query"_attr = redact(query.toString())); Fun f(opCtx, toDBName); f.numSeen = 0; @@ -311,8 +328,12 @@ void Cloner::copyIndexes(OperationContext* opCtx, const BSONObj& from_opts, const std::list<BSONObj>& from_indexes, const NamespaceString& to_collection) { - LOG(2) << "\t\t copyIndexes " << from_collection << " to " << to_collection << " on " - << _conn->getServerAddress(); + LOGV2_DEBUG(20415, + 2, + "\t\t copyIndexes {from_collection} to {to_collection} on {conn_getServerAddress}", + "from_collection"_attr = from_collection, + "to_collection"_attr = to_collection, + "conn_getServerAddress"_attr = _conn->getServerAddress()); uassert(ErrorCodes::PrimarySteppedDown, str::stream() << "Not primary while copying indexes from " << from_collection.ns() @@ -506,8 +527,11 @@ bool Cloner::copyCollection(OperationContext* opCtx, return result; } } else { - LOG(1) << "No collection info found for ns:" << nss.toString() - << ", host:" << _conn->getServerAddress(); + LOGV2_DEBUG(20416, + 1, + "No collection info found for ns:{nss}, host:{conn_getServerAddress}", + "nss"_attr = nss.toString(), + "conn_getServerAddress"_attr = _conn->getServerAddress()); } // main data @@ -517,7 +541,8 @@ bool Cloner::copyCollection(OperationContext* opCtx, /* TODO : copyIndexes bool does not seem to be implemented! */ if (!shouldCopyIndexes) { - log() << "ERROR copy collection shouldCopyIndexes not implemented? " << ns; + LOGV2( + 20417, "ERROR copy collection shouldCopyIndexes not implemented? {ns}", "ns"_attr = ns); } // indexes @@ -530,7 +555,7 @@ StatusWith<std::vector<BSONObj>> Cloner::filterCollectionsForClone( const CloneOptions& opts, const std::list<BSONObj>& initialCollections) { std::vector<BSONObj> finalCollections; for (auto&& collection : initialCollections) { - LOG(2) << "\t cloner got " << collection; + LOGV2_DEBUG(20418, 2, "\t cloner got {collection}", "collection"_attr = collection); BSONElement collectionOptions = collection["options"]; if (collectionOptions.isABSONObj()) { @@ -551,7 +576,7 @@ StatusWith<std::vector<BSONObj>> Cloner::filterCollectionsForClone( if (ns.isSystem()) { if (!ns.isLegalClientSystemNS()) { - LOG(2) << "\t\t not cloning because system collection"; + LOGV2_DEBUG(20419, 2, "\t\t not cloning because system collection"); continue; } } @@ -785,7 +810,10 @@ Status Cloner::copyDb(OperationContext* opCtx, continue; } - LOG(2) << " really will clone: " << params.collectionInfo; + LOGV2_DEBUG(20420, + 2, + " really will clone: {params_collectionInfo}", + "params_collectionInfo"_attr = params.collectionInfo); const NamespaceString from_name(opts.fromDB, params.collectionName); const NamespaceString to_name(toDBName, params.collectionName); @@ -794,7 +822,11 @@ Status Cloner::copyDb(OperationContext* opCtx, clonedColls->insert(from_name.ns()); } - LOG(1) << "\t\t cloning " << from_name << " -> " << to_name; + LOGV2_DEBUG(20421, + 1, + "\t\t cloning {from_name} -> {to_name}", + "from_name"_attr = from_name, + "to_name"_attr = to_name); copy(opCtx, toDBName, @@ -810,7 +842,9 @@ Status Cloner::copyDb(OperationContext* opCtx, // now build the secondary indexes if (opts.syncIndexes) { for (auto&& params : createCollectionParams) { - log() << "copying indexes for: " << params.collectionInfo; + LOGV2(20422, + "copying indexes for: {params_collectionInfo}", + "params_collectionInfo"_attr = params.collectionInfo); const NamespaceString from_name(opts.fromDB, params.collectionName); const NamespaceString to_name(toDBName, params.collectionName); diff --git a/src/mongo/db/collection_index_builds_tracker.cpp b/src/mongo/db/collection_index_builds_tracker.cpp index 40b4f292c27..677aa17fa3a 100644 --- a/src/mongo/db/collection_index_builds_tracker.cpp +++ b/src/mongo/db/collection_index_builds_tracker.cpp @@ -34,6 +34,7 @@ #include "mongo/db/collection_index_builds_tracker.h" #include "mongo/db/catalog/index_builds_manager.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -110,9 +111,11 @@ void CollectionIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_loc return true; } - log() << "Waiting until the following index builds are finished:"; + LOGV2(20425, "Waiting until the following index builds are finished:"); for (const auto& indexBuild : _buildStateByBuildUUID) { - log() << " Index build with UUID: " << indexBuild.first; + LOGV2(20426, + " Index build with UUID: {indexBuild_first}", + "indexBuild_first"_attr = indexBuild.first); } return false; diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index fbcf69dc8c2..6a94edbf374 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -54,6 +54,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/db/read_write_concern_defaults.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/factory.h" #include "mongo/rpc/metadata/client_metadata_ismaster.h" #include "mongo/rpc/op_msg_rpc_impls.h" @@ -572,8 +573,10 @@ void CommandHelpers::evaluateFailCommandFailPoint(OperationContext* opCtx, if (closeConnection) { opCtx->getClient()->session()->end(); - log() << "Failing command '" << cmd->getName() - << "' via 'failCommand' failpoint. Action: closing connection."; + LOGV2(20431, + "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: " + "closing connection.", + "cmd_getName"_attr = cmd->getName()); uasserted(50985, "Failing command due to 'failCommand' failpoint"); } @@ -587,24 +590,33 @@ void CommandHelpers::evaluateFailCommandFailPoint(OperationContext* opCtx, "'blockTimeMS' must be non-negative", blockTimeMS >= 0); - log() << "Blocking command '" << cmd->getName() - << "' via 'failCommand' failpoint for " << blockTimeMS << " milliseconds"; + LOGV2(20432, + "Blocking command '{cmd_getName}' via 'failCommand' failpoint for " + "{blockTimeMS} milliseconds", + "cmd_getName"_attr = cmd->getName(), + "blockTimeMS"_attr = blockTimeMS); opCtx->sleepFor(Milliseconds{blockTimeMS}); - log() << "Unblocking command '" << cmd->getName() - << "' via 'failCommand' failpoint"; + LOGV2(20433, + "Unblocking command '{cmd_getName}' via 'failCommand' failpoint", + "cmd_getName"_attr = cmd->getName()); } if (hasExtraInfo) { - log() << "Failing command '" << cmd->getName() - << "' via 'failCommand' failpoint. Action: returning error code " << errorCode - << " and " << errorExtraInfo << "."; + LOGV2(20434, + "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: " + "returning error code {errorCode} and {errorExtraInfo}.", + "cmd_getName"_attr = cmd->getName(), + "errorCode"_attr = errorCode, + "errorExtraInfo"_attr = errorExtraInfo); uassertStatusOK(Status(ErrorCodes::Error(errorCode), "Failing command due to 'failCommand' failpoint", errorExtraInfo.Obj())); } else if (hasErrorCode) { - log() << "Failing command '" << cmd->getName() - << "' via 'failCommand' failpoint. Action: returning error code " << errorCode - << "."; + LOGV2(20435, + "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: " + "returning error code {errorCode}.", + "cmd_getName"_attr = cmd->getName(), + "errorCode"_attr = errorCode); uasserted(ErrorCodes::Error(errorCode), "Failing command due to 'failCommand' failpoint"); } @@ -672,7 +684,10 @@ void CommandInvocation::checkAuthorization(OperationContext* opCtx, } } } catch (const DBException& e) { - log(LogComponent::kAccessControl) << e.toStatus(); + LOGV2_OPTIONS(20436, + {logComponentV1toV2(LogComponent::kAccessControl)}, + "{e_toStatus}", + "e_toStatus"_attr = e.toStatus()); CommandHelpers::auditLogAuthEvent(opCtx, this, request, e.code()); throw; } diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index d51d9815d08..9ce82d61531 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -54,6 +54,7 @@ #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/operation_context.h" #include "mongo/db/stats/counters.h" +#include "mongo/logv2/log.h" #include "mongo/platform/random.h" #include "mongo/rpc/metadata/client_metadata.h" #include "mongo/rpc/metadata/client_metadata_ismaster.h" @@ -116,8 +117,9 @@ Status _authenticateX509(OperationContext* opCtx, const UserName& user, const BS if (!clientMetadata->getApplicationName().empty() || (driverName != "MongoDB Internal Client" && driverName != "NetworkInterfaceTL")) { - warning() << "Client isn't a mongod or mongos, but is connecting with a " - "certificate with cluster membership"; + LOGV2_WARNING(20430, + "Client isn't a mongod or mongos, but is connecting with a " + "certificate with cluster membership"); } } @@ -256,7 +258,10 @@ bool CmdAuthenticate::run(OperationContext* opCtx, CommandHelpers::handleMarkKillOnClientDisconnect(opCtx); if (!serverGlobalParams.quiet.load()) { mutablebson::Document cmdToLog(cmdObj, mutablebson::Document::kInPlaceDisabled); - log() << " authenticate db: " << dbname << " " << cmdToLog; + LOGV2(20427, + " authenticate db: {dbname} {cmdToLog}", + "dbname"_attr = dbname, + "cmdToLog"_attr = cmdToLog); } std::string mechanism = cmdObj.getStringField("mechanism"); if (mechanism.empty()) { @@ -285,8 +290,13 @@ bool CmdAuthenticate::run(OperationContext* opCtx, if (!status.isOK()) { if (!serverGlobalParams.quiet.load()) { auto const client = opCtx->getClient(); - log() << "Failed to authenticate " << user << " from client " << client->getRemote() - << " with mechanism " << mechanism << ": " << status; + LOGV2(20428, + "Failed to authenticate {user} from client {client_getRemote} with mechanism " + "{mechanism}: {status}", + "user"_attr = user, + "client_getRemote"_attr = client->getRemote(), + "mechanism"_attr = mechanism, + "status"_attr = status); } sleepmillis(saslGlobalParams.authFailedDelay.load()); if (status.code() == ErrorCodes::AuthenticationFailed) { @@ -300,8 +310,12 @@ bool CmdAuthenticate::run(OperationContext* opCtx, } if (!serverGlobalParams.quiet.load()) { - log() << "Successfully authenticated as principal " << user.getUser() << " on " - << user.getDB() << " from client " << opCtx->getClient()->session()->remote(); + LOGV2(20429, + "Successfully authenticated as principal {user_getUser} on {user_getDB} from client " + "{opCtx_getClient_session_remote}", + "user_getUser"_attr = user.getUser(), + "user_getDB"_attr = user.getDB(), + "opCtx_getClient_session_remote"_attr = opCtx->getClient()->session()->remote()); } result.append("dbname", user.getDB()); 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. diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp index c933dd6ad34..42cfdf10cd6 100644 --- a/src/mongo/db/commands/dbcheck.cpp +++ b/src/mongo/db/commands/dbcheck.cpp @@ -47,6 +47,7 @@ #include "mongo/db/repl/optime.h" #include "mongo/util/background.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -210,7 +211,7 @@ protected: } if (_done) { - log() << "dbCheck terminated due to stepdown"; + LOGV2(20451, "dbCheck terminated due to stepdown"); return; } } diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp index aa82cdef7d3..8044d6abaef 100644 --- a/src/mongo/db/commands/dbcommands_d.cpp +++ b/src/mongo/db/commands/dbcommands_d.cpp @@ -86,6 +86,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/stats/storage_stats.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/s/stale_exception.h" #include "mongo/scripting/engine.h" #include "mongo/util/fail_point.h" @@ -280,7 +281,8 @@ public: if (partialOk) { break; // skipped chunk is probably on another shard } - log() << "should have chunk: " << n << " have:" << myn; + LOGV2( + 20452, "should have chunk: {n} have:{myn}", "n"_attr = n, "myn"_attr = myn); dumpChunks(opCtx, nss.ns(), query, sort); uassert(10040, "chunks out of order", n == myn); } @@ -315,7 +317,10 @@ public: // RELOCKED ctx.reset(new AutoGetCollectionForReadCommand(opCtx, nss)); } catch (const StaleConfigException&) { - LOG(1) << "chunk metadata changed during filemd5, will retarget and continue"; + LOGV2_DEBUG( + 20453, + 1, + "chunk metadata changed during filemd5, will retarget and continue"); break; } @@ -350,7 +355,7 @@ public: q.sort(sort); unique_ptr<DBClientCursor> c = client.query(NamespaceString(ns), q); while (c->more()) { - log() << c->nextSafe(); + LOGV2(20454, "{c_nextSafe}", "c_nextSafe"_attr = c->nextSafe()); } } diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index da181689560..7da824f9a10 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -50,6 +50,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/util/log.h" #include "mongo/util/md5.hpp" @@ -370,7 +371,7 @@ private: exec = InternalPlanner::collectionScan( opCtx, nss.ns(), collection, PlanExecutor::NO_YIELD); } else { - log() << "can't find _id index for: " << nss; + LOGV2(20455, "can't find _id index for: {nss}", "nss"_attr = nss); return "no _id _index"; } @@ -386,7 +387,7 @@ private: n++; } if (PlanExecutor::IS_EOF != state) { - warning() << "error while hashing, db dropped? ns=" << nss; + LOGV2_WARNING(20456, "error while hashing, db dropped? ns={nss}", "nss"_attr = nss); uasserted(34371, "Plan executor error while running dbHash command: " + WorkingSetCommon::toStatusString(c)); diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 033023ec710..58fee79a890 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -53,6 +53,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/quick_exit.h" @@ -126,7 +127,7 @@ public: const NamespaceString toReIndexNss = CommandHelpers::parseNsCollectionRequired(dbname, jsobj); - LOG(0) << "CMD: reIndex " << toReIndexNss; + LOGV2(20457, "CMD: reIndex {toReIndexNss}", "toReIndexNss"_attr = toReIndexNss); AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X); Collection* collection = autoColl.getCollection(); @@ -219,7 +220,7 @@ public: } if (MONGO_unlikely(reIndexCrashAfterDrop.shouldFail())) { - log() << "exiting because 'reIndexCrashAfterDrop' fail point was set"; + LOGV2(20458, "exiting because 'reIndexCrashAfterDrop' fail point was set"); quickExit(EXIT_ABRUPT); } diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp index c98457c1f86..0e9509623b6 100644 --- a/src/mongo/db/commands/feature_compatibility_version.cpp +++ b/src/mongo/db/commands/feature_compatibility_version.cpp @@ -52,6 +52,7 @@ #include "mongo/db/wire_version.h" #include "mongo/db/write_concern_options.h" #include "mongo/executor/egress_tag_closer_manager.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/grid.h" @@ -158,8 +159,11 @@ void FeatureCompatibilityVersion::onInsertOrUpdate(OperationContext* opCtx, cons ? serverGlobalParams.featureCompatibility.getVersion() != newVersion : true; if (isDifferent) { - log() << "setting featureCompatibilityVersion to " - << FeatureCompatibilityVersionParser::toString(newVersion); + LOGV2( + 20459, + "setting featureCompatibilityVersion to {FeatureCompatibilityVersionParser_newVersion}", + "FeatureCompatibilityVersionParser_newVersion"_attr = + FeatureCompatibilityVersionParser::toString(newVersion)); } // Remove term field of config document on downgrade. @@ -190,9 +194,10 @@ void FeatureCompatibilityVersion::onInsertOrUpdate(OperationContext* opCtx, cons if (newVersion != ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44) { if (MONGO_unlikely(hangBeforeAbortingRunningTransactionsOnFCVDowngrade.shouldFail())) { - log() << "featureCompatibilityVersion - " - "hangBeforeAbortingRunningTransactionsOnFCVDowngrade fail point enabled. " - "Blocking until fail point is disabled."; + LOGV2(20460, + "featureCompatibilityVersion - " + "hangBeforeAbortingRunningTransactionsOnFCVDowngrade fail point enabled. " + "Blocking until fail point is disabled."); hangBeforeAbortingRunningTransactionsOnFCVDowngrade.pauseWhileSet(); } // Abort all open transactions when downgrading the featureCompatibilityVersion. diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index 45ade956647..becd1c00ba6 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -49,6 +49,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/backup_cursor_hooks.h" #include "mongo/db/storage/storage_engine.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/condition_variable.h" #include "mongo/util/assert_util.h" #include "mongo/util/background.h" @@ -134,7 +135,7 @@ public: } const bool lock = cmdObj["lock"].trueValue(); - log() << "CMD fsync: lock:" << lock; + LOGV2(20461, "CMD fsync: lock:{lock}", "lock"_attr = lock); // fsync + lock is sometimes used to block writes out of the system and does not care if // the `BackupCursorService::fsyncLock` call succeeds. @@ -180,14 +181,18 @@ public: if (!status.isOK()) { releaseLock(); - warning() << "fsyncLock failed. Lock count reset to 0. Status: " << status; + LOGV2_WARNING(20468, + "fsyncLock failed. Lock count reset to 0. Status: {status}", + "status"_attr = status); uassertStatusOK(status); } } - log() << "mongod is locked and no writes are allowed. db.fsyncUnlock() to unlock"; - log() << "Lock count is " << getLockCount(); - log() << " For more info see " << FSyncCommand::url(); + LOGV2(20462, "mongod is locked and no writes are allowed. db.fsyncUnlock() to unlock"); + LOGV2(20463, "Lock count is {getLockCount}", "getLockCount"_attr = getLockCount()); + LOGV2(20464, + " For more info see {FSyncCommand_url}", + "FSyncCommand_url"_attr = FSyncCommand::url()); result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock"); result.append("lockCount", getLockCount()); result.append("seeAlso", FSyncCommand::url()); @@ -296,7 +301,7 @@ public: const BSONObj& cmdObj, std::string& errmsg, BSONObjBuilder& result) override { - log() << "command: unlock requested"; + LOGV2(20465, "command: unlock requested"); Lock::ExclusiveLock lk(opCtx->lockState(), commandMutex); @@ -316,11 +321,13 @@ public: // If we're still locked then lock count is not zero. invariant(lockCount > 0); lockCount = fsyncCmd.getLockCount_inLock(); - log() << "fsyncUnlock completed. Lock count is now " << lockCount; + LOGV2(20466, + "fsyncUnlock completed. Lock count is now {lockCount}", + "lockCount"_attr = lockCount); } else { invariant(fsyncCmd.getLockCount() == 0); lockCount = 0; - log() << "fsyncUnlock completed. mongod is now unlocked and free to accept writes"; + LOGV2(20467, "fsyncUnlock completed. mongod is now unlocked and free to accept writes"); } result.append("info", str::stream() << "fsyncUnlock completed"); @@ -357,7 +364,7 @@ void FSyncLockThread::run() { registerShutdownTask([&] { stdx::unique_lock<Latch> stateLock(fsyncCmd.lockStateMutex); if (fsyncCmd.getLockCount_inLock() > 0) { - warning() << "Interrupting fsync because the server is shutting down."; + LOGV2_WARNING(20469, "Interrupting fsync because the server is shutting down."); while (fsyncCmd.getLockCount_inLock()) { // Relies on the lock to be released in 'releaseLock_inLock()' when the // release brings the lock count to 0. @@ -371,7 +378,7 @@ void FSyncLockThread::run() { try { storageEngine->flushAllFiles(&opCtx, /*callerHoldsReadLock*/ true); } catch (const std::exception& e) { - error() << "error doing flushAll: " << e.what(); + LOGV2_ERROR(20472, "error doing flushAll: {e_what}", "e_what"_attr = e.what()); fsyncCmd.threadStatus = Status(ErrorCodes::CommandFailed, e.what()); fsyncCmd.acquireFsyncLockSyncCV.notify_one(); return; @@ -397,10 +404,12 @@ void FSyncLockThread::run() { }); } catch (const DBException& e) { if (_allowFsyncFailure) { - warning() << "Locking despite storage engine being unable to begin backup : " - << e.toString(); + LOGV2_WARNING(20470, + "Locking despite storage engine being unable to begin backup : {e}", + "e"_attr = e.toString()); } else { - error() << "storage engine unable to begin backup : " << e.toString(); + LOGV2_ERROR( + 20473, "storage engine unable to begin backup : {e}", "e"_attr = e.toString()); fsyncCmd.threadStatus = e.toStatus(); fsyncCmd.acquireFsyncLockSyncCV.notify_one(); return; @@ -411,8 +420,10 @@ void FSyncLockThread::run() { fsyncCmd.acquireFsyncLockSyncCV.notify_one(); while (fsyncCmd.getLockCount_inLock() > 0) { - warning() << "WARNING: instance is locked, blocking all writes. The fsync command has " - "finished execution, remember to unlock the instance using fsyncUnlock()."; + LOGV2_WARNING( + 20471, + "WARNING: instance is locked, blocking all writes. The fsync command has " + "finished execution, remember to unlock the instance using fsyncUnlock()."); fsyncCmd.releaseFsyncLockSyncCV.wait_for(lk, Seconds(60).toSystemDuration()); } @@ -425,7 +436,7 @@ void FSyncLockThread::run() { } } catch (const std::exception& e) { - severe() << "FSyncLockThread exception: " << e.what(); + LOGV2_FATAL(20474, "FSyncLockThread exception: {e_what}", "e_what"_attr = e.what()); fassertFailed(40350); } } diff --git a/src/mongo/db/commands/generic_servers.cpp b/src/mongo/db/commands/generic_servers.cpp index b398e6d59f2..51bfd5ab8b4 100644 --- a/src/mongo/db/commands/generic_servers.cpp +++ b/src/mongo/db/commands/generic_servers.cpp @@ -37,6 +37,7 @@ #include "mongo/db/commands/shutdown.h" #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/log_process_details.h" +#include "mongo/logv2/log.h" #include "mongo/logv2/ramlog.h" #include "mongo/scripting/engine.h" #include "mongo/util/exit.h" @@ -354,7 +355,7 @@ void CmdShutdown::shutdownHelper(const BSONObj& cmdObj) { ::abort(); }); - log() << "terminating, shutdown command received " << cmdObj; + LOGV2(20475, "terminating, shutdown command received {cmdObj}", "cmdObj"_attr = cmdObj); #if defined(_WIN32) // Signal the ServiceMain thread to shutdown. diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 1b674dd6ef7..531952af58e 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -41,6 +41,7 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -263,8 +264,13 @@ public: } } else { if (electionId != repl::ReplicationCoordinator::get(opCtx)->getElectionId()) { - LOG(3) << "oid passed in is " << electionId << ", but our id is " - << repl::ReplicationCoordinator::get(opCtx)->getElectionId(); + LOGV2_DEBUG(20476, + 3, + "oid passed in is {electionId}, but our id is " + "{repl_ReplicationCoordinator_get_opCtx_getElectionId}", + "electionId"_attr = electionId, + "repl_ReplicationCoordinator_get_opCtx_getElectionId"_attr = + repl::ReplicationCoordinator::get(opCtx)->getElectionId()); errmsg = "election occurred after write"; result.append("code", ErrorCodes::WriteConcernFailed); result.append("codeName", diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index 1795337753d..91b6804f691 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -57,6 +57,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/top.h" +#include "mongo/logv2/log.h" #include "mongo/s/chunk_version.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -328,9 +329,14 @@ public: auto status = WorkingSetCommon::getMemberObjectStatus(doc); invariant(!status.isOK()); // Log an error message and then perform the cleanup. - warning() << "GetMore command executor error: " - << PlanExecutor::statestr(*state) << ", status: " << status - << ", stats: " << redact(Explain::getWinningPlanStats(exec)); + LOGV2_WARNING(20478, + "GetMore command executor error: {PlanExecutor_statestr_state}, " + "status: {status}, stats: {Explain_getWinningPlanStats_exec}", + "PlanExecutor_statestr_state"_attr = + PlanExecutor::statestr(*state), + "status"_attr = status, + "Explain_getWinningPlanStats_exec"_attr = + redact(Explain::getWinningPlanStats(exec))); nextBatch->abandon(); return status; @@ -413,8 +419,9 @@ public: ClientCursorParams::LockPolicy::kLockExternally); if (MONGO_unlikely(GetMoreHangBeforeReadLock.shouldFail())) { - log() << "GetMoreHangBeforeReadLock fail point enabled. Blocking until fail " - "point is disabled."; + LOGV2(20477, + "GetMoreHangBeforeReadLock fail point enabled. Blocking until fail " + "point is disabled."); GetMoreHangBeforeReadLock.pauseWhileSet(opCtx); } diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp index 59dd614002a..e1348bb8eda 100644 --- a/src/mongo/db/commands/index_filter_commands.cpp +++ b/src/mongo/db/commands/index_filter_commands.cpp @@ -50,6 +50,7 @@ #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/collection_query_info.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/log.h" @@ -264,7 +265,9 @@ Status ClearFilters::clear(OperationContext* opCtx, // Remove entry from plan cache planCache->remove(*cq).transitional_ignore(); - LOG(0) << "Removed index filter on " << redact(cq->toStringShort()); + LOGV2(20479, + "Removed index filter on {cq_Short}", + "cq_Short"_attr = redact(cq->toStringShort())); return Status::OK(); } @@ -320,7 +323,7 @@ Status ClearFilters::clear(OperationContext* opCtx, planCache->remove(*cq).transitional_ignore(); } - LOG(0) << "Removed all index filters for collection: " << ns; + LOGV2(20480, "Removed all index filters for collection: {ns}", "ns"_attr = ns); return Status::OK(); } @@ -397,7 +400,10 @@ Status SetFilter::set(OperationContext* opCtx, // Remove entry from plan cache. planCache->remove(*cq).transitional_ignore(); - LOG(0) << "Index filter set on " << redact(cq->toStringShort()) << " " << indexesElt; + LOGV2(20481, + "Index filter set on {cq_Short} {indexesElt}", + "cq_Short"_attr = redact(cq->toStringShort()), + "indexesElt"_attr = indexesElt); return Status::OK(); } diff --git a/src/mongo/db/commands/kill_op.cpp b/src/mongo/db/commands/kill_op.cpp index 5a9b639427e..fa088731393 100644 --- a/src/mongo/db/commands/kill_op.cpp +++ b/src/mongo/db/commands/kill_op.cpp @@ -43,6 +43,7 @@ #include "mongo/db/commands/kill_op_cmd_base.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -58,7 +59,7 @@ public: // Used by tests to check if auth checks passed. result.append("info", "attempting to kill op"); - log() << "going to kill op: " << opId; + LOGV2(20482, "going to kill op: {opId}", "opId"_attr = opId); KillOpCmdBase::killLocalOperation(opCtx, opId); // killOp always reports success once past the auth check. diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index a9a8582f136..05f3d15e2ea 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -65,6 +65,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/parallel.h" @@ -467,7 +468,7 @@ Config::Config(const string& _dbname, const BSONObj& cmdObj) { // DEPRECATED if (auto mapParamsElem = cmdObj["mapparams"]) { if (mapParamsDeprecationSampler.tick()) { - warning() << "The mapparams option to MapReduce is deprecated."; + LOGV2_WARNING(20493, "The mapparams option to MapReduce is deprecated."); } if (mapParamsElem.type() == Array) { mapParams = mapParamsElem.embeddedObjectUserCheck().getOwned(); @@ -929,11 +930,12 @@ State::~State() { _config.tempNamespace, _useIncremental ? _config.incLong : NamespaceString()); } catch (...) { - error() << "Unable to drop temporary collection created by mapReduce: " - << _config.tempNamespace - << ". This collection will be removed automatically " - "the next time the server starts up. " - << exceptionToStatus(); + LOGV2_ERROR(20494, + "Unable to drop temporary collection created by mapReduce: " + "{config_tempNamespace}. This collection will be removed automatically " + "the next time the server starts up. {exceptionToStatus}", + "config_tempNamespace"_attr = _config.tempNamespace, + "exceptionToStatus"_attr = exceptionToStatus()); } } if (_scope && !_scope->isKillPending() && _scope->getError().empty()) { @@ -944,7 +946,7 @@ State::~State() { _scope->invoke(cleanup, nullptr, nullptr, 0, true); } catch (const DBException&) { // not important because properties will be reset if scope is reused - LOG(1) << "MapReduce terminated during state destruction"; + LOGV2_DEBUG(20483, 1, "MapReduce terminated during state destruction"); } } } @@ -1086,7 +1088,7 @@ void State::switchMode(bool jsMode) { } void State::bailFromJS() { - LOG(1) << "M/R: Switching from JS mode to mixed mode"; + LOGV2_DEBUG(20484, 1, "M/R: Switching from JS mode to mixed mode"); // reduce and reemit into c++ switchMode(false); @@ -1363,9 +1365,14 @@ void State::reduceAndSpillInMemoryStateIfNeeded() { // reduce now to lower mem usage Timer t; _scope->invoke(_reduceAll, nullptr, nullptr, 0, true); - LOG(3) << " MR - did reduceAll: keys=" << keyCt << " dups=" << dupCt - << " newKeys=" << _scope->getNumberInt("_keyCt") << " time=" << t.millis() - << "ms"; + LOGV2_DEBUG(20485, + 3, + " MR - did reduceAll: keys={keyCt} dups={dupCt} " + "newKeys={scope_getNumberInt_keyCt} time={t_millis}ms", + "keyCt"_attr = keyCt, + "dupCt"_attr = dupCt, + "scope_getNumberInt_keyCt"_attr = _scope->getNumberInt("_keyCt"), + "t_millis"_attr = t.millis()); return; } } @@ -1378,13 +1385,19 @@ void State::reduceAndSpillInMemoryStateIfNeeded() { long oldSize = _size; Timer t; reduceInMemory(); - LOG(3) << " MR - did reduceInMemory: size=" << oldSize << " dups=" << _dupCount - << " newSize=" << _size << " time=" << t.millis() << "ms"; + LOGV2_DEBUG(20486, + 3, + " MR - did reduceInMemory: size={oldSize} dups={dupCount} newSize={size} " + "time={t_millis}ms", + "oldSize"_attr = oldSize, + "dupCount"_attr = _dupCount, + "size"_attr = _size, + "t_millis"_attr = t.millis()); // if size is still high, or values are not reducing well, dump if (_onDisk && (_size > _config.maxInMemSize || _size > oldSize / 2)) { dumpToInc(); - LOG(3) << " MR - dumping to db"; + LOGV2_DEBUG(20487, 3, " MR - dumping to db"); } } } @@ -1411,7 +1424,7 @@ bool runMapReduce(OperationContext* opCtx, const Config config(dbname, cmd); - LOG(1) << "mr ns: " << config.nss; + LOGV2_DEBUG(20488, 1, "mr ns: {config_nss}", "config_nss"_attr = config.nss); uassert(16149, "cannot run map reduce without the js engine", getGlobalScriptEngine()); @@ -1638,19 +1651,19 @@ bool runMapReduce(OperationContext* opCtx, invariant(e.extraInfo<StaleConfigInfo>()->getShardId()); } - log() << "mr detected stale config, should retry" << redact(e); + LOGV2(20489, "mr detected stale config, should retry{e}", "e"_attr = redact(e)); throw; } // TODO: The error handling code for queries is v. fragile, // *requires* rethrow AssertionExceptions - should probably fix. catch (AssertionException& e) { - log() << "mr failed, removing collection" << redact(e); + LOGV2(20490, "mr failed, removing collection{e}", "e"_attr = redact(e)); throw; } catch (std::exception& e) { - log() << "mr failed, removing collection" << causedBy(e); + LOGV2(20491, "mr failed, removing collection{causedBy_e}", "causedBy_e"_attr = causedBy(e)); throw; } catch (...) { - log() << "mr failed for unknown reason, removing collection"; + LOGV2(20492, "mr failed for unknown reason, removing collection"); throw; } diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp index 2899d5b602f..b25debc548b 100644 --- a/src/mongo/db/commands/oplog_note.cpp +++ b/src/mongo/db/commands/oplog_note.cpp @@ -48,6 +48,7 @@ #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -60,7 +61,7 @@ Status _performNoopWrite(OperationContext* opCtx, BSONObj msgObj, StringData not opCtx, MODE_IX, Date_t::now() + Milliseconds(1), Lock::InterruptBehavior::kLeaveUnlocked); if (!lock.isLocked()) { - LOG(1) << "Global lock is not available skipping noopWrite"; + LOGV2_DEBUG(20495, 1, "Global lock is not available skipping noopWrite"); return {ErrorCodes::LockFailed, "Global lock is not available"}; } diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index a189e6f3426..e474b7f6353 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -44,6 +44,7 @@ #include "mongo/db/storage/storage_options.h" #include "mongo/logger/logger.h" #include "mongo/logger/parse_log_component_settings.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -358,8 +359,11 @@ public: try { uassertStatusOK(foundParameter->second->set(parameter)); } catch (const DBException& ex) { - log() << "error setting parameter " << parameterName << " to " - << redact(parameter.toString(false)) << " errMsg: " << redact(ex); + LOGV2(20496, + "error setting parameter {parameterName} to {parameter_false} errMsg: {ex}", + "parameterName"_attr = parameterName, + "parameter_false"_attr = redact(parameter.toString(false)), + "ex"_attr = redact(ex)); throw; } diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp index 31c2153a8da..f5c124d2451 100644 --- a/src/mongo/db/commands/resize_oplog.cpp +++ b/src/mongo/db/commands/resize_oplog.cpp @@ -41,6 +41,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" #include "mongo/db/storage/durable_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -107,7 +108,7 @@ public: uassertStatusOK(status); DurableCatalog::get(opCtx)->updateCappedSize(opCtx, coll->getCatalogId(), size); wunit.commit(); - LOG(0) << "replSetResizeOplog success, currentSize:" << size; + LOGV2(20497, "replSetResizeOplog success, currentSize:{size}", "size"_attr = size); return true; }); } diff --git a/src/mongo/db/commands/rwc_defaults_commands.cpp b/src/mongo/db/commands/rwc_defaults_commands.cpp index b4ada0db3ec..2352c1650d7 100644 --- a/src/mongo/db/commands/rwc_defaults_commands.cpp +++ b/src/mongo/db/commands/rwc_defaults_commands.cpp @@ -41,6 +41,7 @@ #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/rw_concern_default_gen.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/log.h" @@ -114,7 +115,9 @@ public: opCtx, request().getDefaultReadConcern(), request().getDefaultWriteConcern()); updatePersistedDefaultRWConcernDocument(opCtx, newDefaults); - log() << "successfully set RWC defaults to " << newDefaults.toBSON(); + LOGV2(20498, + "successfully set RWC defaults to {newDefaults}", + "newDefaults"_attr = newDefaults.toBSON()); // Refresh to populate the cache with the latest defaults. rwcDefaults.refreshIfNecessary(opCtx); diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp index 685332111b3..b7469ceb8fd 100644 --- a/src/mongo/db/commands/server_status.cpp +++ b/src/mongo/db/commands/server_status.cpp @@ -37,6 +37,7 @@ #include "mongo/db/commands/server_status_internal.h" #include "mongo/db/service_context.h" #include "mongo/db/stats/counters.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/net/http_client.h" #include "mongo/util/net/socket_utils.h" @@ -145,7 +146,7 @@ public: timeBuilder.appendNumber("at end", durationCount<Milliseconds>(runElapsed)); if (runElapsed > Milliseconds(1000)) { BSONObj t = timeBuilder.obj(); - log() << "serverStatus was very slow: " << t; + LOGV2(20499, "serverStatus was very slow: {t}", "t"_attr = t); bool include_timing = true; const auto& elem = cmdObj[kTimingSection]; diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index 9ca817e1d66..6dc12d4af3f 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -54,6 +54,7 @@ #include "mongo/db/s/migration_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/type_collection.h" #include "mongo/s/database_version_helpers.h" @@ -213,7 +214,7 @@ public: if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { const auto shardingState = ShardingState::get(opCtx); if (shardingState->enabled()) { - LOG(0) << "Upgrade: submitting orphaned ranges for cleanup"; + LOGV2(20500, "Upgrade: submitting orphaned ranges for cleanup"); migrationutil::submitOrphanRangesForCleanup(opCtx); } @@ -236,7 +237,7 @@ public: << requestedVersion))))); if (MONGO_unlikely(pauseBeforeUpgradingConfigMetadata.shouldFail())) { - log() << "Hit pauseBeforeUpgradingConfigMetadata"; + LOGV2(20501, "Hit pauseBeforeUpgradingConfigMetadata"); pauseBeforeUpgradingConfigMetadata.pauseWhileSet(opCtx); } ShardingCatalogManager::get(opCtx)->upgradeOrDowngradeChunksAndTags( @@ -308,7 +309,7 @@ public: repl::ReplicationCoordinator::modeReplSet; if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { - LOG(0) << "Downgrade: dropping config.rangeDeletions collection"; + LOGV2(20502, "Downgrade: dropping config.rangeDeletions collection"); migrationutil::dropRangeDeletionsCollection(opCtx); // The primary shard sharding a collection will write the initial chunks for a @@ -334,7 +335,7 @@ public: << requestedVersion))))); if (MONGO_unlikely(pauseBeforeDowngradingConfigMetadata.shouldFail())) { - log() << "Hit pauseBeforeDowngradingConfigMetadata"; + LOGV2(20503, "Hit pauseBeforeDowngradingConfigMetadata"); pauseBeforeDowngradingConfigMetadata.pauseWhileSet(opCtx); } ShardingCatalogManager::get(opCtx)->upgradeOrDowngradeChunksAndTags( diff --git a/src/mongo/db/commands/sleep_command.cpp b/src/mongo/db/commands/sleep_command.cpp index 21407950cd8..c7c74a1c01f 100644 --- a/src/mongo/db/commands/sleep_command.cpp +++ b/src/mongo/db/commands/sleep_command.cpp @@ -35,6 +35,7 @@ #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/lock_manager_defs.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -118,7 +119,7 @@ public: const std::string& ns, const BSONObj& cmdObj, BSONObjBuilder& result) { - log() << "test only command sleep invoked"; + LOGV2(20504, "test only command sleep invoked"); long long msToSleep = 0; if (cmdObj["secs"] || cmdObj["seconds"] || cmdObj["millis"]) { diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 81b7332b31a..bf5f1101fcc 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -45,6 +45,7 @@ #include "mongo/db/op_observer.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -80,7 +81,9 @@ public: string& errmsg, BSONObjBuilder& result) { const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj)); - log() << "test only command godinsert invoked coll:" << nss.coll(); + LOGV2(20505, + "test only command godinsert invoked coll:{nss_coll}", + "nss_coll"_attr = nss.coll()); BSONObj obj = cmdObj["obj"].embeddedObjectUserCheck(); Lock::DBLock lk(opCtx, dbname, MODE_X); diff --git a/src/mongo/db/commands/traffic_recording_cmds.cpp b/src/mongo/db/commands/traffic_recording_cmds.cpp index 7fd2894c9f6..9cb02bcf45a 100644 --- a/src/mongo/db/commands/traffic_recording_cmds.cpp +++ b/src/mongo/db/commands/traffic_recording_cmds.cpp @@ -38,6 +38,7 @@ #include "mongo/db/commands.h" #include "mongo/db/traffic_recorder.h" #include "mongo/db/traffic_recorder_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -53,9 +54,10 @@ public: void typedRun(OperationContext* opCtx) { TrafficRecorder::get(opCtx->getServiceContext()).start(request()); - log() << "** Warning: The recording file contains unencrypted user traffic." - << " We recommend that you limit retention of this file and " - << "store it on an encrypted filesystem volume."; + LOGV2(20506, + "** Warning: The recording file contains unencrypted user traffic. We recommend " + "that you limit retention of this file and store it on an encrypted filesystem " + "volume."); } private: diff --git a/src/mongo/db/commands/txn_cmds.cpp b/src/mongo/db/commands/txn_cmds.cpp index 9f9e7afa02e..91dfc7fa8dd 100644 --- a/src/mongo/db/commands/txn_cmds.cpp +++ b/src/mongo/db/commands/txn_cmds.cpp @@ -44,6 +44,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/transaction_participant.h" #include "mongo/db/transaction_validation.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -95,8 +96,12 @@ public: "commitTransaction must be run within a transaction", txnParticipant); - LOG(3) << "Received commitTransaction for transaction with txnNumber " - << opCtx->getTxnNumber() << " on session " << opCtx->getLogicalSessionId()->toBSON(); + LOGV2_DEBUG(20507, + 3, + "Received commitTransaction for transaction with txnNumber " + "{opCtx_getTxnNumber} on session {opCtx_getLogicalSessionId}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON()); // commitTransaction is retryable. if (txnParticipant.transactionIsCommitted()) { @@ -199,8 +204,12 @@ public: "abortTransaction must be run within a transaction", txnParticipant); - LOG(3) << "Received abortTransaction for transaction with txnNumber " - << opCtx->getTxnNumber() << " on session " << opCtx->getLogicalSessionId()->toBSON(); + LOGV2_DEBUG(20508, + 3, + "Received abortTransaction for transaction with txnNumber {opCtx_getTxnNumber} " + "on session {opCtx_getLogicalSessionId}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON()); uassert(ErrorCodes::NoSuchTransaction, "Transaction isn't in progress", diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 90bec146f42..2ccf5d6d97f 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -67,6 +67,7 @@ #include "mongo/db/ops/write_ops.h" #include "mongo/db/query/cursor_response.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/write_ops/batched_command_response.h" @@ -579,7 +580,7 @@ public: } if (_authzManager->getCacheGeneration() == _cacheGeneration) { - LOG(1) << "User management command did not invalidate the user cache."; + LOGV2_DEBUG(20509, 1, "User management command did not invalidate the user cache."); _authzManager->invalidateUserCache(_opCtx); } } @@ -2494,16 +2495,22 @@ public: Status status = updatePrivilegeDocument(opCtx, userName, userObj); if (!status.isOK()) { // Match the behavior of mongorestore to continue on failure - warning() << "Could not update user " << userName - << " in _mergeAuthzCollections command: " << redact(status); + LOGV2_WARNING( + 20510, + "Could not update user {userName} in _mergeAuthzCollections command: {status}", + "userName"_attr = userName, + "status"_attr = redact(status)); } } else { auditCreateOrUpdateUser(userObj, true); Status status = insertPrivilegeDocument(opCtx, userObj); if (!status.isOK()) { // Match the behavior of mongorestore to continue on failure - warning() << "Could not insert user " << userName - << " in _mergeAuthzCollections command: " << redact(status); + LOGV2_WARNING( + 20511, + "Could not insert user {userName} in _mergeAuthzCollections command: {status}", + "userName"_attr = userName, + "status"_attr = redact(status)); } } usersToDrop->erase(userName); @@ -2532,16 +2539,22 @@ public: Status status = updateRoleDocument(opCtx, roleName, roleObj); if (!status.isOK()) { // Match the behavior of mongorestore to continue on failure - warning() << "Could not update role " << roleName - << " in _mergeAuthzCollections command: " << redact(status); + LOGV2_WARNING( + 20512, + "Could not update role {roleName} in _mergeAuthzCollections command: {status}", + "roleName"_attr = roleName, + "status"_attr = redact(status)); } } else { auditCreateOrUpdateRole(roleObj, true); Status status = insertRoleDocument(opCtx, roleObj); if (!status.isOK()) { // Match the behavior of mongorestore to continue on failure - warning() << "Could not insert role " << roleName - << " in _mergeAuthzCollections command: " << redact(status); + LOGV2_WARNING( + 20513, + "Could not insert role {roleName} in _mergeAuthzCollections command: {status}", + "roleName"_attr = roleName, + "status"_attr = redact(status)); } } rolesToDrop->erase(roleName); diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index 3cdf9353749..f6b32d28eab 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -38,6 +38,7 @@ #include "mongo/db/query/internal_plans.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/record_store.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -142,8 +143,11 @@ public: } if (!serverGlobalParams.quiet.load()) { - LOG(0) << "CMD: validate " << nss.ns() << (background ? ", background:true" : "") - << (fullValidate ? ", full:true" : ""); + LOGV2(20514, + "CMD: validate {nss_ns}{background_background_true}{fullValidate_full_true}", + "nss_ns"_attr = nss.ns(), + "background_background_true"_attr = (background ? ", background:true" : ""), + "fullValidate_full_true"_attr = (fullValidate ? ", full:true" : "")); } // Only one validation per collection can be in progress, the rest wait. diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp index bf2b8bd62ff..8d00a0f1f44 100644 --- a/src/mongo/db/concurrency/d_concurrency_test.cpp +++ b/src/mongo/db/concurrency/d_concurrency_test.cpp @@ -43,6 +43,7 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/service_context_d_test_fixture.h" #include "mongo/db/storage/recovery_unit_noop.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/future.h" #include "mongo/stdx/thread.h" #include "mongo/unittest/unittest.h" @@ -2074,9 +2075,13 @@ TEST_F(DConcurrencyTestFixture, CompatibleFirstStress) { for (auto& thread : threads) thread.join(); for (int threadId = 0; threadId < numThreads; threadId++) { - log() << "thread " << threadId << " stats: " << acquisitionCount[threadId] - << " acquisitions, " << timeoutCount[threadId] << " timeouts, " - << busyWaitCount[threadId] / 1'000'000 << "M busy waits"; + LOGV2(20515, + "thread {threadId} stats: {acquisitionCount_threadId} acquisitions, " + "{timeoutCount_threadId} timeouts, {busyWaitCount_threadId_1_000_000}M busy waits", + "threadId"_attr = threadId, + "acquisitionCount_threadId"_attr = acquisitionCount[threadId], + "timeoutCount_threadId"_attr = timeoutCount[threadId], + "busyWaitCount_threadId_1_000_000"_attr = busyWaitCount[threadId] / 1'000'000); } } diff --git a/src/mongo/db/concurrency/deferred_writer.cpp b/src/mongo/db/concurrency/deferred_writer.cpp index 4bedbe1995c..b06d4faa127 100644 --- a/src/mongo/db/concurrency/deferred_writer.cpp +++ b/src/mongo/db/concurrency/deferred_writer.cpp @@ -35,6 +35,7 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/db_raii.h" #include "mongo/db/operation_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/concurrency/thread_pool.h" #include "mongo/util/log.h" @@ -47,7 +48,10 @@ auto kLogInterval = stdx::chrono::minutes(1); void DeferredWriter::_logFailure(const Status& status) { if (TimePoint::clock::now() - _lastLogged > kLogInterval) { - log() << "Unable to write to collection " << _nss.toString() << ": " << status.toString(); + LOGV2(20516, + "Unable to write to collection {nss}: {status}", + "nss"_attr = _nss.toString(), + "status"_attr = status.toString()); _lastLogged = stdx::chrono::system_clock::now(); } } @@ -55,8 +59,11 @@ void DeferredWriter::_logFailure(const Status& status) { void DeferredWriter::_logDroppedEntry() { _droppedEntries += 1; if (TimePoint::clock::now() - _lastLoggedDrop > kLogInterval) { - log() << "Deferred write buffer for " << _nss.toString() << " is full. " << _droppedEntries - << " entries have been dropped."; + LOGV2( + 20517, + "Deferred write buffer for {nss} is full. {droppedEntries} entries have been dropped.", + "nss"_attr = _nss.toString(), + "droppedEntries"_attr = _droppedEntries); _lastLoggedDrop = stdx::chrono::system_clock::now(); _droppedEntries = 0; } diff --git a/src/mongo/db/concurrency/flow_control_ticketholder.cpp b/src/mongo/db/concurrency/flow_control_ticketholder.cpp index 4a8057159e1..a11c4b399c4 100644 --- a/src/mongo/db/concurrency/flow_control_ticketholder.cpp +++ b/src/mongo/db/concurrency/flow_control_ticketholder.cpp @@ -34,6 +34,7 @@ #include "mongo/db/concurrency/flow_control_ticketholder.h" #include "mongo/db/operation_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/time_support.h" @@ -81,7 +82,11 @@ void FlowControlTicketholder::set(ServiceContext* service, void FlowControlTicketholder::refreshTo(int numTickets) { invariant(numTickets >= 0); stdx::lock_guard<Latch> lk(_mutex); - LOG(4) << "Refreshing tickets. Before: " << _tickets << " Now: " << numTickets; + LOGV2_DEBUG(20518, + 4, + "Refreshing tickets. Before: {tickets} Now: {numTickets}", + "tickets"_attr = _tickets, + "numTickets"_attr = numTickets); _tickets = numTickets; _cv.notify_all(); } @@ -93,7 +98,7 @@ void FlowControlTicketholder::getTicket(OperationContext* opCtx, return; } - LOG(4) << "Taking ticket. Available: " << _tickets; + LOGV2_DEBUG(20519, 4, "Taking ticket. Available: {tickets}", "tickets"_attr = _tickets); if (_tickets == 0) { ++stats->acquireWaitCount; } @@ -130,7 +135,7 @@ void FlowControlTicketholder::getTicket(OperationContext* opCtx, // Should only be called once, during shutdown. void FlowControlTicketholder::setInShutdown() { - LOG(0) << "Stopping further Flow Control ticket acquisitions."; + LOGV2(20520, "Stopping further Flow Control ticket acquisitions."); stdx::lock_guard<Latch> lk(_mutex); _inShutdown = true; _cv.notify_all(); diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp index 0ab21e4c425..b27c632c7ee 100644 --- a/src/mongo/db/concurrency/lock_manager.cpp +++ b/src/mongo/db/concurrency/lock_manager.cpp @@ -41,6 +41,7 @@ #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/locker.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -826,7 +827,9 @@ LockManager::Partition* LockManager::_getPartition(LockRequest* request) const { } void LockManager::dump() const { - log() << "Dumping LockManager @ " << reinterpret_cast<uint64_t>(this) << '\n'; + LOGV2(20521, + "Dumping LockManager @ {reinterpret_cast_uint64_t_this}", + "reinterpret_cast_uint64_t_this"_attr = reinterpret_cast<uint64_t>(this)); auto lockToClientMap = getLockToClientMap(getGlobalServiceContext()); for (unsigned i = 0; i < _numLockBuckets; i++) { @@ -963,7 +966,7 @@ void LockManager::_dumpBucket(const std::map<LockerId, BSONObj>& lockToClientMap } sb << "-----------------------------------------------------------\n"; - log() << sb.str(); + LOGV2(20522, "{sb_str}", "sb_str"_attr = sb.str()); } } diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp index 3f98a7322b3..2b2f104dacc 100644 --- a/src/mongo/db/concurrency/lock_state.cpp +++ b/src/mongo/db/concurrency/lock_state.cpp @@ -39,6 +39,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/flow_control.h" +#include "mongo/logv2/log.h" #include "mongo/platform/compiler.h" #include "mongo/stdx/new.h" #include "mongo/util/background.h" @@ -203,7 +204,7 @@ void LockerImpl::dump() const { } _lock.unlock(); - log() << ss.str(); + LOGV2(20523, "{ss_str}", "ss_str"_attr = ss.str()); } @@ -1062,7 +1063,7 @@ public: } void taskDoWork() { - LOG(2) << "cleaning up unused lock buckets of the global lock manager"; + LOGV2_DEBUG(20524, 2, "cleaning up unused lock buckets of the global lock manager"); getGlobalLockManager()->cleanupUnusedLocks(); } } unusedLockCleaner; diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index 76e64830695..96ded269c07 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -48,6 +48,7 @@ #include "mongo/db/prepare_conflict_tracker.h" #include "mongo/db/query/getmore_request.h" #include "mongo/db/query/plan_summary_stats.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/client_metadata.h" #include "mongo/rpc/metadata/client_metadata_ismaster.h" #include "mongo/rpc/metadata/impersonated_user_metadata.h" @@ -380,7 +381,10 @@ void CurOp::setGenericOpRequestDetails(OperationContext* opCtx, void CurOp::setMessage_inlock(StringData message) { if (_progressMeter.isActive()) { - error() << "old _message: " << redact(_message) << " new message:" << redact(message); + LOGV2_ERROR(20527, + "old _message: {message} new message:{message2}", + "message"_attr = redact(_message), + "message2"_attr = redact(message)); verify(!_progressMeter.isActive()); } _message = message.toString(); // copy @@ -467,12 +471,16 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx, if (lk.isLocked()) { _debug.storageStats = opCtx->recoveryUnit()->getOperationStatistics(); } else { - warning(component) << "Unable to gather storage statistics for a slow " - "operation due to lock aquire timeout"; + LOGV2_WARNING_OPTIONS(20525, + {logComponentV1toV2(component)}, + "Unable to gather storage statistics for a slow " + "operation due to lock aquire timeout"); } } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - warning(component) << "Unable to gather storage statistics for a slow " - "operation due to interrupt"; + LOGV2_WARNING_OPTIONS(20526, + {logComponentV1toV2(component)}, + "Unable to gather storage statistics for a slow " + "operation due to interrupt"); } } diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp index 93dd9cad7f7..6092fcbffbc 100644 --- a/src/mongo/db/cursor_manager.cpp +++ b/src/mongo/db/cursor_manager.cpp @@ -52,6 +52,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/query/plan_executor.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/platform/random.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" @@ -90,7 +91,7 @@ std::pair<Status, int> CursorManager::killCursorsWithMatchingSessions( OperationContext* opCtx, const SessionKiller::Matcher& matcher) { auto eraser = [&](CursorManager& mgr, CursorId id) { uassertStatusOK(mgr.killCursor(opCtx, id, true)); - log() << "killing cursor: " << id << " as part of killing session(s)"; + LOGV2(20528, "killing cursor: {id} as part of killing session(s)", "id"_attr = id); }; auto bySessionCursorKiller = makeKillCursorsBySessionAdaptor(opCtx, matcher, std::move(eraser)); @@ -141,8 +142,10 @@ std::size_t CursorManager::timeoutCursors(OperationContext* opCtx, Date_t now) { // Be careful not to dispose of cursors while holding the partition lock. for (auto&& cursor : toDisposeWithoutMutex) { - log() << "Cursor id " << cursor->cursorid() << " timed out, idle since " - << cursor->getLastUseDate(); + LOGV2(20529, + "Cursor id {cursor_cursorid} timed out, idle since {cursor_getLastUseDate}", + "cursor_cursorid"_attr = cursor->cursorid(), + "cursor_getLastUseDate"_attr = cursor->getLastUseDate()); cursor->dispose(opCtx); } return toDisposeWithoutMutex.size(); @@ -212,8 +215,10 @@ void CursorManager::unpin(OperationContext* opCtx, // proactively delete the cursor. In other cases we preserve the error code so that the client // will see the reason the cursor was killed when asking for the next batch. if (interruptStatus == ErrorCodes::Interrupted || interruptStatus == ErrorCodes::CursorKilled) { - LOG(0) << "removing cursor " << cursor->cursorid() - << " after completing batch: " << interruptStatus; + LOGV2(20530, + "removing cursor {cursor_cursorid} after completing batch: {interruptStatus}", + "cursor_cursorid"_attr = cursor->cursorid(), + "interruptStatus"_attr = interruptStatus); return deregisterAndDestroyCursor(std::move(partition), opCtx, std::move(cursor)); } else if (!interruptStatus.isOK()) { cursor->markAsKilled(interruptStatus); diff --git a/src/mongo/db/database_index_builds_tracker.cpp b/src/mongo/db/database_index_builds_tracker.cpp index 4f7bb13a472..c8d21639050 100644 --- a/src/mongo/db/database_index_builds_tracker.cpp +++ b/src/mongo/db/database_index_builds_tracker.cpp @@ -34,6 +34,7 @@ #include "mongo/db/database_index_builds_tracker.h" #include "mongo/db/catalog/index_builds_manager.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -80,9 +81,11 @@ void DatabaseIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_lock< return true; } - log() << "Waiting until the following index builds are finished:"; + LOGV2(20531, "Waiting until the following index builds are finished:"); for (const auto& indexBuild : _allIndexBuilds) { - log() << " Index build with UUID: " << indexBuild.first; + LOGV2(20532, + " Index build with UUID: {indexBuild_first}", + "indexBuild_first"_attr = indexBuild.first); } return false; diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index b5a2fd26c42..59da6fe85a1 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -152,6 +152,7 @@ #include "mongo/executor/network_interface_factory.h" #include "mongo/executor/network_interface_thread_pool.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/platform/process_id.h" #include "mongo/platform/random.h" #include "mongo/rpc/metadata/egress_metadata_hook_list.h" @@ -300,7 +301,8 @@ ExitCode _initAndListen(int listenPort) { } if (kDebugBuild) - log(LogComponent::kControl) << "DEBUG build (which is slower)" << endl; + LOGV2_OPTIONS( + 20533, {logComponentV1toV2(LogComponent::kControl)}, "DEBUG build (which is slower)"); #if defined(_WIN32) VersionInfoInterface::instance().logTargetMinOS(); @@ -317,7 +319,7 @@ ExitCode _initAndListen(int listenPort) { transport::TransportLayerManager::createWithConfig(&serverGlobalParams, serviceContext); auto res = tl->setup(); if (!res.isOK()) { - error() << "Failed to set up listener: " << res; + LOGV2_ERROR(20568, "Failed to set up listener: {res}", "res"_attr = res); return EXIT_NET_ERROR; } serviceContext->setTransportLayer(std::move(tl)); @@ -352,9 +354,11 @@ ExitCode _initAndListen(int listenPort) { // Warn if field name matches non-active registered storage engine. if (isRegisteredStorageEngine(serviceContext, e.fieldName())) { - warning() << "Detected configuration for non-active storage engine " - << e.fieldName() << " when current storage engine is " - << storageGlobalParams.engine; + LOGV2_WARNING(20566, + "Detected configuration for non-active storage engine {e_fieldName} " + "when current storage engine is {storageGlobalParams_engine}", + "e_fieldName"_attr = e.fieldName(), + "storageGlobalParams_engine"_attr = storageGlobalParams.engine); } } } @@ -362,17 +366,20 @@ ExitCode _initAndListen(int listenPort) { // Disallow running a storage engine that doesn't support capped collections with --profile if (!serviceContext->getStorageEngine()->supportsCappedCollections() && serverGlobalParams.defaultProfile != 0) { - log() << "Running " << storageGlobalParams.engine << " with profiling is not supported. " - << "Make sure you are not using --profile."; + LOGV2(20534, + "Running {storageGlobalParams_engine} with profiling is not supported. Make sure you " + "are not using --profile.", + "storageGlobalParams_engine"_attr = storageGlobalParams.engine); exitCleanly(EXIT_BADOPTIONS); } // Disallow running WiredTiger with --nojournal in a replica set if (storageGlobalParams.engine == "wiredTiger" && !storageGlobalParams.dur && replSettings.usingReplSets()) { - log() << "Running wiredTiger without journaling in a replica set is not " - << "supported. Make sure you are not using --nojournal and that " - << "storage.journal.enabled is not set to 'false'."; + LOGV2(20535, + "Running wiredTiger without journaling in a replica set is not supported. Make sure " + "you are not using --nojournal and that storage.journal.enabled is not set to " + "'false'."); exitCleanly(EXIT_BADOPTIONS); } @@ -415,7 +422,10 @@ ExitCode _initAndListen(int listenPort) { try { nonLocalDatabases = repairDatabasesAndCheckVersion(startupOpCtx.get()); } catch (const ExceptionFor<ErrorCodes::MustDowngrade>& error) { - severe(LogComponent::kControl) << "** IMPORTANT: " << error.toStatus().reason(); + LOGV2_FATAL_OPTIONS(20573, + {logComponentV1toV2(LogComponent::kControl)}, + "** IMPORTANT: {error_toStatus_reason}", + "error_toStatus_reason"_attr = error.toStatus().reason()); exitCleanly(EXIT_NEED_DOWNGRADE); } @@ -437,11 +447,11 @@ ExitCode _initAndListen(int listenPort) { } if (gFlowControlEnabled.load()) { - log() << "Flow Control is enabled on this deployment."; + LOGV2(20536, "Flow Control is enabled on this deployment."); } if (storageGlobalParams.upgrade) { - log() << "finished checking dbs"; + LOGV2(20537, "finished checking dbs"); exitCleanly(EXIT_CLEAN); } @@ -457,7 +467,7 @@ ExitCode _initAndListen(int listenPort) { if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) { Status status = verifySystemIndexes(startupOpCtx.get()); if (!status.isOK()) { - log() << redact(status); + LOGV2(20538, "{status}", "status"_attr = redact(status)); if (status == ErrorCodes::AuthSchemaIncompatible) { exitCleanly(EXIT_NEED_UPGRADE); } else if (status == ErrorCodes::NotMaster) { @@ -473,37 +483,44 @@ ExitCode _initAndListen(int listenPort) { status = globalAuthzManager->getAuthorizationVersion(startupOpCtx.get(), &foundSchemaVersion); if (!status.isOK()) { - log() << "Auth schema version is incompatible: " - << "User and role management commands require auth data to have " - << "at least schema version " << AuthorizationManager::schemaVersion26Final - << " but startup could not verify schema version: " << status; - log() << "To manually repair the 'authSchema' document in the admin.system.version " - "collection, start up with --setParameter " - "startupAuthSchemaValidation=false to disable validation."; + LOGV2(20539, + "Auth schema version is incompatible: User and role management commands require " + "auth data to have at least schema version " + "{AuthorizationManager_schemaVersion26Final} but startup could not verify schema " + "version: {status}", + "AuthorizationManager_schemaVersion26Final"_attr = + AuthorizationManager::schemaVersion26Final, + "status"_attr = status); + LOGV2(20540, + "To manually repair the 'authSchema' document in the admin.system.version " + "collection, start up with --setParameter " + "startupAuthSchemaValidation=false to disable validation."); exitCleanly(EXIT_NEED_UPGRADE); } if (foundSchemaVersion <= AuthorizationManager::schemaVersion26Final) { - log() << "This server is using MONGODB-CR, an authentication mechanism which " - << "has been removed from MongoDB 4.0. In order to upgrade the auth schema, " - << "first downgrade MongoDB binaries to version 3.6 and then run the " - << "authSchemaUpgrade command. " - << "See http://dochub.mongodb.org/core/3.0-upgrade-to-scram-sha-1"; + LOGV2(20541, + "This server is using MONGODB-CR, an authentication mechanism which has been " + "removed from MongoDB 4.0. In order to upgrade the auth schema, first downgrade " + "MongoDB binaries to version 3.6 and then run the authSchemaUpgrade command. See " + "http://dochub.mongodb.org/core/3.0-upgrade-to-scram-sha-1"); exitCleanly(EXIT_NEED_UPGRADE); } } else if (globalAuthzManager->isAuthEnabled()) { - error() << "Auth must be disabled when starting without auth schema validation"; + LOGV2_ERROR(20569, "Auth must be disabled when starting without auth schema validation"); exitCleanly(EXIT_BADOPTIONS); } else { // If authSchemaValidation is disabled and server is running without auth, // warn the user and continue startup without authSchema metadata checks. - log() << startupWarningsLog; - log() << "** WARNING: Startup auth schema validation checks are disabled for the " - "database." - << startupWarningsLog; - log() << "** This mode should only be used to manually repair corrupted auth " - "data." - << startupWarningsLog; + LOGV2_OPTIONS(20542, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(20543, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Startup auth schema validation checks are disabled for the " + "database."); + LOGV2_OPTIONS(20544, + {logv2::LogTag::kStartupWarnings}, + "** This mode should only be used to manually repair corrupted auth " + "data."); } WaitForMajorityService::get(serviceContext).setUp(serviceContext); @@ -514,8 +531,9 @@ ExitCode _initAndListen(int listenPort) { if (shardingInitialized) { auto status = waitForShardRegistryReload(startupOpCtx.get()); if (!status.isOK()) { - LOG(0) << "Failed to load the shard registry as part of startup" - << causedBy(redact(status)); + LOGV2(20545, + "Failed to load the shard registry as part of startup{causedBy_status}", + "causedBy_status"_attr = causedBy(redact(status))); } } @@ -526,8 +544,10 @@ ExitCode _initAndListen(int listenPort) { .refreshIfNecessary(startupOpCtx.get()); } } catch (const DBException& ex) { - warning() << "Failed to load read and write concern defaults at startup" - << causedBy(redact(ex.toStatus())); + LOGV2_WARNING( + 20567, + "Failed to load read and write concern defaults at startup{causedBy_ex_toStatus}", + "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus()))); } auto storageEngine = serviceContext->getStorageEngine(); @@ -604,23 +624,34 @@ ExitCode _initAndListen(int listenPort) { replCoord->startup(startupOpCtx.get()); if (getReplSetMemberInStandaloneMode(serviceContext)) { - log() << startupWarningsLog; - log() << "** WARNING: mongod started without --replSet yet document(s) are present in " - << NamespaceString::kSystemReplSetNamespace << "." << startupWarningsLog; - log() << "** Database contents may appear inconsistent with the oplog and may " - "appear to not contain" - << startupWarningsLog; - log() << "** writes that were visible when this node was running as part of a " - "replica set." - << startupWarningsLog; - log() << "** Restart with --replSet unless you are doing maintenance and no " - "other clients are connected." - << startupWarningsLog; - log() << "** The TTL collection monitor will not start because of this." - << startupWarningsLog; - log() << "** "; - log() << " For more info see http://dochub.mongodb.org/core/ttlcollections"; - log() << startupWarningsLog; + LOGV2_OPTIONS(20546, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(20547, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: mongod started without --replSet yet document(s) are " + "present in {NamespaceString_kSystemReplSetNamespace}.", + "NamespaceString_kSystemReplSetNamespace"_attr = + NamespaceString::kSystemReplSetNamespace); + LOGV2_OPTIONS( + 20548, + {logv2::LogTag::kStartupWarnings}, + "** Database contents may appear inconsistent with the oplog and may " + "appear to not contain"); + LOGV2_OPTIONS( + 20549, + {logv2::LogTag::kStartupWarnings}, + "** writes that were visible when this node was running as part of a " + "replica set."); + LOGV2_OPTIONS( + 20550, + {logv2::LogTag::kStartupWarnings}, + "** Restart with --replSet unless you are doing maintenance and no " + "other clients are connected."); + LOGV2_OPTIONS(20551, + {logv2::LogTag::kStartupWarnings}, + "** The TTL collection monitor will not start because of this."); + LOGV2(20552, "** "); + LOGV2(20553, " For more info see http://dochub.mongodb.org/core/ttlcollections"); + LOGV2_OPTIONS(20554, {logv2::LogTag::kStartupWarnings}, ""); } else { startTTLBackgroundJob(serviceContext); } @@ -670,20 +701,22 @@ ExitCode _initAndListen(int listenPort) { auto start = serviceContext->getServiceExecutor()->start(); if (!start.isOK()) { - error() << "Failed to start the service executor: " << start; + LOGV2_ERROR(20570, "Failed to start the service executor: {start}", "start"_attr = start); return EXIT_NET_ERROR; } start = serviceContext->getServiceEntryPoint()->start(); if (!start.isOK()) { - error() << "Failed to start the service entry point: " << start; + LOGV2_ERROR( + 20571, "Failed to start the service entry point: {start}", "start"_attr = start); return EXIT_NET_ERROR; } if (!storageGlobalParams.repair) { start = serviceContext->getTransportLayer()->start(); if (!start.isOK()) { - error() << "Failed to start the listener: " << start.toString(); + LOGV2_ERROR( + 20572, "Failed to start the listener: {start}", "start"_attr = start.toString()); return EXIT_NET_ERROR; } } @@ -695,12 +728,12 @@ ExitCode _initAndListen(int listenPort) { #else if (ntservice::shouldStartService()) { ntservice::reportStatus(SERVICE_RUNNING); - log() << "Service running"; + LOGV2(20555, "Service running"); } #endif if (MONGO_unlikely(shutdownAtStartup.shouldFail())) { - log() << "starting clean exit via failpoint"; + LOGV2(20556, "starting clean exit via failpoint"); exitCleanly(EXIT_CLEAN); } @@ -712,16 +745,18 @@ ExitCode initAndListen(int listenPort) { try { return _initAndListen(listenPort); } catch (DBException& e) { - log() << "exception in initAndListen: " << e.toString() << ", terminating"; + LOGV2(20557, "exception in initAndListen: {e}, terminating", "e"_attr = e.toString()); return EXIT_UNCAUGHT; } catch (std::exception& e) { - log() << "exception in initAndListen std::exception: " << e.what() << ", terminating"; + LOGV2(20558, + "exception in initAndListen std::exception: {e_what}, terminating", + "e_what"_attr = e.what()); return EXIT_UNCAUGHT; } catch (int& n) { - log() << "exception in initAndListen int: " << n << ", terminating"; + LOGV2(20559, "exception in initAndListen int: {n}, terminating", "n"_attr = n); return EXIT_UNCAUGHT; } catch (...) { - log() << "exception in initAndListen, terminating"; + LOGV2(20560, "exception in initAndListen, terminating"); return EXIT_UNCAUGHT; } } @@ -966,8 +1001,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { } catch (const ExceptionFor<ErrorCodes::NotMaster>&) { // ignore not master errors } catch (const DBException& e) { - log() << "Failed to stepDown in non-command initiated shutdown path " - << e.toString(); + LOGV2(20561, + "Failed to stepDown in non-command initiated shutdown path {e}", + "e"_attr = e.toString()); } } } @@ -992,7 +1028,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { // Shutdown the TransportLayer so that new connections aren't accepted if (auto tl = serviceContext->getTransportLayer()) { - log(LogComponent::kNetwork) << "shutdown: going to close listening sockets..."; + LOGV2_OPTIONS(20562, + {logComponentV1toV2(LogComponent::kNetwork)}, + "shutdown: going to close listening sockets..."); tl->shutdown(); } @@ -1087,8 +1125,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { // Shutdown the Service Entry Point and its sessions and give it a grace period to complete. if (auto sep = serviceContext->getServiceEntryPoint()) { if (!sep->shutdown(Seconds(10))) { - log(LogComponent::kNetwork) - << "Service entry point failed to shutdown within timelimit."; + LOGV2_OPTIONS(20563, + {logComponentV1toV2(LogComponent::kNetwork)}, + "Service entry point failed to shutdown within timelimit."); } } @@ -1096,8 +1135,10 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { if (auto svcExec = serviceContext->getServiceExecutor()) { Status status = svcExec->shutdown(Seconds(10)); if (!status.isOK()) { - log(LogComponent::kNetwork) - << "Service executor failed to shutdown within timelimit: " << status.reason(); + LOGV2_OPTIONS(20564, + {logComponentV1toV2(LogComponent::kNetwork)}, + "Service executor failed to shutdown within timelimit: {status_reason}", + "status_reason"_attr = status.reason()); } } #endif @@ -1126,7 +1167,7 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { // the memory and makes leak sanitizer happy. ScriptEngine::dropScopeCache(); - log(LogComponent::kControl) << "now exiting"; + LOGV2_OPTIONS(20565, {logComponentV1toV2(LogComponent::kControl)}, "now exiting"); audit::logShutdown(client); @@ -1142,7 +1183,10 @@ int mongoDbMain(int argc, char* argv[], char** envp) { Status status = mongo::runGlobalInitializers(argc, argv, envp); if (!status.isOK()) { - severe(LogComponent::kControl) << "Failed global initialization: " << status; + LOGV2_FATAL_OPTIONS(20574, + {logComponentV1toV2(LogComponent::kControl)}, + "Failed global initialization: {status}", + "status"_attr = status); quickExit(EXIT_FAILURE); } @@ -1150,7 +1194,10 @@ int mongoDbMain(int argc, char* argv[], char** envp) { setGlobalServiceContext(ServiceContext::make()); } catch (...) { auto cause = exceptionToStatus(); - severe(LogComponent::kControl) << "Failed to create service context: " << redact(cause); + LOGV2_FATAL_OPTIONS(20575, + {logComponentV1toV2(LogComponent::kControl)}, + "Failed to create service context: {cause}", + "cause"_attr = redact(cause)); quickExit(EXIT_FAILURE); } diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 02df85a977b..07b4c52c2bf 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -39,6 +39,7 @@ #include "mongo/db/db_raii_gen.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/collection_sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -191,9 +192,13 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, // waiting for the lastAppliedTimestamp to move forward. Instead we force the reader take // the PBWM lock and retry. if (lastAppliedTimestamp) { - LOG(0) << "tried reading at last-applied time: " << *lastAppliedTimestamp - << " on ns: " << nss.ns() << ", but future catalog changes are pending at time " - << *minSnapshot << ". Trying again without reading at last-applied time."; + LOGV2(20576, + "tried reading at last-applied time: {lastAppliedTimestamp} on ns: {nss_ns}, but " + "future catalog changes are pending at time {minSnapshot}. Trying again without " + "reading at last-applied time.", + "lastAppliedTimestamp"_attr = *lastAppliedTimestamp, + "nss_ns"_attr = nss.ns(), + "minSnapshot"_attr = *minSnapshot); // Destructing the block sets _shouldConflictWithSecondaryBatchApplication back to the // previous value. If the previous value is false (because there is another // shouldNotConflictWithSecondaryBatchApplicationBlock outside of this function), this @@ -265,7 +270,7 @@ bool AutoGetCollectionForRead::_shouldReadAtLastAppliedTimestamp( // This may occur when multiple collection locks are held concurrently, which is often the case // when DBDirectClient is used. if (opCtx->lockState()->isLockHeldForMode(resourceIdParallelBatchWriterMode, MODE_IS)) { - LOG(1) << "not reading at last-applied because the PBWM lock is held"; + LOGV2_DEBUG(20577, 1, "not reading at last-applied because the PBWM lock is held"); return false; } diff --git a/src/mongo/db/db_raii_test.cpp b/src/mongo/db/db_raii_test.cpp index 73a072aa86a..9df8b19356f 100644 --- a/src/mongo/db/db_raii_test.cpp +++ b/src/mongo/db/db_raii_test.cpp @@ -37,6 +37,7 @@ #include "mongo/db/client.h" #include "mongo/db/concurrency/lock_state.h" #include "mongo/db/db_raii.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" #include "mongo/util/time_support.h" @@ -69,7 +70,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis func(); FAIL("Should have gotten an exception due to timeout"); } catch (const ExceptionFor<ErrorCodes::LockTimeout>& ex) { - log() << ex; + LOGV2(20578, "{ex}", "ex"_attr = ex); Date_t t2 = Date_t::now(); ASSERT_GTE(t2 - t1, timeoutMillis); } diff --git a/src/mongo/db/exec/cached_plan.cpp b/src/mongo/db/exec/cached_plan.cpp index 7f35e28a63d..1467eed69a6 100644 --- a/src/mongo/db/exec/cached_plan.cpp +++ b/src/mongo/db/exec/cached_plan.cpp @@ -48,6 +48,7 @@ #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/stage_builder.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" #include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" @@ -141,10 +142,15 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { // existing cache entry nor cache the result of replanning. BSONObj statusObj = WorkingSetCommon::getStatusMemberDocument(*_ws, id)->toBson(); - LOG(1) << "Execution of cached plan failed, falling back to replan." - << " query: " << redact(_canonicalQuery->toStringShort()) - << " planSummary: " << Explain::getPlanSummary(child().get()) - << " status: " << redact(statusObj); + LOGV2_DEBUG(20579, + 1, + "Execution of cached plan failed, falling back to replan. query: " + "{canonicalQuery_Short} planSummary: {Explain_getPlanSummary_child_get} " + "status: {statusObj}", + "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()), + "Explain_getPlanSummary_child_get"_attr = + Explain::getPlanSummary(child().get()), + "statusObj"_attr = redact(statusObj)); const bool shouldCache = false; return replan(yieldPolicy, @@ -158,11 +164,16 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { // If we're here, the trial period took more than 'maxWorksBeforeReplan' work cycles. This // plan is taking too long, so we replan from scratch. - LOG(1) << "Execution of cached plan required " << maxWorksBeforeReplan - << " works, but was originally cached with only " << _decisionWorks - << " works. Evicting cache entry and replanning query: " - << redact(_canonicalQuery->toStringShort()) - << " plan summary before replan: " << Explain::getPlanSummary(child().get()); + LOGV2_DEBUG( + 20580, + 1, + "Execution of cached plan required {maxWorksBeforeReplan} works, but was originally cached " + "with only {decisionWorks} works. Evicting cache entry and replanning query: " + "{canonicalQuery_Short} plan summary before replan: {Explain_getPlanSummary_child_get}", + "maxWorksBeforeReplan"_attr = maxWorksBeforeReplan, + "decisionWorks"_attr = _decisionWorks, + "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()), + "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get())); const bool shouldCache = true; return replan( @@ -222,11 +233,15 @@ Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, s _replannedQs = std::move(solutions.back()); solutions.pop_back(); - LOG(1) - << "Replanning of query resulted in single query solution, which will not be cached. " - << redact(_canonicalQuery->toStringShort()) - << " plan summary after replan: " << Explain::getPlanSummary(child().get()) - << " previous cache entry evicted: " << (shouldCache ? "yes" : "no"); + LOGV2_DEBUG( + 20581, + 1, + "Replanning of query resulted in single query solution, which will not be cached. " + "{canonicalQuery_Short} plan summary after replan: {Explain_getPlanSummary_child_get} " + "previous cache entry evicted: {shouldCache_yes_no}", + "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()), + "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get()), + "shouldCache_yes_no"_attr = (shouldCache ? "yes" : "no")); return Status::OK(); } @@ -255,9 +270,14 @@ Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, s return pickBestPlanStatus; } - LOG(1) << "Replanning " << redact(_canonicalQuery->toStringShort()) - << " resulted in plan with summary: " << Explain::getPlanSummary(child().get()) - << ", which " << (shouldCache ? "has" : "has not") << " been written to the cache"; + LOGV2_DEBUG(20582, + 1, + "Replanning {canonicalQuery_Short} resulted in plan with summary: " + "{Explain_getPlanSummary_child_get}, which {shouldCache_has_has_not} been written " + "to the cache", + "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()), + "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get()), + "shouldCache_has_has_not"_attr = (shouldCache ? "has" : "has not")); return Status::OK(); } @@ -302,12 +322,19 @@ void CachedPlanStage::updatePlanCache() { PlanCache* cache = CollectionQueryInfo::get(collection()).getPlanCache(); Status fbs = cache->feedback(*_canonicalQuery, score); if (!fbs.isOK()) { - LOG(5) << _canonicalQuery->ns() << ": Failed to update cache with feedback: " << redact(fbs) - << " - " - << "(query: " << redact(_canonicalQuery->getQueryObj()) - << "; sort: " << _canonicalQuery->getQueryRequest().getSort() - << "; projection: " << _canonicalQuery->getQueryRequest().getProj() - << ") is no longer in plan cache."; + LOGV2_DEBUG( + 20583, + 5, + "{canonicalQuery_ns}: Failed to update cache with feedback: {fbs} - (query: " + "{canonicalQuery_getQueryObj}; sort: {canonicalQuery_getQueryRequest_getSort}; " + "projection: {canonicalQuery_getQueryRequest_getProj}) is no longer in plan cache.", + "canonicalQuery_ns"_attr = _canonicalQuery->ns(), + "fbs"_attr = redact(fbs), + "canonicalQuery_getQueryObj"_attr = redact(_canonicalQuery->getQueryObj()), + "canonicalQuery_getQueryRequest_getSort"_attr = + _canonicalQuery->getQueryRequest().getSort(), + "canonicalQuery_getQueryRequest_getProj"_attr = + _canonicalQuery->getQueryRequest().getProj()); } } diff --git a/src/mongo/db/exec/collection_scan.cpp b/src/mongo/db/exec/collection_scan.cpp index 66711faadf6..987d3ea69f3 100644 --- a/src/mongo/db/exec/collection_scan.cpp +++ b/src/mongo/db/exec/collection_scan.cpp @@ -43,6 +43,7 @@ #include "mongo/db/exec/working_set_common.h" #include "mongo/db/repl/optime.h" #include "mongo/db/storage/oplog_hack.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -173,7 +174,7 @@ PlanStage::StageState CollectionScan::doWork(WorkingSetID* out) { boost::optional<RecordId> startLoc = collection()->getRecordStore()->oplogStartHack(getOpCtx(), goal.getValue()); if (startLoc && !startLoc->isNull()) { - LOG(3) << "Using direct oplog seek"; + LOGV2_DEBUG(20584, 3, "Using direct oplog seek"); record = _cursor->seekExact(*startLoc); } } diff --git a/src/mongo/db/exec/document_value/document_value_test.cpp b/src/mongo/db/exec/document_value/document_value_test.cpp index d641b699ae5..2b7797affe6 100644 --- a/src/mongo/db/exec/document_value/document_value_test.cpp +++ b/src/mongo/db/exec/document_value/document_value_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include <math.h> #include "mongo/platform/basic.h" @@ -41,6 +43,8 @@ #include "mongo/db/json.h" #include "mongo/db/pipeline/field_path.h" #include "mongo/dbtests/dbtests.h" +#include "mongo/logv2/log.h" +#include "mongo/util/log.h" namespace DocumentTests { @@ -236,7 +240,7 @@ public: // Remove the second field. md.setField("b", Value()); - log() << md.peek().toString(); + LOGV2(20585, "{md_peek}", "md_peek"_attr = md.peek().toString()); ASSERT_EQUALS(2U, md.peek().size()); ASSERT(md.peek()["b"].missing()); ASSERT_EQUALS("a", getNthField(md.peek(), 0).first.toString()); @@ -1915,7 +1919,7 @@ private: assertComparison(expectedResult, fromBson(a), fromBson(b)); } void assertComparison(int expectedResult, const Value& a, const Value& b) { - mongo::unittest::log() << "testing " << a.toString() << " and " << b.toString(); + LOGV2(20586, "testing {a} and {b}", "a"_attr = a.toString(), "b"_attr = b.toString()); // reflexivity ASSERT_EQUALS(0, cmp(a, a)); diff --git a/src/mongo/db/exec/inclusion_projection_executor_test.cpp b/src/mongo/db/exec/inclusion_projection_executor_test.cpp index e31e5867522..862675bc657 100644 --- a/src/mongo/db/exec/inclusion_projection_executor_test.cpp +++ b/src/mongo/db/exec/inclusion_projection_executor_test.cpp @@ -46,6 +46,7 @@ #include "mongo/db/pipeline/dependencies.h" #include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/db/query/projection_parser.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -82,8 +83,11 @@ public: base->run(); } } catch (...) { - log() << "exception while testing with allowFastPath=" << _allowFastPath - << " and allowFallBackToDefault=" << AllowFallBackToDefault; + LOGV2(20587, + "exception while testing with allowFastPath={allowFastPath} and " + "allowFallBackToDefault={AllowFallBackToDefault}", + "allowFastPath"_attr = _allowFastPath, + "AllowFallBackToDefault"_attr = AllowFallBackToDefault); throw; } } diff --git a/src/mongo/db/exec/multi_plan.cpp b/src/mongo/db/exec/multi_plan.cpp index 38805b4e31d..be859d79e1c 100644 --- a/src/mongo/db/exec/multi_plan.cpp +++ b/src/mongo/db/exec/multi_plan.cpp @@ -48,6 +48,7 @@ #include "mongo/db/query/explain.h" #include "mongo/db/query/plan_cache.h" #include "mongo/db/query/plan_ranker.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -117,7 +118,7 @@ PlanStage::StageState MultiPlanStage::doWork(WorkingSetID* out) { StageState state = bestPlan.root->work(out); if (PlanStage::FAILURE == state && hasBackupPlan()) { - LOG(5) << "Best plan errored out switching to backup"; + LOGV2_DEBUG(20588, 5, "Best plan errored out switching to backup"); // Uncache the bad solution if we fall back // on the backup solution. // @@ -138,7 +139,7 @@ PlanStage::StageState MultiPlanStage::doWork(WorkingSetID* out) { } if (hasBackupPlan() && PlanStage::ADVANCED == state) { - LOG(5) << "Best plan had a blocking stage, became unblocked"; + LOGV2_DEBUG(20589, 5, "Best plan had a blocking stage, became unblocked"); _backupPlanIdx = kNoSuchPlan; } @@ -250,15 +251,22 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { const auto& alreadyProduced = bestCandidate.results; const auto& bestSolution = bestCandidate.solution; - LOG(5) << "Winning solution:\n" << redact(bestSolution->toString()); - LOG(2) << "Winning plan: " << Explain::getPlanSummary(bestCandidate.root); + LOGV2_DEBUG(20590, + 5, + "Winning solution:\n{bestSolution}", + "bestSolution"_attr = redact(bestSolution->toString())); + LOGV2_DEBUG(20591, + 2, + "Winning plan: {Explain_getPlanSummary_bestCandidate_root}", + "Explain_getPlanSummary_bestCandidate_root"_attr = + Explain::getPlanSummary(bestCandidate.root)); _backupPlanIdx = kNoSuchPlan; if (bestSolution->hasBlockingStage && (0 == alreadyProduced.size())) { - LOG(5) << "Winner has blocking stage, looking for backup plan..."; + LOGV2_DEBUG(20592, 5, "Winner has blocking stage, looking for backup plan..."); for (auto&& ix : candidateOrder) { if (!_candidates[ix].solution->hasBlockingStage) { - LOG(5) << "Candidate " << ix << " is backup child"; + LOGV2_DEBUG(20593, 5, "Candidate {ix} is backup child", "ix"_attr = ix); _backupPlanIdx = ix; break; } @@ -286,12 +294,20 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { size_t winnerIdx = ranking->candidateOrder[0]; size_t runnerUpIdx = ranking->candidateOrder[1]; - LOG(1) << "Winning plan tied with runner-up. Not caching." - << " query: " << redact(_query->toStringShort()) - << " winner score: " << ranking->scores[0] - << " winner summary: " << Explain::getPlanSummary(_candidates[winnerIdx].root) - << " runner-up score: " << ranking->scores[1] << " runner-up summary: " - << Explain::getPlanSummary(_candidates[runnerUpIdx].root); + LOGV2_DEBUG(20594, + 1, + "Winning plan tied with runner-up. Not caching. query: {query_Short} " + "winner score: {ranking_scores_0} winner summary: " + "{Explain_getPlanSummary_candidates_winnerIdx_root} runner-up score: " + "{ranking_scores_1} runner-up summary: " + "{Explain_getPlanSummary_candidates_runnerUpIdx_root}", + "query_Short"_attr = redact(_query->toStringShort()), + "ranking_scores_0"_attr = ranking->scores[0], + "Explain_getPlanSummary_candidates_winnerIdx_root"_attr = + Explain::getPlanSummary(_candidates[winnerIdx].root), + "ranking_scores_1"_attr = ranking->scores[1], + "Explain_getPlanSummary_candidates_runnerUpIdx_root"_attr = + Explain::getPlanSummary(_candidates[runnerUpIdx].root)); } if (alreadyProduced.empty()) { @@ -300,10 +316,15 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { canCache = false; size_t winnerIdx = ranking->candidateOrder[0]; - LOG(1) << "Winning plan had zero results. Not caching." - << " query: " << redact(_query->toStringShort()) - << " winner score: " << ranking->scores[0] - << " winner summary: " << Explain::getPlanSummary(_candidates[winnerIdx].root); + LOGV2_DEBUG(20595, + 1, + "Winning plan had zero results. Not caching. query: {query_Short} winner " + "score: {ranking_scores_0} winner summary: " + "{Explain_getPlanSummary_candidates_winnerIdx_root}", + "query_Short"_attr = redact(_query->toStringShort()), + "ranking_scores_0"_attr = ranking->scores[0], + "Explain_getPlanSummary_candidates_winnerIdx_root"_attr = + Explain::getPlanSummary(_candidates[winnerIdx].root)); } } @@ -329,8 +350,11 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { bool validSolutions = true; for (size_t ix = 0; ix < solutions.size(); ++ix) { if (nullptr == solutions[ix]->cacheData.get()) { - LOG(5) << "Not caching query because this solution has no cache data: " - << redact(solutions[ix]->toString()); + LOGV2_DEBUG( + 20596, + 5, + "Not caching query because this solution has no cache data: {solutions_ix}", + "solutions_ix"_attr = redact(solutions[ix]->toString())); validSolutions = false; break; } diff --git a/src/mongo/db/exec/projection_executor_builder_test.cpp b/src/mongo/db/exec/projection_executor_builder_test.cpp index c89235aeb6b..ecdd29d44fc 100644 --- a/src/mongo/db/exec/projection_executor_builder_test.cpp +++ b/src/mongo/db/exec/projection_executor_builder_test.cpp @@ -39,6 +39,7 @@ #include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/db/query/projection_ast_util.h" #include "mongo/db/query/projection_parser.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -64,8 +65,11 @@ public: _allowFastPath = false; base->run(); } catch (...) { - log() << "exception while testing with allowFastPath=" << _allowFastPath - << " and allowFallBackToDefault=" << AllowFallBackToDefault; + LOGV2(20597, + "exception while testing with allowFastPath={allowFastPath} and " + "allowFallBackToDefault={AllowFallBackToDefault}", + "allowFastPath"_attr = _allowFastPath, + "AllowFallBackToDefault"_attr = AllowFallBackToDefault); throw; } } diff --git a/src/mongo/db/exec/subplan.cpp b/src/mongo/db/exec/subplan.cpp index c6fc9991185..dc9b66466b8 100644 --- a/src/mongo/db/exec/subplan.cpp +++ b/src/mongo/db/exec/subplan.cpp @@ -47,6 +47,7 @@ #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_common.h" #include "mongo/db/query/stage_builder.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" #include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" @@ -111,7 +112,7 @@ Status SubplanStage::planSubqueries() { const auto insertionRes = _indexMap.insert(std::make_pair(ie.identifier, i)); // Be sure the key was not already in the map. invariant(insertionRes.second); - LOG(5) << "Subplanner: index " << i << " is " << ie; + LOGV2_DEBUG(20598, 5, "Subplanner: index {i} is {ie}", "i"_attr = i, "ie"_attr = ie); } for (size_t i = 0; i < _orExpression->numChildren(); ++i) { @@ -141,8 +142,12 @@ Status SubplanStage::planSubqueries() { auto planCacheKey = planCache->computeKey(*branchResult->canonicalQuery); if (auto cachedSol = planCache->getCacheEntryIfActive(planCacheKey)) { // We have a CachedSolution. Store it for later. - LOG(5) << "Subplanner: cached plan found for child " << i << " of " - << _orExpression->numChildren(); + LOGV2_DEBUG( + 20599, + 5, + "Subplanner: cached plan found for child {i} of {orExpression_numChildren}", + "i"_attr = i, + "orExpression_numChildren"_attr = _orExpression->numChildren()); branchResult->cachedSolution = std::move(cachedSol); } @@ -150,7 +155,11 @@ Status SubplanStage::planSubqueries() { if (!branchResult->cachedSolution) { // No CachedSolution found. We'll have to plan from scratch. - LOG(5) << "Subplanner: planning child " << i << " of " << _orExpression->numChildren(); + LOGV2_DEBUG(20600, + 5, + "Subplanner: planning child {i} of {orExpression_numChildren}", + "i"_attr = i, + "orExpression_numChildren"_attr = _orExpression->numChildren()); // We don't set NO_TABLE_SCAN because peeking at the cache data will keep us from // considering any plan that's a collscan. @@ -164,7 +173,10 @@ Status SubplanStage::planSubqueries() { } branchResult->solutions = std::move(solutions.getValue()); - LOG(5) << "Subplanner: got " << branchResult->solutions.size() << " solutions"; + LOGV2_DEBUG(20601, + 5, + "Subplanner: got {branchResult_solutions_size} solutions", + "branchResult_solutions_size"_attr = branchResult->solutions.size()); } } @@ -329,7 +341,10 @@ Status SubplanStage::choosePlanForSubqueries(PlanYieldPolicy* yieldPolicy) { return Status(ErrorCodes::NoQueryExecutionPlans, ss); } - LOG(5) << "Subplanner: fully tagged tree is " << redact(solnRoot->toString()); + LOGV2_DEBUG(20602, + 5, + "Subplanner: fully tagged tree is {solnRoot}", + "solnRoot"_attr = redact(solnRoot->toString())); _compositeSolution = QueryPlannerAnalysis::analyzeDataAccess(*_query, _plannerParams, std::move(solnRoot)); @@ -340,7 +355,10 @@ Status SubplanStage::choosePlanForSubqueries(PlanYieldPolicy* yieldPolicy) { return Status(ErrorCodes::NoQueryExecutionPlans, ss); } - LOG(5) << "Subplanner: Composite solution is " << redact(_compositeSolution->toString()); + LOGV2_DEBUG(20603, + 5, + "Subplanner: Composite solution is {compositeSolution}", + "compositeSolution"_attr = redact(_compositeSolution->toString())); // Use the index tags from planning each branch to construct the composite solution, // and set that solution as our child stage. diff --git a/src/mongo/db/exec/trial_stage.cpp b/src/mongo/db/exec/trial_stage.cpp index 1e5b36fb7c4..4220631d974 100644 --- a/src/mongo/db/exec/trial_stage.cpp +++ b/src/mongo/db/exec/trial_stage.cpp @@ -40,6 +40,7 @@ #include "mongo/db/exec/or.h" #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/working_set_common.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -145,7 +146,10 @@ PlanStage::StageState TrialStage::_workTrialPlan(WorkingSetID* out) { // Either of these cause us to immediately end the trial phase and switch to the backup. auto statusDoc = WorkingSetCommon::getStatusMemberDocument(*_ws, *out); BSONObj statusObj = statusDoc ? statusDoc->toBson() : BSONObj(); - LOG(1) << "Trial plan failed; switching to backup plan. Status: " << redact(statusObj); + LOGV2_DEBUG(20604, + 1, + "Trial plan failed; switching to backup plan. Status: {statusObj}", + "statusObj"_attr = redact(statusObj)); _specificStats.trialCompleted = true; _replaceCurrentPlan(_backupPlan); *out = WorkingSet::INVALID_ID; diff --git a/src/mongo/db/exec/update_stage.cpp b/src/mongo/db/exec/update_stage.cpp index 2ded1a54e58..6ff31d7bf77 100644 --- a/src/mongo/db/exec/update_stage.cpp +++ b/src/mongo/db/exec/update_stage.cpp @@ -52,6 +52,7 @@ #include "mongo/db/storage/duplicate_key_error_info.h" #include "mongo/db/update/path_support.h" #include "mongo/db/update/storage_validation.h" +#include "mongo/logv2/log.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/s/would_change_owning_shard_exception.h" #include "mongo/util/assert_util.h" @@ -735,7 +736,7 @@ bool UpdateStage::checkUpdateChangesShardKeyFields(ScopedCollectionMetadata meta if (!metadata->keyBelongsToMe(newShardKey)) { if (MONGO_unlikely(hangBeforeThrowWouldChangeOwningShard.shouldFail())) { - log() << "Hit hangBeforeThrowWouldChangeOwningShard failpoint"; + LOGV2(20605, "Hit hangBeforeThrowWouldChangeOwningShard failpoint"); hangBeforeThrowWouldChangeOwningShard.pauseWhileSet(getOpCtx()); } diff --git a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp index 6b33f660d87..677f5ec18b3 100644 --- a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp +++ b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp @@ -27,15 +27,19 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/client/dbclient_connection.h" #include "mongo/client/dbclient_rs.h" #include "mongo/db/query/cursor_response.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/stdx/future.h" #include "mongo/unittest/integration_test.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" #include "mongo/util/system_clock_source.h" namespace mongo { @@ -114,9 +118,12 @@ bool confirmCurrentOpContents(DBClientBase* conn, sleepFor(intervalMS); } auto currentOp = BSON("currentOp" << BSON("idleCursors" << true)); - unittest::log() - << "confirmCurrentOpContents fails with curOpMatch: " << curOpMatch << " currentOp: " - << conn->runCommand(OpMsgRequest::fromDBAndBody("admin", currentOp))->getCommandReply(); + LOGV2(20606, + "confirmCurrentOpContents fails with curOpMatch: {curOpMatch} currentOp: " + "{conn_runCommand_OpMsgRequest_fromDBAndBody_admin_currentOp_getCommandReply}", + "curOpMatch"_attr = curOpMatch, + "conn_runCommand_OpMsgRequest_fromDBAndBody_admin_currentOp_getCommandReply"_attr = + conn->runCommand(OpMsgRequest::fromDBAndBody("admin", currentOp))->getCommandReply()); return false; } @@ -167,7 +174,9 @@ auto startExhaustQuery( sleepFor(Milliseconds(10)); } ASSERT(queryCursor); - unittest::log() << "Started exhaust query with cursorId: " << queryCursor->getCursorId(); + LOGV2(20607, + "Started exhaust query with cursorId: {queryCursor_getCursorId}", + "queryCursor_getCursorId"_attr = queryCursor->getCursorId()); return queryThread; } @@ -286,7 +295,7 @@ void testClientDisconnect(bool disconnectAfterGetMoreBatch) { // Kill the client connection while the exhaust getMore is blocked on the failpoint. queryConnection->shutdownAndDisallowReconnect(); - unittest::log() << "Killed exhaust connection."; + LOGV2(20608, "Killed exhaust connection."); if (disconnectAfterGetMoreBatch) { // Disable the failpoint to allow the exhaust getMore to continue sending out the response diff --git a/src/mongo/db/free_mon/free_mon_controller.cpp b/src/mongo/db/free_mon/free_mon_controller.cpp index a9de7ca4c49..895a278a57b 100644 --- a/src/mongo/db/free_mon/free_mon_controller.cpp +++ b/src/mongo/db/free_mon/free_mon_controller.cpp @@ -35,6 +35,7 @@ #include "mongo/db/ftdc/collector.h" #include "mongo/logger/logstream_builder.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -167,7 +168,7 @@ void FreeMonController::start(RegistrationType registrationType, void FreeMonController::stop() { // Stop the agent - log() << "Shutting down free monitoring"; + LOGV2(20609, "Shutting down free monitoring"); { stdx::lock_guard<Latch> lock(_mutex); @@ -198,7 +199,9 @@ void FreeMonController::turnCrankForTest(size_t countMessagesToIgnore) { invariant(_state == State::kStarted); } - log() << "Turning Crank: " << countMessagesToIgnore; + LOGV2(20610, + "Turning Crank: {countMessagesToIgnore}", + "countMessagesToIgnore"_attr = countMessagesToIgnore); _processor->turnCrankForTest(countMessagesToIgnore); } diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp index 296b3700b93..afb05e22f9f 100644 --- a/src/mongo/db/free_mon/free_mon_controller_test.cpp +++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp @@ -62,6 +62,7 @@ #include "mongo/db/service_context_d_test_fixture.h" #include "mongo/executor/network_interface_mock.h" #include "mongo/executor/thread_pool_task_executor_test_fixture.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/object_check.h" #include "mongo/unittest/barrier.h" #include "mongo/unittest/temp_dir.h" @@ -245,7 +246,7 @@ public: Future<FreeMonRegistrationResponse> sendRegistrationAsync( const FreeMonRegistrationRequest& req) final { - log() << "Sending Registration ..."; + LOGV2(20611, "Sending Registration ..."); _registers.addAndFetch(1); @@ -291,7 +292,7 @@ public: Future<FreeMonMetricsResponse> sendMetricsAsync(const FreeMonMetricsRequest& req) final { - log() << "Sending Metrics ..."; + LOGV2(20612, "Sending Metrics ..."); _metrics.addAndFetch(1); @@ -508,8 +509,8 @@ TEST(FreeMonRetryTest, TestRegistration) { // If jitter is large as possible, we'd expect trueMin increments before false. const auto trueMin = characterizeJitter(Seconds{9}, Seconds{119}); - // unittest::log() << "trueMin:" << trueMin; - // unittest::log() << "trueMax:" << trueMax; + // LOGV2(20613, "trueMin:{trueMin}", "trueMin"_attr = trueMin); + // LOGV2(20614, "trueMax:{trueMax}", "trueMax"_attr = trueMax); for (int j = 0; j < 30; j++) { // std::cout << "j: " << j << "\n"; diff --git a/src/mongo/db/free_mon/free_mon_processor.cpp b/src/mongo/db/free_mon/free_mon_processor.cpp index 8cb57bda42f..469488ba029 100644 --- a/src/mongo/db/free_mon/free_mon_processor.cpp +++ b/src/mongo/db/free_mon/free_mon_processor.cpp @@ -46,6 +46,7 @@ #include "mongo/db/free_mon/free_mon_storage.h" #include "mongo/db/service_context.h" #include "mongo/idl/idl_parser.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -259,9 +260,11 @@ void FreeMonProcessor::run() { // Stop the queue _queue.stop(); - warning() << "Uncaught exception in '" << exceptionToStatus() - << "' in free monitoring subsystem. Shutting down the " - "free monitoring subsystem."; + LOGV2_WARNING(20619, + "Uncaught exception in '{exceptionToStatus}' in free monitoring subsystem. " + "Shutting down the " + "free monitoring subsystem.", + "exceptionToStatus"_attr = exceptionToStatus()); } } @@ -600,7 +603,7 @@ void FreeMonProcessor::doAsyncRegisterComplete( Status s = validateRegistrationResponse(resp); if (!s.isOK()) { - warning() << "Free Monitoring registration halted due to " << s; + LOGV2_WARNING(20620, "Free Monitoring registration halted due to {s}", "s"_attr = s); // Disable on any error _state->setState(StorageStateEnum::disabled); @@ -646,7 +649,9 @@ void FreeMonProcessor::doAsyncRegisterComplete( // Notify waiters notifyPendingRegisters(Status::OK()); - log() << "Free Monitoring is Enabled. Frequency: " << resp.getReportingInterval() << " seconds"; + LOGV2(20615, + "Free Monitoring is Enabled. Frequency: {resp_getReportingInterval} seconds", + "resp_getReportingInterval"_attr = resp.getReportingInterval()); // Enqueue next metrics upload immediately to deliver a good experience enqueue(FreeMonMessage::createNow(FreeMonMessageType::MetricsSend)); @@ -666,12 +671,16 @@ void FreeMonProcessor::doAsyncRegisterFail( if (!_registrationRetry->incrementError()) { // We have exceeded our retry - warning() << "Free Monitoring is abandoning registration after excess retries"; + LOGV2_WARNING(20621, "Free Monitoring is abandoning registration after excess retries"); return; } - LOG(1) << "Free Monitoring Registration Failed with status '" << msg->getPayload() - << "', retrying in " << _registrationRetry->getNextDuration(); + LOGV2_DEBUG(20616, + 1, + "Free Monitoring Registration Failed with status '{msg_getPayload}', retrying in " + "{registrationRetry_getNextDuration}", + "msg_getPayload"_attr = msg->getPayload(), + "registrationRetry_getNextDuration"_attr = _registrationRetry->getNextDuration()); // Enqueue a register retry enqueue(FreeMonRegisterCommandMessage::createWithDeadline( @@ -688,7 +697,7 @@ void FreeMonProcessor::doCommandUnregister( writeState(client); - log() << "Free Monitoring is Disabled"; + LOGV2(20617, "Free Monitoring is Disabled"); msg->setStatus(Status::OK()); } @@ -778,7 +787,7 @@ void FreeMonProcessor::doAsyncMetricsComplete( Status s = validateMetricsResponse(resp); if (!s.isOK()) { - warning() << "Free Monitoring metrics uploading halted due to " << s; + LOGV2_WARNING(20622, "Free Monitoring metrics uploading halted due to {s}", "s"_attr = s); // Disable free monitoring on validation errors _state->setState(StorageStateEnum::disabled); @@ -851,12 +860,16 @@ void FreeMonProcessor::doAsyncMetricsFail( if (!_metricsRetry->incrementError()) { // We have exceeded our retry - warning() << "Free Monitoring is abandoning metrics upload after excess retries"; + LOGV2_WARNING(20623, "Free Monitoring is abandoning metrics upload after excess retries"); return; } - LOG(1) << "Free Monitoring Metrics upload failed with status " << msg->getPayload() - << ", retrying in " << _metricsRetry->getNextDuration(); + LOGV2_DEBUG(20618, + 1, + "Free Monitoring Metrics upload failed with status {msg_getPayload}, retrying in " + "{metricsRetry_getNextDuration}", + "msg_getPayload"_attr = msg->getPayload(), + "metricsRetry_getNextDuration"_attr = _metricsRetry->getNextDuration()); // Enqueue next metrics upload enqueue(FreeMonMessage::createWithDeadline(FreeMonMessageType::MetricsSend, @@ -948,9 +961,11 @@ void FreeMonProcessor::doNotifyOnUpsert( // Stop the queue _queue.stop(); - warning() << "Uncaught exception in '" << exceptionToStatus() - << "' in free monitoring op observer. Shutting down the " - "free monitoring subsystem."; + LOGV2_WARNING(20624, + "Uncaught exception in '{exceptionToStatus}' in free monitoring op observer. " + "Shutting down the " + "free monitoring subsystem.", + "exceptionToStatus"_attr = exceptionToStatus()); } } diff --git a/src/mongo/db/ftdc/controller.cpp b/src/mongo/db/ftdc/controller.cpp index 937fe0dbc7d..47acae27edf 100644 --- a/src/mongo/db/ftdc/controller.cpp +++ b/src/mongo/db/ftdc/controller.cpp @@ -39,6 +39,7 @@ #include "mongo/db/ftdc/collector.h" #include "mongo/db/ftdc/util.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/thread.h" @@ -137,8 +138,9 @@ BSONObj FTDCController::getMostRecentPeriodicDocument() { } void FTDCController::start() { - log() << "Initializing full-time diagnostic data capture with directory '" - << _path.generic_string() << "'"; + LOGV2(20625, + "Initializing full-time diagnostic data capture with directory '{path_generic_string}'", + "path_generic_string"_attr = _path.generic_string()); // Start the thread _thread = stdx::thread([this] { doLoop(); }); @@ -152,7 +154,7 @@ void FTDCController::start() { } void FTDCController::stop() { - log() << "Shutting down full-time diagnostic data capture"; + LOGV2(20626, "Shutting down full-time diagnostic data capture"); { stdx::lock_guard<Latch> lock(_mutex); @@ -180,7 +182,9 @@ void FTDCController::stop() { if (_mgr) { auto s = _mgr->close(); if (!s.isOK()) { - log() << "Failed to close full-time diagnostic data capture file manager: " << s; + LOGV2(20627, + "Failed to close full-time diagnostic data capture file manager: {s}", + "s"_attr = s); } } } diff --git a/src/mongo/db/ftdc/file_manager.cpp b/src/mongo/db/ftdc/file_manager.cpp index 61ac60fcc48..783e9793c55 100644 --- a/src/mongo/db/ftdc/file_manager.cpp +++ b/src/mongo/db/ftdc/file_manager.cpp @@ -43,6 +43,7 @@ #include "mongo/db/ftdc/constants.h" #include "mongo/db/ftdc/file_reader.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -227,8 +228,12 @@ Status FTDCFileManager::trimDirectory(std::vector<boost::filesystem::path>& file size += fileSize; if (size >= maxSize) { - LOG(1) << "Cleaning file over full-time diagnostic data capture quota, file: " - << (*it).generic_string() << " with size " << fileSize; + LOGV2_DEBUG(20628, + 1, + "Cleaning file over full-time diagnostic data capture quota, file: " + "{it_generic_string} with size {fileSize}", + "it_generic_string"_attr = (*it).generic_string(), + "fileSize"_attr = fileSize); boost::filesystem::remove(*it, ec); if (ec) { @@ -257,8 +262,9 @@ FTDCFileManager::recoverInterimFile() { boost::system::error_code ec; size_t size = boost::filesystem::file_size(interimFile, ec); if (ec) { - log() << "Recover interim file failed as the file size could not be checked: " - << ec.message(); + LOGV2(20629, + "Recover interim file failed as the file size could not be checked: {ec_message}", + "ec_message"_attr = ec.message()); return docs; } @@ -269,11 +275,12 @@ FTDCFileManager::recoverInterimFile() { FTDCFileReader read; auto s = read.open(interimFile); if (!s.isOK()) { - log() << "Unclean full-time diagnostic data capture shutdown detected, found interim file, " - "but failed " - "to open it, some " - "metrics may have been lost. " - << s; + LOGV2(20630, + "Unclean full-time diagnostic data capture shutdown detected, found interim file, " + "but failed " + "to open it, some " + "metrics may have been lost. {s}", + "s"_attr = s); // Note: We ignore any actual errors as reading from the interim files is a best-effort return docs; @@ -288,10 +295,11 @@ FTDCFileManager::recoverInterimFile() { // Warn if the interim file was corrupt or we had an unclean shutdown if (!m.isOK() || !docs.empty()) { - log() << "Unclean full-time diagnostic data capture shutdown detected, found interim file, " - "some " - "metrics may have been lost. " - << m.getStatus(); + LOGV2(20631, + "Unclean full-time diagnostic data capture shutdown detected, found interim file, " + "some " + "metrics may have been lost. {m_getStatus}", + "m_getStatus"_attr = m.getStatus()); } // Note: We ignore any actual errors as reading from the interim files is a best-effort diff --git a/src/mongo/db/ftdc/file_manager_test.cpp b/src/mongo/db/ftdc/file_manager_test.cpp index a6cf6c6b38c..c8fba1ddd2c 100644 --- a/src/mongo/db/ftdc/file_manager_test.cpp +++ b/src/mongo/db/ftdc/file_manager_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <algorithm> @@ -46,8 +48,10 @@ #include "mongo/db/ftdc/file_writer.h" #include "mongo/db/ftdc/ftdc_test.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/temp_dir.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace mongo { @@ -111,7 +115,10 @@ TEST_F(FTDCFileManagerTest, TestFull) { for (auto& file : files) { int fs = boost::filesystem::file_size(file); ASSERT_TRUE(fs < c.maxFileSizeBytes * 1.10); - unittest::log() << "File " << file.generic_string() << " has size " << fs; + LOGV2(20632, + "File {file_generic_string} has size {fs}", + "file_generic_string"_attr = file.generic_string(), + "fs"_attr = fs); if (file.generic_string().find("interim") == std::string::npos) { sum += fs; } diff --git a/src/mongo/db/ftdc/util.cpp b/src/mongo/db/ftdc/util.cpp index 9500bf62ecb..a1442ec8b6f 100644 --- a/src/mongo/db/ftdc/util.cpp +++ b/src/mongo/db/ftdc/util.cpp @@ -42,6 +42,7 @@ #include "mongo/db/ftdc/constants.h" #include "mongo/db/jsobj.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -180,8 +181,10 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc, while (itCurrent.more()) { // Schema mismatch if current document is longer than reference document if (matches && !itReference.more()) { - LOG(4) << "full-time diagnostic data capture schema change: currrent document is " - "longer than reference document"; + LOGV2_DEBUG(20633, + 4, + "full-time diagnostic data capture schema change: currrent document is " + "longer than reference document"); matches = false; } @@ -191,10 +194,15 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc, if (matches) { // Check for matching field names if (referenceElement.fieldNameStringData() != currentElement.fieldNameStringData()) { - LOG(4) - << "full-time diagnostic data capture schema change: field name change - from '" - << referenceElement.fieldNameStringData() << "' to '" - << currentElement.fieldNameStringData() << "'"; + LOGV2_DEBUG(20634, + 4, + "full-time diagnostic data capture schema change: field name change - " + "from '{referenceElement_fieldNameStringData}' to " + "'{currentElement_fieldNameStringData}'", + "referenceElement_fieldNameStringData"_attr = + referenceElement.fieldNameStringData(), + "currentElement_fieldNameStringData"_attr = + currentElement.fieldNameStringData()); matches = false; } @@ -205,11 +213,19 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc, if ((currentElement.type() != referenceElement.type()) && !(referenceElement.isNumber() == true && currentElement.isNumber() == referenceElement.isNumber())) { - LOG(4) << "full-time diagnostic data capture schema change: field type change for " - "field '" - << referenceElement.fieldNameStringData() << "' from '" - << static_cast<int>(referenceElement.type()) << "' to '" - << static_cast<int>(currentElement.type()) << "'"; + LOGV2_DEBUG( + 20635, + 4, + "full-time diagnostic data capture schema change: field type change for " + "field '{referenceElement_fieldNameStringData}' from " + "'{static_cast_int_referenceElement_type}' to " + "'{static_cast_int_currentElement_type}'", + "referenceElement_fieldNameStringData"_attr = + referenceElement.fieldNameStringData(), + "static_cast_int_referenceElement_type"_attr = + static_cast<int>(referenceElement.type()), + "static_cast_int_currentElement_type"_attr = + static_cast<int>(currentElement.type())); matches = false; } } @@ -261,8 +277,10 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc, // schema mismatch if ref is longer than curr if (matches && itReference.more()) { - LOG(4) << "full-time diagnostic data capture schema change: reference document is longer " - "then current"; + LOGV2_DEBUG(20636, + 4, + "full-time diagnostic data capture schema change: reference document is longer " + "then current"); matches = false; } diff --git a/src/mongo/db/geo/r2_region_coverer.cpp b/src/mongo/db/geo/r2_region_coverer.cpp index 284350f62ab..c1c6b06c28d 100644 --- a/src/mongo/db/geo/r2_region_coverer.cpp +++ b/src/mongo/db/geo/r2_region_coverer.cpp @@ -35,6 +35,7 @@ #include "mongo/db/geo/r2_region_coverer.h" #include "mongo/db/geo/shapes.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -108,7 +109,10 @@ void R2RegionCoverer::getCovering(const R2Region& region, vector<GeoHash>* cover Candidate* candidate = _candidateQueue->top().second; // Owned _candidateQueue->pop(); // REDACT?? I think this may have User info, but I'm not sure how to redact - LOG(3) << "Pop: " << redact(candidate->cell.toString()); + LOGV2_DEBUG(20637, + 3, + "Pop: {candidate_cell}", + "candidate_cell"_attr = redact(candidate->cell.toString())); // Try to expand this cell into its children if (candidate->cell.getBits() < _minLevel || candidate->numChildren == 1 || @@ -123,7 +127,10 @@ void R2RegionCoverer::getCovering(const R2Region& region, vector<GeoHash>* cover candidate->isTerminal = true; addCandidate(candidate); } - LOG(3) << "Queue: " << _candidateQueue->size(); + LOGV2_DEBUG(20638, + 3, + "Queue: {candidateQueue_size}", + "candidateQueue_size"_attr = _candidateQueue->size()); } _region = nullptr; @@ -185,7 +192,11 @@ void R2RegionCoverer::addCandidate(Candidate* candidate) { numTerminals); _candidateQueue->push(make_pair(priority, candidate)); // queue owns candidate // REDACT?? - LOG(3) << "Push: " << redact(candidate->cell.toString()) << " (" << priority << ") "; + LOGV2_DEBUG(20639, + 3, + "Push: {candidate_cell} ({priority}) ", + "candidate_cell"_attr = redact(candidate->cell.toString()), + "priority"_attr = priority); } } diff --git a/src/mongo/db/geo/r2_region_coverer_test.cpp b/src/mongo/db/geo/r2_region_coverer_test.cpp index d569cb78ce1..394698b1d47 100644 --- a/src/mongo/db/geo/r2_region_coverer_test.cpp +++ b/src/mongo/db/geo/r2_region_coverer_test.cpp @@ -38,6 +38,7 @@ #include "mongo/base/init.h" #include "mongo/bson/bsonmisc.h" #include "mongo/db/geo/geometry_container.h" +#include "mongo/logv2/log.h" #include "mongo/platform/random.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -58,7 +59,7 @@ MONGO_INITIALIZER(R2CellUnion_Test)(InitializerContext* context) { } } generator.seed(seed); - log() << "R2CellUnion Test - Random Number Generator Seed: " << seed; + LOGV2(20640, "R2CellUnion Test - Random Number Generator Seed: {seed}", "seed"_attr = seed); return Status::OK(); } @@ -226,8 +227,8 @@ void checkCellIdCovering(const GeoHashConverter& converter, // The covering doesn't contain this cell, so the region shouldn't contain this cell. if (region.fastContains(cell)) { - log() << "covering " << covering.toString(); - log() << "cellId " << cellId; + LOGV2(20641, "covering {covering}", "covering"_attr = covering.toString()); + LOGV2(20642, "cellId {cellId}", "cellId"_attr = cellId); } ASSERT_FALSE(region.fastContains(cell)); @@ -726,8 +727,12 @@ TEST(R2CellUnion, Normalize) { ASSERT_EQUALS(expected[i], cellUnion.cellIds()[i]); } } - log() << "Average Unnormalized Size: " << unnormalizedSum * 1.0 / kIters; - log() << "Average Normalized Size: " << normalizedSum * 1.0 / kIters; + LOGV2(20643, + "Average Unnormalized Size: {unnormalizedSum_1_0_kIters}", + "unnormalizedSum_1_0_kIters"_attr = unnormalizedSum * 1.0 / kIters); + LOGV2(20644, + "Average Normalized Size: {normalizedSum_1_0_kIters}", + "normalizedSum_1_0_kIters"_attr = normalizedSum * 1.0 / kIters); } void testContains(const R2CellUnion& cellUnion, GeoHash id, int num) { diff --git a/src/mongo/db/index/2d_key_generator_test.cpp b/src/mongo/db/index/2d_key_generator_test.cpp index 2745eb06b8a..88556e0b58e 100644 --- a/src/mongo/db/index/2d_key_generator_test.cpp +++ b/src/mongo/db/index/2d_key_generator_test.cpp @@ -40,6 +40,7 @@ #include "mongo/db/index/2d_common.h" #include "mongo/db/index/expression_params.h" #include "mongo/db/json.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -61,14 +62,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) { bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) { if (expectedKeys.size() != actualKeys.size()) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20645, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20646, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } diff --git a/src/mongo/db/index/btree_key_generator_test.cpp b/src/mongo/db/index/btree_key_generator_test.cpp index 811c5d41bab..4607d217de4 100644 --- a/src/mongo/db/index/btree_key_generator_test.cpp +++ b/src/mongo/db/index/btree_key_generator_test.cpp @@ -39,6 +39,7 @@ #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/json.h" #include "mongo/db/query/collation/collator_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -137,15 +138,22 @@ bool testKeygen(const BSONObj& kp, // bool match = keysetsEqual(expectedKeys, actualKeys); if (!match) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20647, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } match = (expectedMultikeyPaths == actualMultikeyPaths); if (!match) { - log() << "Expected: " << dumpMultikeyPaths(expectedMultikeyPaths) << ", " - << "Actual: " << dumpMultikeyPaths(actualMultikeyPaths); + LOGV2(20648, + "Expected: {dumpMultikeyPaths_expectedMultikeyPaths}, Actual: " + "{dumpMultikeyPaths_actualMultikeyPaths}", + "dumpMultikeyPaths_expectedMultikeyPaths"_attr = + dumpMultikeyPaths(expectedMultikeyPaths), + "dumpMultikeyPaths_actualMultikeyPaths"_attr = + dumpMultikeyPaths(actualMultikeyPaths)); } return match; diff --git a/src/mongo/db/index/duplicate_key_tracker.cpp b/src/mongo/db/index/duplicate_key_tracker.cpp index 9898415dfe4..fc1d3604f90 100644 --- a/src/mongo/db/index/duplicate_key_tracker.cpp +++ b/src/mongo/db/index/duplicate_key_tracker.cpp @@ -37,6 +37,7 @@ #include "mongo/db/curop.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/keypattern.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -79,8 +80,13 @@ Status DuplicateKeyTracker::recordKeys(OperationContext* opCtx, const std::vecto records.emplace_back(Record{RecordId(), RecordData(obj.objdata(), obj.objsize())}); } - LOG(1) << "recording " << records.size() << " duplicate key conflicts on unique index: " - << _indexCatalogEntry->descriptor()->indexName(); + LOGV2_DEBUG(20676, + 1, + "recording {records_size} duplicate key conflicts on unique index: " + "{indexCatalogEntry_descriptor_indexName}", + "records_size"_attr = records.size(), + "indexCatalogEntry_descriptor_indexName"_attr = + _indexCatalogEntry->descriptor()->indexName()); WriteUnitOfWork wuow(opCtx); std::vector<Timestamp> timestamps(records.size()); @@ -138,9 +144,13 @@ Status DuplicateKeyTracker::checkConstraints(OperationContext* opCtx) const { invariant(resolved == _duplicateCounter.load()); int logLevel = (resolved > 0) ? 0 : 1; - LOG(logLevel) << "index build: resolved " << resolved - << " duplicate key conflicts for unique index: " - << _indexCatalogEntry->descriptor()->indexName(); + LOGV2_DEBUG(20677, + logSeverityV1toV2(logLevel).toInt(), + "index build: resolved {resolved} duplicate key conflicts for unique index: " + "{indexCatalogEntry_descriptor_indexName}", + "resolved"_attr = resolved, + "indexCatalogEntry_descriptor_indexName"_attr = + _indexCatalogEntry->descriptor()->indexName()); return Status::OK(); } diff --git a/src/mongo/db/index/hash_key_generator_test.cpp b/src/mongo/db/index/hash_key_generator_test.cpp index f2babba8cb4..c75e526ae47 100644 --- a/src/mongo/db/index/hash_key_generator_test.cpp +++ b/src/mongo/db/index/hash_key_generator_test.cpp @@ -40,6 +40,7 @@ #include "mongo/db/hasher.h" #include "mongo/db/json.h" #include "mongo/db/query/collation/collator_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -64,14 +65,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) { bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) { if (expectedKeys.size() != actualKeys.size()) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20678, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20679, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } diff --git a/src/mongo/db/index/haystack_access_method.cpp b/src/mongo/db/index/haystack_access_method.cpp index e309dcaebed..98a04d22d89 100644 --- a/src/mongo/db/index/haystack_access_method.cpp +++ b/src/mongo/db/index/haystack_access_method.cpp @@ -44,6 +44,7 @@ #include "mongo/db/index/haystack_access_method_internal.h" #include "mongo/db/jsobj.h" #include "mongo/db/query/internal_plans.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -89,8 +90,12 @@ void HaystackAccessMethod::searchCommand(OperationContext* opCtx, unsigned limit) const { Timer t; - LOG(1) << "SEARCH near:" << redact(nearObj) << " maxDistance:" << maxDistance - << " search: " << redact(search); + LOGV2_DEBUG(20680, + 1, + "SEARCH near:{nearObj} maxDistance:{maxDistance} search: {search}", + "nearObj"_attr = redact(nearObj), + "maxDistance"_attr = maxDistance, + "search"_attr = redact(search)); int x, y; { BSONObjIterator i(nearObj); diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index cb325e1e6ab..f929b0f3ffa 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -52,6 +52,7 @@ #include "mongo/db/repl/timestamp_block.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/progress_meter.h" #include "mongo/util/scopeguard.h" @@ -113,7 +114,10 @@ bool AbstractIndexAccessMethod::isFatalError(OperationContext* opCtx, // A document might be indexed multiple times during a background index build if it moves ahead // of the cursor (e.g. via an update). We test this scenario and swallow the error accordingly. if (status == ErrorCodes::DuplicateKeyValue && !_indexCatalogEntry->isReady(opCtx)) { - LOG(3) << "KeyString " << key << " already in index during background indexing (ok)"; + LOGV2_DEBUG(20681, + 3, + "KeyString {key} already in index during background indexing (ok)", + "key"_attr = key); return false; } return true; @@ -200,10 +204,16 @@ void AbstractIndexAccessMethod::removeOneKey(OperationContext* opCtx, try { _newInterface->unindex(opCtx, keyString, dupsAllowed); } catch (AssertionException& e) { - log() << "Assertion failure: _unindex failed on: " << _descriptor->parentNS() - << " for index: " << _descriptor->indexName(); - log() << "Assertion failure: _unindex failed: " << redact(e) << " KeyString:" << keyString - << " dl:" << loc; + LOGV2(20682, + "Assertion failure: _unindex failed on: {descriptor_parentNS} for index: " + "{descriptor_indexName}", + "descriptor_parentNS"_attr = _descriptor->parentNS(), + "descriptor_indexName"_attr = _descriptor->indexName()); + LOGV2(20683, + "Assertion failure: _unindex failed: {e} KeyString:{keyString} dl:{loc}", + "e"_attr = redact(e), + "keyString"_attr = keyString, + "loc"_attr = loc); logContext(); } } @@ -523,8 +533,13 @@ Status AbstractIndexAccessMethod::BulkBuilderImpl::insert(OperationContext* opCt // index builder can retry at a point when data is consistent. auto interceptor = _indexCatalogEntry->indexBuildInterceptor(); if (interceptor && interceptor->getSkippedRecordTracker()) { - LOG(1) << "Recording suppressed key generation error to retry later: " << status - << " on " << loc << ": " << redact(obj); + LOGV2_DEBUG(20684, + 1, + "Recording suppressed key generation error to retry later: " + "{status} on {loc}: {obj}", + "status"_attr = status, + "loc"_attr = loc, + "obj"_attr = redact(obj)); interceptor->getSkippedRecordTracker()->record(opCtx, loc); } }); @@ -618,9 +633,11 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx, if (kDebugBuild || _descriptor->unique()) { cmpData = data.first.compareWithoutRecordId(previousKey); if (cmpData < 0) { - severe() << "expected the next key" << data.first.toString() - << " to be greater than or equal to the previous key" - << previousKey.toString(); + LOGV2_FATAL(20687, + "expected the next key{data_first} to be greater than or equal to the " + "previous key{previousKey}", + "data_first"_attr = data.first.toString(), + "previousKey"_attr = previousKey.toString()); fassertFailedNoTrace(31171); } } @@ -667,8 +684,11 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx, pm.finished(); - log() << "index build: inserted " << bulk->getKeysInserted() - << " keys from external sorter into index in " << timer.seconds() << " seconds"; + LOGV2(20685, + "index build: inserted {bulk_getKeysInserted} keys from external sorter into index in " + "{timer_seconds} seconds", + "bulk_getKeysInserted"_attr = bulk->getKeysInserted(), + "timer_seconds"_attr = timer.seconds()); WriteUnitOfWork wunit(opCtx); builder->commit(true); @@ -682,8 +702,13 @@ void AbstractIndexAccessMethod::setIndexIsMultikey(OperationContext* opCtx, Mult IndexAccessMethod::OnSuppressedErrorFn IndexAccessMethod::kNoopOnSuppressedErrorFn = [](Status status, const BSONObj& obj, boost::optional<RecordId> loc) { - LOG(1) << "Suppressed key generation error: " << redact(status) - << " when getting index keys for " << loc << ": " << redact(obj); + LOGV2_DEBUG( + 20686, + 1, + "Suppressed key generation error: {status} when getting index keys for {loc}: {obj}", + "status"_attr = redact(status), + "loc"_attr = loc, + "obj"_attr = redact(obj)); }; void AbstractIndexAccessMethod::getKeys(const BSONObj& obj, diff --git a/src/mongo/db/index/index_access_method_factory_impl.cpp b/src/mongo/db/index/index_access_method_factory_impl.cpp index 2eb06511d1b..bff506b0023 100644 --- a/src/mongo/db/index/index_access_method_factory_impl.cpp +++ b/src/mongo/db/index/index_access_method_factory_impl.cpp @@ -40,6 +40,7 @@ #include "mongo/db/index/haystack_access_method.h" #include "mongo/db/index/s2_access_method.h" #include "mongo/db/index/wildcard_access_method.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -62,7 +63,9 @@ std::unique_ptr<IndexAccessMethod> IndexAccessMethodFactoryImpl::make( return std::make_unique<TwoDAccessMethod>(entry, std::move(sortedDataInterface)); else if (IndexNames::WILDCARD == type) return std::make_unique<WildcardAccessMethod>(entry, std::move(sortedDataInterface)); - log() << "Can't find index for keyPattern " << desc->keyPattern(); + LOGV2(20688, + "Can't find index for keyPattern {desc_keyPattern}", + "desc_keyPattern"_attr = desc->keyPattern()); fassertFailed(31021); } diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp index 90de76f1be5..8ca9bf0fd20 100644 --- a/src/mongo/db/index/index_build_interceptor.cpp +++ b/src/mongo/db/index/index_build_interceptor.cpp @@ -46,6 +46,7 @@ #include "mongo/db/multi_key_path_tracker.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/progress_meter.h" @@ -268,10 +269,17 @@ Status IndexBuildInterceptor::drainWritesIntoIndex(OperationContext* opCtx, progress->finished(); int logLevel = (_numApplied - appliedAtStart > 0) ? 0 : 1; - LOG(logLevel) << "index build: drain applied " << (_numApplied - appliedAtStart) - << " side writes (inserted: " << totalInserted << ", deleted: " << totalDeleted - << ") for '" << _indexCatalogEntry->descriptor()->indexName() << "' in " - << timer.millis() << " ms"; + LOGV2_DEBUG(20689, + logSeverityV1toV2(logLevel).toInt(), + "index build: drain applied {numApplied_appliedAtStart} side writes (inserted: " + "{totalInserted}, deleted: {totalDeleted}) for " + "'{indexCatalogEntry_descriptor_indexName}' in {timer_millis} ms", + "numApplied_appliedAtStart"_attr = (_numApplied - appliedAtStart), + "totalInserted"_attr = totalInserted, + "totalDeleted"_attr = totalDeleted, + "indexCatalogEntry_descriptor_indexName"_attr = + _indexCatalogEntry->descriptor()->indexName(), + "timer_millis"_attr = timer.millis()); return Status::OK(); } @@ -355,7 +363,7 @@ void IndexBuildInterceptor::_yield(OperationContext* opCtx) { hangDuringIndexBuildDrainYield.executeIf( [&](auto&&) { - log() << "Hanging index build during drain yield"; + LOGV2(20690, "Hanging index build during drain yield"); hangDuringIndexBuildDrainYield.pauseWhileSet(); }, [&](auto&& config) { @@ -380,7 +388,7 @@ bool IndexBuildInterceptor::areAllWritesApplied(OperationContext* opCtx) const { << writesRecorded << ", applied: " << _numApplied; dassert(writesRecorded == _numApplied, message); - warning() << message; + LOGV2_WARNING(20692, "{message}", "message"_attr = message); } return true; } @@ -482,8 +490,13 @@ Status IndexBuildInterceptor::sideWrite(OperationContext* opCtx, RecordData(doc.objdata(), doc.objsize())}); } - LOG(2) << "recording " << records.size() << " side write keys on index '" - << _indexCatalogEntry->descriptor()->indexName() << "'"; + LOGV2_DEBUG(20691, + 2, + "recording {records_size} side write keys on index " + "'{indexCatalogEntry_descriptor_indexName}'", + "records_size"_attr = records.size(), + "indexCatalogEntry_descriptor_indexName"_attr = + _indexCatalogEntry->descriptor()->indexName()); // By passing a vector of null timestamps, these inserts are not timestamped individually, but // rather with the timestamp of the owning operation. diff --git a/src/mongo/db/index/s2_key_generator_test.cpp b/src/mongo/db/index/s2_key_generator_test.cpp index 1a8432d0ff6..40ec009fcc3 100644 --- a/src/mongo/db/index/s2_key_generator_test.cpp +++ b/src/mongo/db/index/s2_key_generator_test.cpp @@ -41,6 +41,7 @@ #include "mongo/db/index/s2_common.h" #include "mongo/db/json.h" #include "mongo/db/query/collation/collator_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -79,14 +80,18 @@ std::string dumpMultikeyPaths(const MultikeyPaths& multikeyPaths) { bool areKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) { if (expectedKeys.size() != actualKeys.size()) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20693, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20694, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } diff --git a/src/mongo/db/index/wildcard_key_generator_test.cpp b/src/mongo/db/index/wildcard_key_generator_test.cpp index 4d5d7f9f3c1..4a3233caa04 100644 --- a/src/mongo/db/index/wildcard_key_generator_test.cpp +++ b/src/mongo/db/index/wildcard_key_generator_test.cpp @@ -34,6 +34,7 @@ #include "mongo/bson/json.h" #include "mongo/db/index/wildcard_key_generator.h" #include "mongo/db/query/collation/collator_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -67,14 +68,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) { bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) { if (expectedKeys.size() != actualKeys.size()) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20695, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) { - log() << "Expected: " << dumpKeyset(expectedKeys) << ", " - << "Actual: " << dumpKeyset(actualKeys); + LOGV2(20696, + "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}", + "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys), + "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys)); return false; } diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index b18f136597a..629ccf6b2d3 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -56,6 +56,7 @@ #include "mongo/db/server_recovery.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -255,8 +256,13 @@ void unlockRSTLForIndexCleanup(OperationContext* opCtx) { void logFailure(Status status, const NamespaceString& nss, std::shared_ptr<ReplIndexBuildState> replState) { - log() << "Index build failed: " << replState->buildUUID << ": " << nss << " ( " - << replState->collectionUUID << " ): " << status; + LOGV2( + 20649, + "Index build failed: {replState_buildUUID}: {nss} ( {replState_collectionUUID} ): {status}", + "replState_buildUUID"_attr = replState->buildUUID, + "nss"_attr = nss, + "replState_collectionUUID"_attr = replState->collectionUUID, + "status"_attr = status); } /** @@ -270,16 +276,26 @@ void forEachIndexBuild( return; } - log() << logPrefix << "active index builds: " << indexBuilds.size(); + LOGV2(20650, + "{logPrefix}active index builds: {indexBuilds_size}", + "logPrefix"_attr = logPrefix, + "indexBuilds_size"_attr = indexBuilds.size()); for (auto replState : indexBuilds) { std::string indexNamesStr; str::joinStringDelim(replState->indexNames, &indexNamesStr, ','); - log() << logPrefix << replState->buildUUID << ": collection: " << replState->collectionUUID - << "; indexes: " << replState->indexNames.size() << " [" << indexNamesStr - << "]; method: " - << (IndexBuildProtocol::kTwoPhase == replState->protocol ? "two phase" - : "single phase"); + LOGV2(20651, + "{logPrefix}{replState_buildUUID}: collection: {replState_collectionUUID}; indexes: " + "{replState_indexNames_size} [{indexNamesStr}]; method: " + "{IndexBuildProtocol_kTwoPhase_replState_protocol_two_phase_single_phase}", + "logPrefix"_attr = logPrefix, + "replState_buildUUID"_attr = replState->buildUUID, + "replState_collectionUUID"_attr = replState->collectionUUID, + "replState_indexNames_size"_attr = replState->indexNames.size(), + "indexNamesStr"_attr = indexNamesStr, + "IndexBuildProtocol_kTwoPhase_replState_protocol_two_phase_single_phase"_attr = + (IndexBuildProtocol::kTwoPhase == replState->protocol ? "two phase" + : "single phase")); onIndexBuild(replState); } @@ -402,9 +418,11 @@ Status IndexBuildsCoordinator::_startIndexBuildForRecovery(OperationContext* opC // after an abort has been rolled back. if (!DurableCatalog::get(opCtx)->isIndexPresent( opCtx, collection->getCatalogId(), indexNames[i])) { - log() << "The index for build " << buildUUID - << " was not found while trying to drop the index during recovery: " - << indexNames[i]; + LOGV2(20652, + "The index for build {buildUUID} was not found while trying to drop the " + "index during recovery: {indexNames_i}", + "buildUUID"_attr = buildUUID, + "indexNames_i"_attr = indexNames[i]); continue; } @@ -583,11 +601,15 @@ void IndexBuildsCoordinator::applyCommitIndexBuild(OperationContext* opCtx, // If the index build was not found, we must restart the build. For some reason the index // build has already been aborted on this node. This is possible in certain infrequent race // conditions with stepdown, shutdown, and user interruption. - log() << "Could not find an active index build with UUID " << buildUUID - << " while processing a commitIndexBuild oplog entry. Restarting the index build on " - "collection " - << nss << " (" << collUUID << ") at optime " - << opCtx->recoveryUnit()->getCommitTimestamp(); + LOGV2(20653, + "Could not find an active index build with UUID {buildUUID} while processing a " + "commitIndexBuild oplog entry. Restarting the index build on " + "collection {nss} ({collUUID}) at optime {opCtx_recoveryUnit_getCommitTimestamp}", + "buildUUID"_attr = buildUUID, + "nss"_attr = nss, + "collUUID"_attr = collUUID, + "opCtx_recoveryUnit_getCommitTimestamp"_attr = + opCtx->recoveryUnit()->getCommitTimestamp()); IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions; indexBuildOptions.replSetAndNotPrimaryAtStart = true; @@ -621,7 +643,10 @@ void IndexBuildsCoordinator::applyCommitIndexBuild(OperationContext* opCtx, replState->condVar.notify_all(); } auto fut = replState->sharedPromise.getFuture(); - log() << "Index build joined after commit: " << buildUUID << ": " << fut.waitNoThrow(opCtx); + LOGV2(20654, + "Index build joined after commit: {buildUUID}: {fut_waitNoThrow_opCtx}", + "buildUUID"_attr = buildUUID, + "fut_waitNoThrow_opCtx"_attr = fut.waitNoThrow(opCtx)); // Throws if there was an error building the index. fut.get(); @@ -661,7 +686,10 @@ void IndexBuildsCoordinator::abortIndexBuildByBuildUUID(OperationContext* opCtx, auto replState = invariant(_getIndexBuild(buildUUID)); auto fut = replState->sharedPromise.getFuture(); - log() << "Index build joined after abort: " << buildUUID << ": " << fut.waitNoThrow(); + LOGV2(20655, + "Index build joined after abort: {buildUUID}: {fut_waitNoThrow}", + "buildUUID"_attr = buildUUID, + "fut_waitNoThrow"_attr = fut.waitNoThrow()); } bool IndexBuildsCoordinator::abortIndexBuildByBuildUUIDNoWait(OperationContext* opCtx, @@ -674,8 +702,10 @@ bool IndexBuildsCoordinator::abortIndexBuildByBuildUUIDNoWait(OperationContext* // succeed, so suppress the error. auto replStateResult = _getIndexBuild(buildUUID); if (!replStateResult.isOK()) { - log() << "ignoring error while aborting index build " << buildUUID << ": " - << replStateResult.getStatus(); + LOGV2(20656, + "ignoring error while aborting index build {buildUUID}: {replStateResult_getStatus}", + "buildUUID"_attr = buildUUID, + "replStateResult_getStatus"_attr = replStateResult.getStatus()); return false; } @@ -718,7 +748,7 @@ std::size_t IndexBuildsCoordinator::getActiveIndexBuildCount(OperationContext* o } void IndexBuildsCoordinator::onStepUp(OperationContext* opCtx) { - log() << "IndexBuildsCoordinator::onStepUp - this node is stepping up to primary"; + LOGV2(20657, "IndexBuildsCoordinator::onStepUp - this node is stepping up to primary"); auto indexBuilds = _getIndexBuilds(); auto onIndexBuild = [this, opCtx](std::shared_ptr<ReplIndexBuildState> replState) { @@ -753,35 +783,37 @@ void IndexBuildsCoordinator::onStepUp(OperationContext* opCtx) { } IndexBuilds IndexBuildsCoordinator::onRollback(OperationContext* opCtx) { - log() << "IndexBuildsCoordinator::onRollback - this node is entering the rollback state"; + LOGV2(20658, "IndexBuildsCoordinator::onRollback - this node is entering the rollback state"); IndexBuilds buildsAborted; auto indexBuilds = _getIndexBuilds(); - auto onIndexBuild = [this, opCtx, &buildsAborted]( - std::shared_ptr<ReplIndexBuildState> replState) { - if (IndexBuildProtocol::kSinglePhase == replState->protocol) { - log() << "IndexBuildsCoordinator::onRollback - not aborting single phase index build: " - << replState->buildUUID; - return; - } - const std::string reason = "rollback"; - - IndexBuildDetails aborted{replState->collectionUUID}; - // Record the index builds aborted due to rollback. This allows any rollback algorithm - // to efficiently restart all unfinished index builds without having to scan all indexes - // in all collections. - for (auto spec : replState->indexSpecs) { - aborted.indexSpecs.emplace_back(spec.getOwned()); - } - buildsAborted.insert({replState->buildUUID, aborted}); + auto onIndexBuild = + [this, opCtx, &buildsAborted](std::shared_ptr<ReplIndexBuildState> replState) { + if (IndexBuildProtocol::kSinglePhase == replState->protocol) { + LOGV2(20659, + "IndexBuildsCoordinator::onRollback - not aborting single phase index build: " + "{replState_buildUUID}", + "replState_buildUUID"_attr = replState->buildUUID); + return; + } + const std::string reason = "rollback"; + + IndexBuildDetails aborted{replState->collectionUUID}; + // Record the index builds aborted due to rollback. This allows any rollback algorithm + // to efficiently restart all unfinished index builds without having to scan all indexes + // in all collections. + for (auto spec : replState->indexSpecs) { + aborted.indexSpecs.emplace_back(spec.getOwned()); + } + buildsAborted.insert({replState->buildUUID, aborted}); - // Leave abort timestamp as null. This will unblock the index build and allow it to - // complete without cleaning up. Subsequently, the rollback algorithm can decide how to - // undo the index build depending on the state of the oplog. Waits for index build - // thread to exit. - abortIndexBuildByBuildUUID(opCtx, replState->buildUUID, Timestamp(), reason); - }; + // Leave abort timestamp as null. This will unblock the index build and allow it to + // complete without cleaning up. Subsequently, the rollback algorithm can decide how to + // undo the index build depending on the state of the oplog. Waits for index build + // thread to exit. + abortIndexBuildByBuildUUID(opCtx, replState->buildUUID, Timestamp(), reason); + }; forEachIndexBuild(indexBuilds, "IndexBuildsCoordinator::onRollback - "_sd, onIndexBuild); return buildsAborted; } @@ -793,8 +825,12 @@ void IndexBuildsCoordinator::restartIndexBuildsForRecovery(OperationContext* opC CollectionCatalog::get(opCtx).lookupNSSByUUID(opCtx, build.collUUID); invariant(nss); - log() << "Restarting index build for collection: " << *nss - << ", collection UUID: " << build.collUUID << ", index build UUID: " << buildUUID; + LOGV2(20660, + "Restarting index build for collection: {nss}, collection UUID: {build_collUUID}, " + "index build UUID: {buildUUID}", + "nss"_attr = *nss, + "build_collUUID"_attr = build.collUUID, + "buildUUID"_attr = buildUUID); IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions; // Start the index build as if in secondary oplog application. @@ -1074,7 +1110,7 @@ Status IndexBuildsCoordinator::_registerIndexBuild( } } std::string msg = ss; - log() << msg; + LOGV2(20661, "{msg}", "msg"_attr = msg); if (aborted) { return {ErrorCodes::IndexBuildAborted, msg}; } @@ -1304,7 +1340,8 @@ IndexBuildsCoordinator::PostSetupAction IndexBuildsCoordinator::_setUpIndexBuild ((status == ErrorCodes::IndexOptionsConflict || status == ErrorCodes::IndexKeySpecsConflict) && options.indexConstraints == IndexBuildsManager::IndexConstraints::kRelax)) { - LOG(1) << "Ignoring indexing error: " << redact(status); + LOGV2_DEBUG( + 20662, 1, "Ignoring indexing error: {status}", "status"_attr = redact(status)); return PostSetupAction::kCompleteIndexBuildEarly; } @@ -1599,11 +1636,17 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, _indexBuildsManager.tearDownIndexBuild( opCtx, collection, replState->buildUUID, MultiIndexBlock::kNoopOnCleanUpFn); - log() << "Index build completed successfully: " << replState->buildUUID << ": " << nss - << " ( " << replState->collectionUUID - << " ). Index specs built: " << replState->indexSpecs.size() - << ". Indexes in catalog before build: " << replState->stats.numIndexesBefore - << ". Indexes in catalog after build: " << replState->stats.numIndexesAfter; + LOGV2(20663, + "Index build completed successfully: {replState_buildUUID}: {nss} ( " + "{replState_collectionUUID} ). Index specs built: {replState_indexSpecs_size}. " + "Indexes in catalog before build: {replState_stats_numIndexesBefore}. Indexes in " + "catalog after build: {replState_stats_numIndexesAfter}", + "replState_buildUUID"_attr = replState->buildUUID, + "nss"_attr = nss, + "replState_collectionUUID"_attr = replState->collectionUUID, + "replState_indexSpecs_size"_attr = replState->indexSpecs.size(), + "replState_stats_numIndexesBefore"_attr = replState->stats.numIndexesBefore, + "replState_stats_numIndexesAfter"_attr = replState->stats.numIndexesAfter); return; } @@ -1678,9 +1721,11 @@ void IndexBuildsCoordinator::_buildIndexTwoPhase( if (!replSetAndNotPrimary) { throw; } - log() << "Index build failed before final phase during oplog application. " - "Waiting for abort: " - << replState->buildUUID << ": " << ex; + LOGV2(20664, + "Index build failed before final phase during oplog application. " + "Waiting for abort: {replState_buildUUID}: {ex}", + "replState_buildUUID"_attr = replState->buildUUID, + "ex"_attr = ex); preAbortStatus = ex.toStatus(); } @@ -1735,7 +1780,7 @@ void IndexBuildsCoordinator::_scanCollectionAndInsertKeysIntoSorter( } if (MONGO_unlikely(hangAfterIndexBuildDumpsInsertsFromBulk.shouldFail())) { - log() << "Hanging after dumping inserts from bulk builder"; + LOGV2(20665, "Hanging after dumping inserts from bulk builder"); hangAfterIndexBuildDumpsInsertsFromBulk.pauseWhileSet(); } } @@ -1761,7 +1806,7 @@ NamespaceString IndexBuildsCoordinator::_insertKeysFromSideTablesWithoutBlocking } if (MONGO_unlikely(hangAfterIndexBuildFirstDrain.shouldFail())) { - log() << "Hanging after index build first drain"; + LOGV2(20666, "Hanging after index build first drain"); hangAfterIndexBuildFirstDrain.pauseWhileSet(); } @@ -1783,7 +1828,7 @@ NamespaceString IndexBuildsCoordinator::_insertKeysFromSideTablesWithoutBlocking } if (MONGO_unlikely(hangAfterIndexBuildSecondDrain.shouldFail())) { - log() << "Hanging after index build second drain"; + LOGV2(20667, "Hanging after index build second drain"); hangAfterIndexBuildSecondDrain.pauseWhileSet(); } @@ -1800,8 +1845,10 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort( const Status& preAbortStatus) { Timestamp commitIndexBuildTimestamp; if (shouldWaitForCommitOrAbort(opCtx, nss, *replState)) { - log() << "Index build waiting for commit or abort before completing final phase: " - << replState->buildUUID; + LOGV2(20668, + "Index build waiting for commit or abort before completing final phase: " + "{replState_buildUUID}", + "replState_buildUUID"_attr = replState->buildUUID); // Yield locks and storage engine resources before blocking. opCtx->recoveryUnit()->abandonSnapshot(); @@ -1816,9 +1863,12 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort( opCtx->waitForConditionOrInterrupt(replState->condVar, lk, isReadyToCommitOrAbort); if (replState->isCommitReady) { - log() << "Committing index build: " << replState->buildUUID - << ", timestamp: " << replState->commitTimestamp - << ", collection UUID: " << replState->collectionUUID; + LOGV2(20669, + "Committing index build: {replState_buildUUID}, timestamp: " + "{replState_commitTimestamp}, collection UUID: {replState_collectionUUID}", + "replState_buildUUID"_attr = replState->buildUUID, + "replState_commitTimestamp"_attr = replState->commitTimestamp, + "replState_collectionUUID"_attr = replState->collectionUUID); commitIndexBuildTimestamp = replState->commitTimestamp; invariant(!replState->aborted, replState->buildUUID.toString()); uassertStatusOK(preAbortStatus.withContext( @@ -1826,11 +1876,15 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort( "commitIndexBuild oplog entry from the primary with timestamp: " << replState->commitTimestamp.toString())); } else if (replState->aborted) { - log() << "Aborting index build: " << replState->buildUUID - << ", timestamp: " << replState->abortTimestamp - << ", reason: " << replState->abortReason - << ", collection UUID: " << replState->collectionUUID - << ", local index error (if any): " << preAbortStatus; + LOGV2(20670, + "Aborting index build: {replState_buildUUID}, timestamp: " + "{replState_abortTimestamp}, reason: {replState_abortReason}, collection UUID: " + "{replState_collectionUUID}, local index error (if any): {preAbortStatus}", + "replState_buildUUID"_attr = replState->buildUUID, + "replState_abortTimestamp"_attr = replState->abortTimestamp, + "replState_abortReason"_attr = replState->abortReason, + "replState_collectionUUID"_attr = replState->collectionUUID, + "preAbortStatus"_attr = preAbortStatus); invariant(!replState->isCommitReady, replState->buildUUID.toString()); } } @@ -1905,14 +1959,16 @@ void IndexBuildsCoordinator::_insertKeysFromSideTablesAndCommit( } if (indexBuildOptions.replSetAndNotPrimaryAtStart) { - LOG(1) << "Skipping createIndexes oplog entry for index build: " - << replState->buildUUID; + LOGV2_DEBUG(20671, + 1, + "Skipping createIndexes oplog entry for index build: {replState_buildUUID}", + "replState_buildUUID"_attr = replState->buildUUID); // Get a timestamp to complete the index build in the absence of a createIndexBuild // oplog entry. repl::UnreplicatedWritesBlock uwb(opCtx); if (!IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(opCtx, collection->ns())) { - log() << "Did not timestamp index commit write."; + LOGV2(20672, "Did not timestamp index commit write."); } return; } @@ -1954,7 +2010,10 @@ StatusWith<std::pair<long long, long long>> IndexBuildsCoordinator::_runIndexReb indexCatalogStats.numIndexesBefore = getNumIndexesTotal(opCtx, collection); try { - log() << "Index builds manager starting: " << buildUUID << ": " << nss; + LOGV2(20673, + "Index builds manager starting: {buildUUID}: {nss}", + "buildUUID"_attr = buildUUID, + "nss"_attr = nss); std::tie(numRecords, dataSize) = uassertStatusOK(_indexBuildsManager.startBuildingIndexForRecovery( @@ -1973,14 +2032,24 @@ StatusWith<std::pair<long long, long long>> IndexBuildsCoordinator::_runIndexReb indexCatalogStats.numIndexesAfter = getNumIndexesTotal(opCtx, collection); - log() << "Index builds manager completed successfully: " << buildUUID << ": " << nss - << ". Index specs requested: " << replState->indexSpecs.size() - << ". Indexes in catalog before build: " << indexCatalogStats.numIndexesBefore - << ". Indexes in catalog after build: " << indexCatalogStats.numIndexesAfter; + LOGV2(20674, + "Index builds manager completed successfully: {buildUUID}: {nss}. Index specs " + "requested: {replState_indexSpecs_size}. Indexes in catalog before build: " + "{indexCatalogStats_numIndexesBefore}. Indexes in catalog after build: " + "{indexCatalogStats_numIndexesAfter}", + "buildUUID"_attr = buildUUID, + "nss"_attr = nss, + "replState_indexSpecs_size"_attr = replState->indexSpecs.size(), + "indexCatalogStats_numIndexesBefore"_attr = indexCatalogStats.numIndexesBefore, + "indexCatalogStats_numIndexesAfter"_attr = indexCatalogStats.numIndexesAfter); } catch (const DBException& ex) { status = ex.toStatus(); invariant(status != ErrorCodes::IndexAlreadyExists); - log() << "Index builds manager failed: " << buildUUID << ": " << nss << ": " << status; + LOGV2(20675, + "Index builds manager failed: {buildUUID}: {nss}: {status}", + "buildUUID"_attr = buildUUID, + "nss"_attr = nss, + "status"_attr = status); } // Index build is registered in manager regardless of IndexBuildsManager::setUpIndexBuild() diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp index 2d262167793..db4f894e815 100644 --- a/src/mongo/db/initialize_server_global_state.cpp +++ b/src/mongo/db/initialize_server_global_state.cpp @@ -58,6 +58,7 @@ #include "mongo/logger/rotatable_file_manager.h" #include "mongo/logger/rotatable_file_writer.h" #include "mongo/logger/syslog_appender.h" +#include "mongo/logv2/log.h" #include "mongo/logv2/log_domain_global.h" #include "mongo/platform/process_id.h" #include "mongo/util/log.h" @@ -287,8 +288,10 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection, boost::system::error_code ec; boost::filesystem::rename(absoluteLogpath, renameTarget, ec); if (!ec) { - log() << "log file \"" << absoluteLogpath << "\" exists; moved to \"" - << renameTarget << "\"."; + LOGV2(20697, + "log file \"{absoluteLogpath}\" exists; moved to \"{renameTarget}\".", + "absoluteLogpath"_attr = absoluteLogpath, + "renameTarget"_attr = renameTarget); } else { return Status(ErrorCodes::FileRenameFailed, str::stream() @@ -321,7 +324,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection, : logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kTruncate; if (serverGlobalParams.logAppend && exists) { - log() << "***** SERVER RESTARTED *****"; + LOGV2(20698, "***** SERVER RESTARTED *****"); // FIXME rewrite for logv2 // Status status = logger::RotatableFileWriter::Use(writer.getValue()).status(); // if (!status.isOK()) @@ -339,7 +342,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection, javascriptAppender = std::make_unique<RotatableFileAppender<MessageEventEphemeral>>( std::make_unique<MessageEventDetailsEncoder>(), writer.getValue()); if (serverGlobalParams.logAppend && exists) { - log() << "***** SERVER RESTARTED *****"; + LOGV2(20699, "***** SERVER RESTARTED *****"); Status status = logger::RotatableFileWriter::Use(writer.getValue()).status(); if (!status.isOK()) return status; diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index 82993e676c9..87819671ad4 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -42,6 +42,7 @@ #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/client_metadata.h" #include "mongo/rpc/metadata/client_metadata_ismaster.h" #include "mongo/util/log.h" @@ -159,8 +160,9 @@ void profile(OperationContext* opCtx, NetworkOp op) { Database* const db = autoGetDb->getDb(); if (!db) { // Database disappeared - log() << "note: not profiling because db went away for " - << CurOp::get(opCtx)->getNS(); + LOGV2(20700, + "note: not profiling because db went away for {CurOp_get_opCtx_getNS}", + "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS()); break; } @@ -201,14 +203,21 @@ void profile(OperationContext* opCtx, NetworkOp op) { } } catch (const AssertionException& assertionEx) { if (acquireDbXLock && ErrorCodes::isInterruption(assertionEx)) { - warning() - << "Interrupted while attempting to create profile collection in database " - << dbName << " to profile operation " << networkOpToString(op) << " against " - << CurOp::get(opCtx)->getNS() - << ". Manually create profile collection to ensure future operations are logged."; + LOGV2_WARNING( + 20702, + "Interrupted while attempting to create profile collection in database {dbName} to " + "profile operation {networkOpToString_op} against {CurOp_get_opCtx_getNS}. " + "Manually create profile collection to ensure future operations are logged.", + "dbName"_attr = dbName, + "networkOpToString_op"_attr = networkOpToString(op), + "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS()); } else { - warning() << "Caught Assertion while trying to profile " << networkOpToString(op) - << " against " << CurOp::get(opCtx)->getNS() << ": " << redact(assertionEx); + LOGV2_WARNING(20703, + "Caught Assertion while trying to profile {networkOpToString_op} against " + "{CurOp_get_opCtx_getNS}: {assertionEx}", + "networkOpToString_op"_attr = networkOpToString(op), + "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS(), + "assertionEx"_attr = redact(assertionEx)); } } } @@ -231,7 +240,9 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) { } // system.profile namespace doesn't exist; create it - log() << "Creating profile collection: " << dbProfilingNS; + LOGV2(20701, + "Creating profile collection: {dbProfilingNS}", + "dbProfilingNS"_attr = dbProfilingNS); CollectionOptions collectionOptions; collectionOptions.capped = true; diff --git a/src/mongo/db/keys_collection_client_direct.cpp b/src/mongo/db/keys_collection_client_direct.cpp index 861440f7707..817b380ec41 100644 --- a/src/mongo/db/keys_collection_client_direct.cpp +++ b/src/mongo/db/keys_collection_client_direct.cpp @@ -45,6 +45,7 @@ #include "mongo/db/logical_time.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/sharding_catalog_client.h" #include "mongo/s/write_ops/batched_command_request.h" @@ -158,9 +159,12 @@ Status KeysCollectionClientDirect::_insert(OperationContext* opCtx, Shard::CommandResponse::processBatchWriteResponse(swResponse, &batchResponse); if (retry < kOnErrorNumRetries && isRetriableError(writeStatus.code(), Shard::RetryPolicy::kIdempotent)) { - LOG(2) << "Batch write command to " << nss.db() - << "failed with retriable error and will be retried" - << causedBy(redact(writeStatus)); + LOGV2_DEBUG(20704, + 2, + "Batch write command to {nss_db}failed with retriable error and will be " + "retried{causedBy_writeStatus}", + "nss_db"_attr = nss.db(), + "causedBy_writeStatus"_attr = causedBy(redact(writeStatus))); continue; } diff --git a/src/mongo/db/keys_collection_manager.cpp b/src/mongo/db/keys_collection_manager.cpp index 91e8bd8f4a4..a921df95c59 100644 --- a/src/mongo/db/keys_collection_manager.cpp +++ b/src/mongo/db/keys_collection_manager.cpp @@ -41,6 +41,7 @@ #include "mongo/db/logical_time.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -293,7 +294,7 @@ void KeysCollectionManager::PeriodicRunner::_doPeriodicRefresh(ServiceContext* s return _inShutdown || _refreshRequest; }); } catch (const DBException& e) { - LOG(1) << "Unable to wait for refresh request due to: " << e; + LOGV2_DEBUG(20705, 1, "Unable to wait for refresh request due to: {e}", "e"_attr = e); if (ErrorCodes::isShutdownError(e)) { return; diff --git a/src/mongo/db/kill_sessions_common.cpp b/src/mongo/db/kill_sessions_common.cpp index 7a3f93e9d3c..fd31d2f1438 100644 --- a/src/mongo/db/kill_sessions_common.cpp +++ b/src/mongo/db/kill_sessions_common.cpp @@ -37,6 +37,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/session_killer.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -56,8 +57,10 @@ SessionKiller::Result killSessionsLocalKillOps(OperationContext* opCtx, if (const KillAllSessionsByPattern* pattern = matcher.match(*lsid)) { ScopedKillAllSessionsByPatternImpersonator impersonator(opCtx, *pattern); - log() << "killing op: " << opCtxToKill->getOpID() - << " as part of killing session: " << lsid->toBSON(); + LOGV2(20706, + "killing op: {opCtxToKill_getOpID} as part of killing session: {lsid}", + "opCtxToKill_getOpID"_attr = opCtxToKill->getOpID(), + "lsid"_attr = lsid->toBSON()); opCtx->getServiceContext()->killOperation(lk, opCtxToKill); } diff --git a/src/mongo/db/kill_sessions_local.cpp b/src/mongo/db/kill_sessions_local.cpp index eb708bb97f8..91da0862ab0 100644 --- a/src/mongo/db/kill_sessions_local.cpp +++ b/src/mongo/db/kill_sessions_local.cpp @@ -40,6 +40,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/session_catalog.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -118,31 +119,34 @@ SessionKiller::Result killSessionsLocal(OperationContext* opCtx, void killAllExpiredTransactions(OperationContext* opCtx) { SessionKiller::Matcher matcherAllSessions( KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}); - killSessionsAction(opCtx, - matcherAllSessions, - [when = opCtx->getServiceContext()->getPreciseClockSource()->now()]( - const ObservableSession& session) { - return TransactionParticipant::get(session).expiredAsOf(when); - }, - [](OperationContext* opCtx, const SessionToKill& session) { - auto txnParticipant = TransactionParticipant::get(session); - // If the transaction is aborted here, it means it was aborted after - // the filter. The most likely reason for this is that the transaction - // was active and the session kill aborted it. We still want to log - // that as aborted due to transactionLifetimeLimitSessions. - if (txnParticipant.transactionIsInProgress() || - txnParticipant.transactionIsAborted()) { - log() << "Aborting transaction with txnNumber " - << txnParticipant.getActiveTxnNumber() << " on session " - << session.getSessionId().getId() - << " because it has been running for longer than " - "'transactionLifetimeLimitSeconds'"; - if (txnParticipant.transactionIsInProgress()) { - txnParticipant.abortTransaction(opCtx); - } - } - }, - ErrorCodes::TransactionExceededLifetimeLimitSeconds); + killSessionsAction( + opCtx, + matcherAllSessions, + [when = opCtx->getServiceContext()->getPreciseClockSource()->now()]( + const ObservableSession& session) { + return TransactionParticipant::get(session).expiredAsOf(when); + }, + [](OperationContext* opCtx, const SessionToKill& session) { + auto txnParticipant = TransactionParticipant::get(session); + // If the transaction is aborted here, it means it was aborted after + // the filter. The most likely reason for this is that the transaction + // was active and the session kill aborted it. We still want to log + // that as aborted due to transactionLifetimeLimitSessions. + if (txnParticipant.transactionIsInProgress() || txnParticipant.transactionIsAborted()) { + LOGV2(20707, + "Aborting transaction with txnNumber {txnParticipant_getActiveTxnNumber} on " + "session {session_getSessionId_getId} because it has been running for longer " + "than " + "'transactionLifetimeLimitSeconds'", + "txnParticipant_getActiveTxnNumber"_attr = + txnParticipant.getActiveTxnNumber(), + "session_getSessionId_getId"_attr = session.getSessionId().getId()); + if (txnParticipant.transactionIsInProgress()) { + txnParticipant.abortTransaction(opCtx); + } + } + }, + ErrorCodes::TransactionExceededLifetimeLimitSeconds); } void killSessionsLocalShutdownAllTransactions(OperationContext* opCtx) { @@ -189,29 +193,34 @@ void yieldLocksForPreparedTransactions(OperationContext* opCtx) { // to yield their locks. SessionKiller::Matcher matcherAllSessions( KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(newOpCtx.get())}); - killSessionsAction(newOpCtx.get(), - matcherAllSessions, - [](const ObservableSession& session) { - return TransactionParticipant::get(session).transactionIsPrepared(); - }, - [](OperationContext* killerOpCtx, const SessionToKill& session) { - auto txnParticipant = TransactionParticipant::get(session); - // Yield locks for prepared transactions. - // When scanning and killing operations, all prepared transactions are - // included in the - // list. Even though new sessions may be created after the scan, none of - // them can become - // prepared during stepdown, since the RSTL has been enqueued, preventing - // any new - // writes. - if (txnParticipant.transactionIsPrepared()) { - LOG(3) << "Yielding locks of prepared transaction. SessionId: " - << session.getSessionId().getId() - << " TxnNumber: " << txnParticipant.getActiveTxnNumber(); - txnParticipant.refreshLocksForPreparedTransaction(killerOpCtx, true); - } - }, - ErrorCodes::InterruptedDueToReplStateChange); + killSessionsAction( + newOpCtx.get(), + matcherAllSessions, + [](const ObservableSession& session) { + return TransactionParticipant::get(session).transactionIsPrepared(); + }, + [](OperationContext* killerOpCtx, const SessionToKill& session) { + auto txnParticipant = TransactionParticipant::get(session); + // Yield locks for prepared transactions. + // When scanning and killing operations, all prepared transactions are + // included in the + // list. Even though new sessions may be created after the scan, none of + // them can become + // prepared during stepdown, since the RSTL has been enqueued, preventing + // any new + // writes. + if (txnParticipant.transactionIsPrepared()) { + LOGV2_DEBUG( + 20708, + 3, + "Yielding locks of prepared transaction. SessionId: " + "{session_getSessionId_getId} TxnNumber: {txnParticipant_getActiveTxnNumber}", + "session_getSessionId_getId"_attr = session.getSessionId().getId(), + "txnParticipant_getActiveTxnNumber"_attr = txnParticipant.getActiveTxnNumber()); + txnParticipant.refreshLocksForPreparedTransaction(killerOpCtx, true); + } + }, + ErrorCodes::InterruptedDueToReplStateChange); } } // namespace mongo diff --git a/src/mongo/db/log_process_details.cpp b/src/mongo/db/log_process_details.cpp index 9e30fc04822..140f0f51495 100644 --- a/src/mongo/db/log_process_details.cpp +++ b/src/mongo/db/log_process_details.cpp @@ -51,7 +51,7 @@ bool is32bit() { void logProcessDetails() { auto&& vii = VersionInfoInterface::instance(); - log() << mongodVersion(vii); + LOGV2(20719, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii)); vii.logBuildInfo(); ProcessInfo p; @@ -61,17 +61,24 @@ void logProcessDetails() { "version"_attr = p.getOsVersion()); if (ProcessInfo::getMemSizeMB() < ProcessInfo::getSystemMemSizeMB()) { - log() << ProcessInfo::getMemSizeMB() << " MB of memory available to the process out of " - << ProcessInfo::getSystemMemSizeMB() << " MB total system memory"; + LOGV2(20720, + "{ProcessInfo_getMemSizeMB} MB of memory available to the process out of " + "{ProcessInfo_getSystemMemSizeMB} MB total system memory", + "ProcessInfo_getMemSizeMB"_attr = ProcessInfo::getMemSizeMB(), + "ProcessInfo_getSystemMemSizeMB"_attr = ProcessInfo::getSystemMemSizeMB()); } printCommandLineOpts(); } void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { - log() << "pid=" << ProcessId::getCurrent() << " port=" << serverGlobalParams.port - << (is32bit() ? " 32" : " 64") << "-bit " - << "host=" << getHostNameCached(); + LOGV2(20721, + "pid={ProcessId_getCurrent} port={serverGlobalParams_port}{is32bit_32_64}-bit " + "host={getHostNameCached}", + "ProcessId_getCurrent"_attr = ProcessId::getCurrent(), + "serverGlobalParams_port"_attr = serverGlobalParams.port, + "is32bit_32_64"_attr = (is32bit() ? " 32" : " 64"), + "getHostNameCached"_attr = getHostNameCached()); auto replCoord = repl::ReplicationCoordinator::get(serviceContext); if (replCoord != nullptr && @@ -79,10 +86,12 @@ void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { auto rsConfig = replCoord->getConfig(); if (rsConfig.isInitialized()) { - log() << "Replica Set Config: " << rsConfig.toBSON(); - log() << "Replica Set Member State: " << (replCoord->getMemberState()).toString(); + LOGV2(20722, "Replica Set Config: {rsConfig}", "rsConfig"_attr = rsConfig.toBSON()); + LOGV2(20723, + "Replica Set Member State: {replCoord_getMemberState}", + "replCoord_getMemberState"_attr = (replCoord->getMemberState()).toString()); } else { - log() << "Node currently has no Replica Set Config."; + LOGV2(20724, "Node currently has no Replica Set Config."); } } diff --git a/src/mongo/db/logical_clock.cpp b/src/mongo/db/logical_clock.cpp index 6dea3e7acdc..cb785c29ec5 100644 --- a/src/mongo/db/logical_clock.cpp +++ b/src/mongo/db/logical_clock.cpp @@ -39,6 +39,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/time_proof_service.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -122,8 +123,9 @@ LogicalTime LogicalClock::reserveTicks(uint64_t nTicks) { // second. else if (clusterTime.asTimestamp().getInc() > (kMaxSignedInt - nTicks)) { - log() << "Exceeded maximum allowable increment value within one second. Moving clusterTime " - "forward to the next second."; + LOGV2(20709, + "Exceeded maximum allowable increment value within one second. Moving clusterTime " + "forward to the next second."); // Move time forward to the next second clusterTime = LogicalTime(Timestamp(clusterTime.asTimestamp().getSecs() + 1, 0)); diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp index eae770cfecc..f3c162006b2 100644 --- a/src/mongo/db/logical_session_cache_impl.cpp +++ b/src/mongo/db/logical_session_cache_impl.cpp @@ -38,6 +38,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/platform/atomic_word.h" #include "mongo/util/duration.h" #include "mongo/util/log.h" @@ -124,15 +125,17 @@ void LogicalSessionCacheImpl::_periodicRefresh(Client* client) { try { _refresh(client); } catch (...) { - log() << "Failed to refresh session cache: " << exceptionToStatus() - << ", will try again at the next refresh interval"; + LOGV2(20710, + "Failed to refresh session cache: {exceptionToStatus}, will try again at the next " + "refresh interval", + "exceptionToStatus"_attr = exceptionToStatus()); } } void LogicalSessionCacheImpl::_periodicReap(Client* client) { auto res = _reap(client); if (!res.isOK()) { - log() << "Failed to reap transaction table: " << res; + LOGV2(20711, "Failed to reap transaction table: {res}", "res"_attr = res); } return; @@ -174,9 +177,12 @@ Status LogicalSessionCacheImpl::_reap(Client* client) { "waiting until next sessions reap interval"; if (ex.code() != ErrorCodes::NamespaceNotFound || ex.code() != ErrorCodes::NamespaceNotSharded) { - log() << notSetUpWarning << ": " << ex.reason(); + LOGV2(20712, + "{notSetUpWarning}: {ex_reason}", + "notSetUpWarning"_attr = notSetUpWarning, + "ex_reason"_attr = ex.reason()); } else { - log() << notSetUpWarning; + LOGV2(20713, "{notSetUpWarning}", "notSetUpWarning"_attr = notSetUpWarning); } return Status::OK(); } @@ -243,8 +249,10 @@ void LogicalSessionCacheImpl::_refresh(Client* client) { try { _sessionsColl->setupSessionsCollection(opCtx); } catch (const DBException& ex) { - log() << "Failed to refresh session cache, will try again at the next refresh interval" - << causedBy(redact(ex)); + LOGV2(20714, + "Failed to refresh session cache, will try again at the next refresh " + "interval{causedBy_ex}", + "causedBy_ex"_attr = causedBy(redact(ex))); return; } @@ -374,7 +382,10 @@ Status LogicalSessionCacheImpl::_addToCacheIfNotFull(WithLock, LogicalSessionRec "high"}; auto severity = MONGO_GET_LIMITED_SEVERITY(ErrorCodes::TooManyLogicalSessions, Seconds{1}, 0, 2); - LOG(severity) << status.toString(); + LOGV2_DEBUG(20715, + logSeverityV1toV2(severity).toInt(), + "{status}", + "status"_attr = status.toString()); return status; } diff --git a/src/mongo/db/logical_time_validator.cpp b/src/mongo/db/logical_time_validator.cpp index 6d448f78a5f..0fa0b55cfc5 100644 --- a/src/mongo/db/logical_time_validator.cpp +++ b/src/mongo/db/logical_time_validator.cpp @@ -42,6 +42,7 @@ #include "mongo/db/logical_clock.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -195,7 +196,7 @@ bool LogicalTimeValidator::shouldGossipLogicalTime() { } void LogicalTimeValidator::resetKeyManagerCache() { - log() << "Resetting key manager cache"; + LOGV2(20716, "Resetting key manager cache"); invariant(_keyManager); _keyManager->clearCache(); stdx::lock_guard<Latch> lk(_mutex); @@ -205,7 +206,7 @@ void LogicalTimeValidator::resetKeyManagerCache() { void LogicalTimeValidator::stopKeyManager() { if (_keyManager) { - log() << "Stopping key manager"; + LOGV2(20717, "Stopping key manager"); _keyManager->stopMonitoring(); _keyManager->clearCache(); @@ -213,7 +214,7 @@ void LogicalTimeValidator::stopKeyManager() { _lastSeenValidTime = SignedLogicalTime(); _timeProofService.resetCache(); } else { - log() << "Stopping key manager: no key manager exists."; + LOGV2(20718, "Stopping key manager: no key manager exists."); } } diff --git a/src/mongo/db/matcher/rewrite_expr.cpp b/src/mongo/db/matcher/rewrite_expr.cpp index 01e5a6e51c5..31dfcfd51ee 100644 --- a/src/mongo/db/matcher/rewrite_expr.cpp +++ b/src/mongo/db/matcher/rewrite_expr.cpp @@ -36,6 +36,7 @@ #include "mongo/db/matcher/expression_internal_expr_eq.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_tree.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -44,16 +45,25 @@ using CmpOp = ExpressionCompare::CmpOp; RewriteExpr::RewriteResult RewriteExpr::rewrite(const boost::intrusive_ptr<Expression>& expression, const CollatorInterface* collator) { - LOG(5) << "Expression prior to rewrite: " << expression->serialize(false); + LOGV2_DEBUG(20725, + 5, + "Expression prior to rewrite: {expression_serialize_false}", + "expression_serialize_false"_attr = expression->serialize(false)); RewriteExpr rewriteExpr(collator); std::unique_ptr<MatchExpression> matchExpression; if (auto matchTree = rewriteExpr._rewriteExpression(expression)) { matchExpression = std::move(matchTree); - LOG(5) << "Post-rewrite MatchExpression: " << matchExpression->debugString(); + LOGV2_DEBUG(20726, + 5, + "Post-rewrite MatchExpression: {matchExpression_debugString}", + "matchExpression_debugString"_attr = matchExpression->debugString()); matchExpression = MatchExpression::optimize(std::move(matchExpression)); - LOG(5) << "Post-rewrite/post-optimized MatchExpression: " << matchExpression->debugString(); + LOGV2_DEBUG(20727, + 5, + "Post-rewrite/post-optimized MatchExpression: {matchExpression_debugString}", + "matchExpression_debugString"_attr = matchExpression->debugString()); } return {std::move(matchExpression), std::move(rewriteExpr._matchExprElemStorage)}; diff --git a/src/mongo/db/matcher/schema/json_schema_parser.cpp b/src/mongo/db/matcher/schema/json_schema_parser.cpp index a8ad976b5da..005ddeab349 100644 --- a/src/mongo/db/matcher/schema/json_schema_parser.cpp +++ b/src/mongo/db/matcher/schema/json_schema_parser.cpp @@ -60,6 +60,7 @@ #include "mongo/db/matcher/schema/expression_internal_schema_xor.h" #include "mongo/db/matcher/schema/json_pointer.h" #include "mongo/logger/log_component_settings.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/string_map.h" @@ -1610,12 +1611,19 @@ StatusWithMatchExpression JSONSchemaParser::parse( const boost::intrusive_ptr<ExpressionContext>& expCtx, BSONObj schema, bool ignoreUnknownKeywords) { - LOG(5) << "Parsing JSON Schema: " << schema.jsonString(JsonStringFormat::LegacyStrict); + LOGV2_DEBUG(20728, + 5, + "Parsing JSON Schema: {schema_jsonString_JsonStringFormat_LegacyStrict}", + "schema_jsonString_JsonStringFormat_LegacyStrict"_attr = + schema.jsonString(JsonStringFormat::LegacyStrict)); try { auto translation = _parse(expCtx, ""_sd, schema, ignoreUnknownKeywords); if (shouldLog(logger::LogSeverity::Debug(5)) && translation.isOK()) { - LOG(5) << "Translated schema match expression: " - << translation.getValue()->debugString(); + LOGV2_DEBUG(20729, + 5, + "Translated schema match expression: {translation_getValue_debugString}", + "translation_getValue_debugString"_attr = + translation.getValue()->debugString()); } return translation; } catch (const DBException& ex) { diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 11a75108e9c..c841a794121 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -53,6 +53,7 @@ #include "mongo/db/server_options_base.h" #include "mongo/db/server_options_nongeneral_gen.h" #include "mongo/db/server_options_server_helpers.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/net/ssl_options.h" #include "mongo/util/options_parser/startup_options.h" @@ -101,13 +102,19 @@ void printMongodHelp(const moe::OptionSection& options) { namespace { void sysRuntimeInfo() { #if defined(_SC_PAGE_SIZE) - log() << " page size: " << (int)sysconf(_SC_PAGE_SIZE); + LOGV2(20873, + " page size: {int_sysconf_SC_PAGE_SIZE}", + "int_sysconf_SC_PAGE_SIZE"_attr = (int)sysconf(_SC_PAGE_SIZE)); #endif #if defined(_SC_PHYS_PAGES) - log() << " _SC_PHYS_PAGES: " << sysconf(_SC_PHYS_PAGES); + LOGV2(20874, + " _SC_PHYS_PAGES: {sysconf_SC_PHYS_PAGES}", + "sysconf_SC_PHYS_PAGES"_attr = sysconf(_SC_PHYS_PAGES)); #endif #if defined(_SC_AVPHYS_PAGES) - log() << " _SC_AVPHYS_PAGES: " << sysconf(_SC_AVPHYS_PAGES); + LOGV2(20875, + " _SC_AVPHYS_PAGES: {sysconf_SC_AVPHYS_PAGES}", + "sysconf_SC_AVPHYS_PAGES"_attr = sysconf(_SC_AVPHYS_PAGES)); #endif } } // namespace @@ -121,7 +128,7 @@ bool handlePreValidationMongodOptions(const moe::Environment& params, if (params.count("version") && params["version"].as<bool>() == true) { setPlainConsoleLogger(); auto&& vii = VersionInfoInterface::instance(); - log() << mongodVersion(vii); + LOGV2(20876, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii)); vii.logBuildInfo(); return false; } @@ -132,7 +139,7 @@ bool handlePreValidationMongodOptions(const moe::Environment& params, } if (params.count("master") || params.count("slave")) { - severe() << "Master/slave replication is no longer supported"; + LOGV2_FATAL(20881, "Master/slave replication is no longer supported"); return false; } @@ -572,10 +579,11 @@ Status storeMongodOptions(const moe::Environment& params) { if (params.count("replication.enableMajorityReadConcern") && !params["replication.enableMajorityReadConcern"].as<bool>()) { - warning() - << "Config servers require majority read concern, but it was explicitly " - "disabled. The override is being ignored and the process is continuing " - "with majority read concern enabled."; + LOGV2_WARNING( + 20879, + "Config servers require majority read concern, but it was explicitly " + "disabled. The override is being ignored and the process is continuing " + "with majority read concern enabled."); } serverGlobalParams.enableMajorityReadConcern = true; @@ -630,10 +638,11 @@ Status storeMongodOptions(const moe::Environment& params) { // Check if we are 32 bit and have not explicitly specified any journaling options if (sizeof(void*) == 4 && !params.count("storage.journal.enabled")) { // trying to make this stand out more like startup warnings - log() << endl; - warning() << "32-bit servers don't have journaling enabled by default. " - << "Please use --journal if you want durability."; - log() << endl; + LOGV2(20877, ""); + LOGV2_WARNING(20880, + "32-bit servers don't have journaling enabled by default. Please use " + "--journal if you want durability."); + LOGV2(20878, ""); } bool isClusterRoleShard = params.count("shardsvr"); diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp index 282612c54c8..1e1858d812b 100644 --- a/src/mongo/db/operation_context.cpp +++ b/src/mongo/db/operation_context.cpp @@ -36,6 +36,7 @@ #include "mongo/db/client.h" #include "mongo/db/operation_key_manager.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/platform/random.h" #include "mongo/transport/baton.h" @@ -223,7 +224,9 @@ Status OperationContext::checkForInterruptNoAssert() noexcept { checkForInterruptFail.executeIf( [&](auto&&) { - log() << "set pending kill on op " << getOpID() << ", for checkForInterruptFail"; + LOGV2(20882, + "set pending kill on op {getOpID}, for checkForInterruptFail", + "getOpID"_attr = getOpID()); markKilled(); }, [&](auto&& data) { return opShouldFail(getClient(), data); }); @@ -324,7 +327,7 @@ void OperationContext::markKilled(ErrorCodes::Error killCode) { invariant(!ErrorExtraInfo::parserFor(killCode)); if (killCode == ErrorCodes::ClientDisconnect) { - log() << "operation was interrupted because a client disconnected"; + LOGV2(20883, "operation was interrupted because a client disconnected"); } if (auto status = ErrorCodes::OK; _killCode.compareAndSwap(&status, killCode)) { diff --git a/src/mongo/db/operation_killer.cpp b/src/mongo/db/operation_killer.cpp index 742a9d142e3..e6546e6c246 100644 --- a/src/mongo/db/operation_killer.cpp +++ b/src/mongo/db/operation_killer.cpp @@ -37,6 +37,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/client.h" #include "mongo/db/operation_key_manager.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -82,7 +83,7 @@ void OperationKiller::killOperation(OperationId opId) { serviceContext->killOperation(target, target->getOperationContext()); - log() << "Killed operation: " << opId; + LOGV2(20884, "Killed operation: {opId}", "opId"_attr = opId); } void OperationKiller::killOperation(const OperationKey& opKey) { diff --git a/src/mongo/db/ops/update_result.cpp b/src/mongo/db/ops/update_result.cpp index 8765dd1dde1..e5276be908a 100644 --- a/src/mongo/db/ops/update_result.cpp +++ b/src/mongo/db/ops/update_result.cpp @@ -35,6 +35,7 @@ #include "mongo/db/ops/update_result.h" #include "mongo/db/lasterror.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -53,7 +54,7 @@ UpdateResult::UpdateResult(bool existing_, if (!existing && numMatched == 0 && !id.eoo()) { upserted = id.wrap(kUpsertedFieldName); } - LOG(4) << "UpdateResult -- " << redact(toString()); + LOGV2_DEBUG(20885, 4, "UpdateResult -- {}", ""_attr = redact(toString())); } std::string UpdateResult::toString() const { diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp index 196fb827e86..0518b6dd75e 100644 --- a/src/mongo/db/ops/write_ops_exec.cpp +++ b/src/mongo/db/ops/write_ops_exec.cpp @@ -74,6 +74,7 @@ #include "mongo/db/storage/duplicate_key_error_info.h" #include "mongo/db/transaction_participant.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/would_change_owning_shard_exception.h" @@ -128,8 +129,13 @@ void finishCurOp(OperationContext* opCtx, CurOp* curOp) { curOp->getReadWriteType()); if (!curOp->debug().errInfo.isOK()) { - LOG(3) << "Caught Assertion in " << redact(logicalOpToString(curOp->getLogicalOp())) - << ": " << curOp->debug().errInfo.toString(); + LOGV2_DEBUG( + 20886, + 3, + "Caught Assertion in {logicalOpToString_curOp_getLogicalOp}: {curOp_debug_errInfo}", + "logicalOpToString_curOp_getLogicalOp"_attr = + redact(logicalOpToString(curOp->getLogicalOp())), + "curOp_debug_errInfo"_attr = curOp->debug().errInfo.toString()); } // Mark the op as complete, and log it if appropriate. Returns a boolean indicating whether @@ -147,7 +153,7 @@ void finishCurOp(OperationContext* opCtx, CurOp* curOp) { // We need to ignore all errors here. We don't want a successful op to fail because of a // failure to record stats. We also don't want to replace the error reported for an op that // is failing. - log() << "Ignoring error from finishCurOp: " << redact(ex); + LOGV2(20887, "Ignoring error from finishCurOp: {ex}", "ex"_attr = redact(ex)); } } @@ -168,7 +174,11 @@ public: // guard to fire in that case. Operations on the local DB aren't replicated, so they // don't need to bump the lastOp. replClientInfo().setLastOpToSystemLastOpTimeIgnoringInterrupt(_opCtx); - LOG(5) << "Set last op to system time: " << replClientInfo().getLastOp().getTimestamp(); + LOGV2_DEBUG(20888, + 5, + "Set last op to system time: {replClientInfo_getLastOp_getTimestamp}", + "replClientInfo_getLastOp_getTimestamp"_attr = + replClientInfo().getLastOp().getTimestamp()); } } @@ -375,10 +385,11 @@ bool insertBatchAndHandleErrors(OperationContext* opCtx, opCtx, "hangDuringBatchInsert", [&wholeOp]() { - log() << "batch insert - hangDuringBatchInsert fail point enabled for namespace " - << wholeOp.getNamespace() - << ". Blocking " - "until fail point is disabled."; + LOGV2(20889, + "batch insert - hangDuringBatchInsert fail point enabled for namespace " + "{wholeOp_getNamespace}. Blocking " + "until fail point is disabled.", + "wholeOp_getNamespace"_attr = wholeOp.getNamespace()); }, true, // Check for interrupt periodically. wholeOp.getNamespace()); @@ -609,9 +620,11 @@ static SingleWriteResult performSingleUpdateOp(OperationContext* opCtx, opCtx, "hangDuringBatchUpdate", [&ns]() { - log() << "batch update - hangDuringBatchUpdate fail point enabled for nss " << ns - << ". Blocking until " - "fail point is disabled."; + LOGV2(20890, + "batch update - hangDuringBatchUpdate fail point enabled for nss {ns}. Blocking " + "until " + "fail point is disabled.", + "ns"_attr = ns); }, false /*checkForInterrupt*/, ns); @@ -862,8 +875,9 @@ static SingleWriteResult performSingleDeleteOp(OperationContext* opCtx, opCtx, "hangDuringBatchRemove", []() { - log() << "batch remove - hangDuringBatchRemove fail point enabled. Blocking " - "until fail point is disabled."; + LOGV2(20891, + "batch remove - hangDuringBatchRemove fail point enabled. Blocking " + "until fail point is disabled."); }, true // Check for interrupt periodically. ); diff --git a/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp b/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp index 12d931edc4c..975a225a7fd 100644 --- a/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp +++ b/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp @@ -38,6 +38,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/transaction_participant.h" #include "mongo/db/transaction_participant_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/periodic_runner.h" @@ -108,15 +109,18 @@ void PeriodicThreadToAbortExpiredTransactions::_init(ServiceContext* serviceCont _anchor = std::make_shared<PeriodicJobAnchor>(periodicRunner->makeJob(std::move(job))); - TransactionParticipant::observeTransactionLifetimeLimitSeconds.addObserver( - [anchor = _anchor](const Argument& secs) { - try { - anchor->setPeriod(getPeriod(secs)); - } catch (const DBException& ex) { - log() << "Failed to update period of thread which aborts expired transactions " - << ex.toStatus(); - } - }); + TransactionParticipant::observeTransactionLifetimeLimitSeconds.addObserver([anchor = _anchor]( + const Argument& + secs) { + try { + anchor->setPeriod(getPeriod(secs)); + } catch (const DBException& ex) { + LOGV2( + 20892, + "Failed to update period of thread which aborts expired transactions {ex_toStatus}", + "ex_toStatus"_attr = ex.toStatus()); + } + }); } } // namespace mongo diff --git a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp index 3f9010eb08d..5d99a62f91b 100644 --- a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp +++ b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp @@ -38,6 +38,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/snapshot_window_options.h" #include "mongo/db/snapshot_window_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/periodic_runner.h" @@ -82,9 +83,11 @@ void PeriodicThreadToDecreaseSnapshotHistoryCachePressure::_init(ServiceContext* SnapshotWindowUtil::decreaseTargetSnapshotWindowSize(opCtx.get()); } catch (const DBException& ex) { if (!ErrorCodes::isShutdownError(ex.toStatus().code())) { - warning() << "Periodic task to check for and decrease cache pressure caused by " - "maintaining too much snapshot history failed! Caused by: " - << ex.toStatus(); + LOGV2_WARNING( + 20894, + "Periodic task to check for and decrease cache pressure caused by " + "maintaining too much snapshot history failed! Caused by: {ex_toStatus}", + "ex_toStatus"_attr = ex.toStatus()); } } }, @@ -97,9 +100,10 @@ void PeriodicThreadToDecreaseSnapshotHistoryCachePressure::_init(ServiceContext* try { anchor->setPeriod(Seconds(secs)); } catch (const DBException& ex) { - log() << "Failed to update the period of the thread which decreases data history cache " - "target size if there is cache pressure." - << ex.toStatus(); + LOGV2(20893, + "Failed to update the period of the thread which decreases data history cache " + "target size if there is cache pressure.{ex_toStatus}", + "ex_toStatus"_attr = ex.toStatus()); } }); } diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp index bf576960b20..ef90138a584 100644 --- a/src/mongo/db/pipeline/document_source_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_cursor.cpp @@ -40,6 +40,7 @@ #include "mongo/db/query/explain.h" #include "mongo/db/query/find_common.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -80,7 +81,8 @@ void DocumentSourceCursor::loadBatch() { } while (MONGO_unlikely(hangBeforeDocumentSourceCursorLoadBatch.shouldFail())) { - log() << "Hanging aggregation due to 'hangBeforeDocumentSourceCursorLoadBatch' failpoint"; + LOGV2(20895, + "Hanging aggregation due to 'hangBeforeDocumentSourceCursorLoadBatch' failpoint"); sleepmillis(10); } diff --git a/src/mongo/db/pipeline/document_source_exchange.cpp b/src/mongo/db/pipeline/document_source_exchange.cpp index 9e8e37e97cd..8c7b990ba78 100644 --- a/src/mongo/db/pipeline/document_source_exchange.cpp +++ b/src/mongo/db/pipeline/document_source_exchange.cpp @@ -39,6 +39,7 @@ #include "mongo/db/hasher.h" #include "mongo/db/pipeline/document_source_exchange.h" #include "mongo/db/storage/key_string.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -302,7 +303,8 @@ DocumentSource::GetNextResult Exchange::getNext(OperationContext* opCtx, // There is not any document so try to load more from the source. if (_loadingThreadId == kInvalidThreadId) { - LOG(3) << "A consumer " << consumerId << " begins loading"; + LOGV2_DEBUG( + 20896, 3, "A consumer {consumerId} begins loading", "consumerId"_attr = consumerId); try { // This consumer won the race and will fill the buffers. @@ -316,7 +318,7 @@ DocumentSource::GetNextResult Exchange::getNext(OperationContext* opCtx, size_t fullConsumerId = loadNextBatch(); if (MONGO_unlikely(exchangeFailLoadNextBatch.shouldFail())) { - log() << "exchangeFailLoadNextBatch fail point enabled."; + LOGV2(20897, "exchangeFailLoadNextBatch fail point enabled."); uasserted(ErrorCodes::FailPointEnabled, "Asserting on loading the next batch due to failpoint."); } diff --git a/src/mongo/db/pipeline/document_source_exchange_test.cpp b/src/mongo/db/pipeline/document_source_exchange_test.cpp index 65ab3f8b4a4..539cbc5cef9 100644 --- a/src/mongo/db/pipeline/document_source_exchange_test.cpp +++ b/src/mongo/db/pipeline/document_source_exchange_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/hasher.h" @@ -36,11 +38,13 @@ #include "mongo/db/storage/key_string.h" #include "mongo/executor/network_interface_factory.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/platform/random.h" #include "mongo/unittest/temp_dir.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" #include "mongo/util/concurrency/thread_pool.h" +#include "mongo/util/log.h" #include "mongo/util/system_clock_source.h" #include "mongo/util/time_support.h" @@ -117,7 +121,7 @@ protected: static auto getNewSeed() { auto seed = Date_t::now().asInt64(); - unittest::log() << "Generated new seed is " << seed; + LOGV2(20898, "Generated new seed is {seed}", "seed"_attr = seed); return seed; } diff --git a/src/mongo/db/pipeline/document_source_match_test.cpp b/src/mongo/db/pipeline/document_source_match_test.cpp index cb4821161fd..9873ba1c55b 100644 --- a/src/mongo/db/pipeline/document_source_match_test.cpp +++ b/src/mongo/db/pipeline/document_source_match_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <string> @@ -40,8 +42,10 @@ #include "mongo/db/pipeline/document_source_match.h" #include "mongo/db/pipeline/document_source_mock.h" #include "mongo/db/pipeline/pipeline.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace mongo { namespace { @@ -59,7 +63,7 @@ TEST_F(DocumentSourceMatchTest, RedactSafePortion) { auto match = DocumentSourceMatch::create(fromjson(input), expCtx); ASSERT_BSONOBJ_EQ(match->redactSafePortion(), fromjson(safePortion)); } catch (...) { - unittest::log() << "Problem with redactSafePortion() of: " << input; + LOGV2(20899, "Problem with redactSafePortion() of: {input}", "input"_attr = input); throw; } }; diff --git a/src/mongo/db/pipeline/document_source_merge.cpp b/src/mongo/db/pipeline/document_source_merge.cpp index bc3239eb726..ad68c53598c 100644 --- a/src/mongo/db/pipeline/document_source_merge.cpp +++ b/src/mongo/db/pipeline/document_source_merge.cpp @@ -40,6 +40,7 @@ #include "mongo/db/curop_failpoint_helpers.h" #include "mongo/db/ops/write_ops.h" #include "mongo/db/pipeline/document_path_support.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -487,8 +488,9 @@ void DocumentSourceMerge::waitWhileFailPointEnabled() { pExpCtx->opCtx, "hangWhileBuildingDocumentSourceMergeBatch", []() { - log() << "Hanging aggregation due to 'hangWhileBuildingDocumentSourceMergeBatch' " - << "failpoint"; + LOGV2( + 20900, + "Hanging aggregation due to 'hangWhileBuildingDocumentSourceMergeBatch' failpoint"); }); } diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 67df77f760c..93122dac504 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -39,6 +39,7 @@ #include "mongo/db/curop_failpoint_helpers.h" #include "mongo/db/ops/write_ops.h" #include "mongo/db/pipeline/document_path_support.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/destructor_guard.h" #include "mongo/util/fail_point.h" @@ -152,8 +153,8 @@ void DocumentSourceOut::initialize() { pExpCtx->opCtx, "outWaitAfterTempCollectionCreation", []() { - log() << "Hanging aggregation due to 'outWaitAfterTempCollectionCreation' " - << "failpoint"; + LOGV2(20901, + "Hanging aggregation due to 'outWaitAfterTempCollectionCreation' failpoint"); }); if (_originalIndexes.empty()) { return; @@ -245,8 +246,8 @@ void DocumentSourceOut::waitWhileFailPointEnabled() { pExpCtx->opCtx, "hangWhileBuildingDocumentSourceOutBatch", []() { - log() << "Hanging aggregation due to 'hangWhileBuildingDocumentSourceOutBatch' " - << "failpoint"; + LOGV2(20902, + "Hanging aggregation due to 'hangWhileBuildingDocumentSourceOutBatch' failpoint"); }); } diff --git a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp index 09e4b1fc148..64ca6cdf86b 100644 --- a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp @@ -40,6 +40,7 @@ #include "mongo/db/exec/document_value/value.h" #include "mongo/db/pipeline/expression.h" #include "mongo/db/pipeline/expression_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -121,8 +122,10 @@ DocumentSource::GetNextResult DocumentSourceSampleFromRandomCursor::getNextNonDu if (_seenDocs.insert(std::move(idField)).second) { return nextInput; } - LOG(1) << "$sample encountered duplicate document: " - << nextInput.getDocument().toString(); + LOGV2_DEBUG(20903, + 1, + "$sample encountered duplicate document: {nextInput_getDocument}", + "nextInput_getDocument"_attr = nextInput.getDocument().toString()); break; // Try again with the next document. } case GetNextResult::ReturnStatus::kPauseExecution: { diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp index d6d3569e5a8..e288214f60d 100644 --- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp +++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp @@ -49,6 +49,7 @@ #include "mongo/db/pipeline/lite_parsed_pipeline.h" #include "mongo/db/pipeline/semantic_analysis.h" #include "mongo/executor/task_executor_pool.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/query/cluster_query_knobs_gen.h" @@ -171,7 +172,10 @@ std::vector<RemoteCursor> establishShardCursors( const std::set<ShardId>& shardIds, const BSONObj& cmdObj, const ReadPreferenceSetting& readPref) { - LOG(1) << "Dispatching command " << redact(cmdObj) << " to establish cursors on shards"; + LOGV2_DEBUG(20904, + 1, + "Dispatching command {cmdObj} to establish cursors on shards", + "cmdObj"_attr = redact(cmdObj)); const bool mustRunOnAll = mustRunOnAllShards(nss, hasChangeStream); std::vector<std::pair<ShardId, BSONObj>> requests; @@ -204,8 +208,9 @@ std::vector<RemoteCursor> establishShardCursors( } if (MONGO_unlikely(shardedAggregateHangBeforeEstablishingShardCursors.shouldFail())) { - log() << "shardedAggregateHangBeforeEstablishingShardCursors fail point enabled. Blocking " - "until fail point is disabled."; + LOGV2(20905, + "shardedAggregateHangBeforeEstablishingShardCursors fail point enabled. Blocking " + "until fail point is disabled."); while (MONGO_unlikely(shardedAggregateHangBeforeEstablishingShardCursors.shouldFail())) { sleepsecs(1); } @@ -754,10 +759,13 @@ DispatchShardPipelineResults dispatchShardPipeline( boost::optional<SplitPipeline> splitPipelines; if (needsSplit) { - LOG(5) << "Splitting pipeline: " - << "targeting = " << shardIds.size() - << " shards, needsMongosMerge = " << needsMongosMerge - << ", needsPrimaryShardMerge = " << needsPrimaryShardMerge; + LOGV2_DEBUG(20906, + 5, + "Splitting pipeline: targeting = {shardIds_size} shards, needsMongosMerge = " + "{needsMongosMerge}, needsPrimaryShardMerge = {needsPrimaryShardMerge}", + "shardIds_size"_attr = shardIds.size(), + "needsMongosMerge"_attr = needsMongosMerge, + "needsPrimaryShardMerge"_attr = needsPrimaryShardMerge); splitPipelines = splitPipeline(std::move(pipeline)); exchangeSpec = checkIfEligibleForExchange(opCtx, splitPipelines->mergePipeline.get()); diff --git a/src/mongo/db/query/collection_query_info.cpp b/src/mongo/db/query/collection_query_info.cpp index 9d18d8175d9..2ff45ae8fe5 100644 --- a/src/mongo/db/query/collection_query_info.cpp +++ b/src/mongo/db/query/collection_query_info.cpp @@ -48,6 +48,7 @@ #include "mongo/db/query/plan_cache.h" #include "mongo/db/query/planner_ixselect.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/clock_source.h" #include "mongo/util/log.h" @@ -178,7 +179,10 @@ void CollectionQueryInfo::notifyOfQuery(OperationContext* opCtx, void CollectionQueryInfo::clearQueryCache() { const Collection* coll = get.owner(this); - LOG(1) << coll->ns() << ": clearing plan cache - collection info cache reset"; + LOGV2_DEBUG(20907, + 1, + "{coll_ns}: clearing plan cache - collection info cache reset", + "coll_ns"_attr = coll->ns()); if (nullptr != _planCache.get()) { _planCache->clear(); } diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index a87df84a6df..197475a9173 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -63,6 +63,7 @@ #include "mongo/db/stats/top.h" #include "mongo/db/storage/storage_options.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/s/chunk_version.h" #include "mongo/s/stale_exception.h" #include "mongo/util/fail_point.h" @@ -203,8 +204,10 @@ void generateBatch(int ntoreturn, switch (*state) { // Log an error message and then perform the cleanup. case PlanExecutor::FAILURE: { - error() << "getMore executor error, stats: " - << redact(Explain::getWinningPlanStats(exec)); + LOGV2_ERROR(20918, + "getMore executor error, stats: {Explain_getWinningPlanStats_exec}", + "Explain_getWinningPlanStats_exec"_attr = + redact(Explain::getWinningPlanStats(exec))); // We should always have a valid status object by this point. auto status = WorkingSetCommon::getMemberObjectStatus(doc); invariant(!status.isOK()); @@ -244,7 +247,7 @@ Message getMore(OperationContext* opCtx, bool* isCursorAuthorized) { invariant(ntoreturn >= 0); - LOG(5) << "Running getMore, cursorid: " << cursorid; + LOGV2_DEBUG(20909, 5, "Running getMore, cursorid: {cursorid}", "cursorid"_attr = cursorid); CurOp& curOp = *CurOp::get(opCtx); curOp.ensureStarted(); @@ -525,8 +528,11 @@ Message getMore(OperationContext* opCtx, cursorid = 0; curOp.debug().cursorExhausted = true; - LOG(5) << "getMore NOT saving client cursor, ended with state " - << PlanExecutor::statestr(state); + LOGV2_DEBUG( + 20910, + 5, + "getMore NOT saving client cursor, ended with state {PlanExecutor_statestr_state}", + "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state)); } else { cursorFreer.dismiss(); // Continue caching the ClientCursor. @@ -534,7 +540,10 @@ Message getMore(OperationContext* opCtx, cursorPin->incNBatches(); exec->saveState(); exec->detachFromOperationContext(); - LOG(5) << "getMore saving client cursor ended with state " << PlanExecutor::statestr(state); + LOGV2_DEBUG(20911, + 5, + "getMore saving client cursor ended with state {PlanExecutor_statestr_state}", + "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state)); // Set 'exhaust' if the client requested exhaust and the cursor is not exhausted. *exhaust = opCtx->isExhaust(); @@ -567,7 +576,8 @@ Message getMore(OperationContext* opCtx, qr.setCursorId(cursorid); qr.setStartingFrom(startingResult); qr.setNReturned(numResults); - LOG(5) << "getMore returned " << numResults << " results\n"; + LOGV2_DEBUG( + 20912, 5, "getMore returned {numResults} results\n", "numResults"_attr = numResults); return Message(bb.release()); } @@ -605,8 +615,9 @@ bool runQuery(OperationContext* opCtx, "Can't canonicalize query"); invariant(cq.get()); - LOG(5) << "Running query:\n" << redact(cq->toString()); - LOG(2) << "Running query: " << redact(cq->toStringShort()); + LOGV2_DEBUG(20913, 5, "Running query:\n{cq}", "cq"_attr = redact(cq->toString())); + LOGV2_DEBUG( + 20914, 2, "Running query: {cq_Short}", "cq_Short"_attr = redact(cq->toStringShort())); // Parse, canonicalize, plan, transcribe, and get a plan executor. AutoGetCollectionForReadCommand ctx(opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden); @@ -704,17 +715,25 @@ bool runQuery(OperationContext* opCtx, ++numResults; if (FindCommon::enoughForFirstBatch(qr, numResults)) { - LOG(5) << "Enough for first batch, wantMore=" << qr.wantMore() - << " ntoreturn=" << qr.getNToReturn().value_or(0) - << " numResults=" << numResults; + LOGV2_DEBUG(20915, + 5, + "Enough for first batch, wantMore={qr_wantMore} " + "ntoreturn={qr_getNToReturn_value_or_0} numResults={numResults}", + "qr_wantMore"_attr = qr.wantMore(), + "qr_getNToReturn_value_or_0"_attr = qr.getNToReturn().value_or(0), + "numResults"_attr = numResults); break; } } // Caller expects exceptions thrown in certain cases. if (PlanExecutor::FAILURE == state) { - error() << "Plan executor error during find: " << PlanExecutor::statestr(state) - << ", stats: " << redact(Explain::getWinningPlanStats(exec.get())); + LOGV2_ERROR(20919, + "Plan executor error during find: {PlanExecutor_statestr_state}, stats: " + "{Explain_getWinningPlanStats_exec_get}", + "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state), + "Explain_getWinningPlanStats_exec_get"_attr = + redact(Explain::getWinningPlanStats(exec.get()))); uassertStatusOKWithContext(WorkingSetCommon::getMemberObjectStatus(doc), "Executor error during OP_QUERY find"); MONGO_UNREACHABLE; @@ -746,8 +765,11 @@ bool runQuery(OperationContext* opCtx, }); ccId = pinnedCursor.getCursor()->cursorid(); - LOG(5) << "caching executor with cursorid " << ccId << " after returning " << numResults - << " results"; + LOGV2_DEBUG(20916, + 5, + "caching executor with cursorid {ccId} after returning {numResults} results", + "ccId"_attr = ccId, + "numResults"_attr = numResults); // Set curOp.debug().exhaust if the client requested exhaust and the cursor is not // exhausted. @@ -768,7 +790,10 @@ bool runQuery(OperationContext* opCtx, endQueryOp(opCtx, collection, *pinnedCursor.getCursor()->getExecutor(), numResults, ccId); } else { - LOG(5) << "Not caching executor but returning " << numResults << " results."; + LOGV2_DEBUG(20917, + 5, + "Not caching executor but returning {numResults} results.", + "numResults"_attr = numResults); endQueryOp(opCtx, collection, *exec, numResults, ccId); } diff --git a/src/mongo/db/query/find_common.cpp b/src/mongo/db/query/find_common.cpp index e236faccfb7..6b8a3a97b30 100644 --- a/src/mongo/db/query/find_common.cpp +++ b/src/mongo/db/query/find_common.cpp @@ -38,6 +38,7 @@ #include "mongo/db/curop_failpoint_helpers.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/query/query_request.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -79,8 +80,9 @@ bool FindCommon::haveSpaceForNext(const BSONObj& nextDoc, long long numDocs, int void FindCommon::waitInFindBeforeMakingBatch(OperationContext* opCtx, const CanonicalQuery& cq) { auto whileWaitingFunc = [&, hasLogged = false]() mutable { if (!std::exchange(hasLogged, true)) { - log() << "Waiting in find before making batch for query - " - << redact(cq.toStringShort()); + LOGV2(20908, + "Waiting in find before making batch for query - {cq_Short}", + "cq_Short"_attr = redact(cq.toStringShort())); } }; diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 255b814f97b..4738f0fa6be 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -87,6 +87,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/scripting/engine.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -186,9 +187,14 @@ IndexEntry indexEntryFromIndexCatalogEntry(OperationContext* opCtx, multikeyPathSet = accessMethod->getMultikeyPathSet(opCtx, &mkAccessStats); } - LOG(2) << "Multikey path metadata range index scan stats: { index: " - << desc->indexName() << ", numSeeks: " << mkAccessStats.keysExamined - << ", keysExamined: " << mkAccessStats.keysExamined << "}"; + LOGV2_DEBUG(20920, + 2, + "Multikey path metadata range index scan stats: {{ index: " + "{desc_indexName}, numSeeks: {mkAccessStats_keysExamined}, keysExamined: " + "{mkAccessStats_keysExamined2}}}", + "desc_indexName"_attr = desc->indexName(), + "mkAccessStats_keysExamined"_attr = mkAccessStats.keysExamined, + "mkAccessStats_keysExamined2"_attr = mkAccessStats.keysExamined); } } @@ -358,8 +364,11 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, // This can happen as we're called by internal clients as well. if (nullptr == collection) { const string& ns = canonicalQuery->ns(); - LOG(2) << "Collection " << ns << " does not exist." - << " Using EOF plan: " << redact(canonicalQuery->toStringShort()); + LOGV2_DEBUG(20921, + 2, + "Collection {ns} does not exist. Using EOF plan: {canonicalQuery_Short}", + "ns"_attr = ns, + "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort())); root = std::make_unique<EOFStage>(opCtx); return PrepareExecutionResult(std::move(canonicalQuery), nullptr, std::move(root)); } @@ -380,7 +389,10 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, // If we have an _id index we can use an idhack plan. if (descriptor && IDHackStage::supportsQuery(collection, *canonicalQuery)) { - LOG(2) << "Using idhack: " << redact(canonicalQuery->toStringShort()); + LOGV2_DEBUG(20922, + 2, + "Using idhack: {canonicalQuery_Short}", + "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort())); root = std::make_unique<IDHackStage>(opCtx, canonicalQuery.get(), ws, descriptor); @@ -473,7 +485,11 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, auto querySolution = std::move(statusWithQs.getValue()); if ((plannerParams.options & QueryPlannerParams::IS_COUNT) && turnIxscanIntoCount(querySolution.get())) { - LOG(2) << "Using fast count: " << redact(canonicalQuery->toStringShort()); + LOGV2_DEBUG(20923, + 2, + "Using fast count: {canonicalQuery_Short}", + "canonicalQuery_Short"_attr = + redact(canonicalQuery->toStringShort())); } auto root = @@ -499,7 +515,10 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, if (internalQueryPlanOrChildrenIndependently.load() && SubplanStage::canUseSubplanning(*canonicalQuery)) { - LOG(2) << "Running query as sub-queries: " << redact(canonicalQuery->toStringShort()); + LOGV2_DEBUG(20924, + 2, + "Running query as sub-queries: {canonicalQuery_Short}", + "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort())); root = std::make_unique<SubplanStage>( opCtx, collection, ws, plannerParams, canonicalQuery.get()); @@ -524,8 +543,13 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, auto root = StageBuilder::build(opCtx, collection, *canonicalQuery, *solutions[i], ws); - LOG(2) << "Using fast count: " << redact(canonicalQuery->toStringShort()) - << ", planSummary: " << Explain::getPlanSummary(root.get()); + LOGV2_DEBUG(20925, + 2, + "Using fast count: {canonicalQuery_Short}, planSummary: " + "{Explain_getPlanSummary_root_get}", + "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()), + "Explain_getPlanSummary_root_get"_attr = + Explain::getPlanSummary(root.get())); return PrepareExecutionResult( std::move(canonicalQuery), std::move(solutions[i]), std::move(root)); @@ -537,9 +561,12 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, // Only one possible plan. Run it. Build the stages from the solution. auto root = StageBuilder::build(opCtx, collection, *canonicalQuery, *solutions[0], ws); - LOG(2) << "Only one plan is available; it will be run but will not be cached. " - << redact(canonicalQuery->toStringShort()) - << ", planSummary: " << Explain::getPlanSummary(root.get()); + LOGV2_DEBUG(20926, + 2, + "Only one plan is available; it will be run but will not be cached. " + "{canonicalQuery_Short}, planSummary: {Explain_getPlanSummary_root_get}", + "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()), + "Explain_getPlanSummary_root_get"_attr = Explain::getPlanSummary(root.get())); return PrepareExecutionResult( std::move(canonicalQuery), std::move(solutions[0]), std::move(root)); @@ -731,8 +758,11 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDelete( if (!collection) { // Treat collections that do not exist as empty collections. Return a PlanExecutor which // contains an EOF stage. - LOG(2) << "Collection " << nss.ns() << " does not exist." - << " Using EOF stage: " << redact(request->getQuery()); + LOGV2_DEBUG(20927, + 2, + "Collection {nss_ns} does not exist. Using EOF stage: {request_getQuery}", + "nss_ns"_attr = nss.ns(), + "request_getQuery"_attr = redact(request->getQuery())); return PlanExecutor::make( opCtx, std::move(ws), std::make_unique<EOFStage>(opCtx), nullptr, policy, nss); } @@ -759,7 +789,10 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDelete( if (descriptor && CanonicalQuery::isSimpleIdQuery(unparsedQuery) && request->getProj().isEmpty() && hasCollectionDefaultCollation) { - LOG(2) << "Using idhack: " << redact(unparsedQuery); + LOGV2_DEBUG(20928, + 2, + "Using idhack: {unparsedQuery}", + "unparsedQuery"_attr = redact(unparsedQuery)); auto idHackStage = std::make_unique<IDHackStage>( opCtx, unparsedQuery["_id"].wrap(), ws.get(), descriptor); @@ -880,8 +913,11 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorUpdate( // we are an explain. If the collection doesn't exist, we're not an explain, and the upsert flag // is true, we expect the caller to have created the collection already. if (!collection) { - LOG(2) << "Collection " << nss.ns() << " does not exist." - << " Using EOF stage: " << redact(request->getQuery()); + LOGV2_DEBUG(20929, + 2, + "Collection {nss_ns} does not exist. Using EOF stage: {request_getQuery}", + "nss_ns"_attr = nss.ns(), + "request_getQuery"_attr = redact(request->getQuery())); return PlanExecutor::make( opCtx, std::move(ws), std::make_unique<EOFStage>(opCtx), nullptr, policy, nss); } @@ -906,7 +942,10 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorUpdate( if (descriptor && CanonicalQuery::isSimpleIdQuery(unparsedQuery) && request->getProj().isEmpty() && hasCollectionDefaultCollation) { - LOG(2) << "Using idhack: " << redact(unparsedQuery); + LOGV2_DEBUG(20930, + 2, + "Using idhack: {unparsedQuery}", + "unparsedQuery"_attr = redact(unparsedQuery)); // Working set 'ws' is discarded. InternalPlanner::updateWithIdHack() makes its own // WorkingSet. @@ -1507,8 +1546,13 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorForS auto root = StageBuilder::build(opCtx, collection, *parsedDistinct->getQuery(), *soln, ws.get()); - LOG(2) << "Using fast distinct: " << redact(parsedDistinct->getQuery()->toStringShort()) - << ", planSummary: " << Explain::getPlanSummary(root.get()); + LOGV2_DEBUG(20931, + 2, + "Using fast distinct: {parsedDistinct_getQuery_Short}, planSummary: " + "{Explain_getPlanSummary_root_get}", + "parsedDistinct_getQuery_Short"_attr = + redact(parsedDistinct->getQuery()->toStringShort()), + "Explain_getPlanSummary_root_get"_attr = Explain::getPlanSummary(root.get())); return PlanExecutor::make(parsedDistinct->releaseQuery(), std::move(ws), @@ -1548,8 +1592,14 @@ getExecutorDistinctFromIndexSolutions(OperationContext* opCtx, auto root = StageBuilder::build( opCtx, collection, *parsedDistinct->getQuery(), *currentSolution, ws.get()); - LOG(2) << "Using fast distinct: " << redact(parsedDistinct->getQuery()->toStringShort()) - << ", planSummary: " << Explain::getPlanSummary(root.get()); + LOGV2_DEBUG(20932, + 2, + "Using fast distinct: {parsedDistinct_getQuery_Short}, planSummary: " + "{Explain_getPlanSummary_root_get}", + "parsedDistinct_getQuery_Short"_attr = + redact(parsedDistinct->getQuery()->toStringShort()), + "Explain_getPlanSummary_root_get"_attr = + Explain::getPlanSummary(root.get())); return PlanExecutor::make(parsedDistinct->releaseQuery(), std::move(ws), diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp index 1e3a5bf9d47..9bb746228e1 100644 --- a/src/mongo/db/query/index_bounds_builder.cpp +++ b/src/mongo/db/query/index_bounds_builder.cpp @@ -50,6 +50,7 @@ #include "mongo/db/query/planner_ixselect.h" #include "mongo/db/query/planner_wildcard_helpers.h" #include "mongo/db/query/query_knobs_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" #include "third_party/s2/s2cell.h" @@ -887,13 +888,15 @@ void IndexBoundsBuilder::_translatePredicate(const MatchExpression* expr, *tightnessOut = IndexBoundsBuilder::INEXACT_FETCH; } else { - warning() << "Planner error trying to build geo bounds for " << elt.toString() - << " index element."; + LOGV2_WARNING(20934, + "Planner error trying to build geo bounds for {elt} index element.", + "elt"_attr = elt.toString()); verify(0); } } else { - warning() << "Planner error, trying to build bounds for expression: " - << redact(expr->debugString()); + LOGV2_WARNING(20935, + "Planner error, trying to build bounds for expression: {expr_debugString}", + "expr_debugString"_attr = redact(expr->debugString())); verify(0); } } @@ -1198,9 +1201,11 @@ void IndexBoundsBuilder::alignBounds(IndexBounds* bounds, const BSONObj& kp, int } if (!bounds->isValidFor(kp, scanDir)) { - log() << "INVALID BOUNDS: " << redact(bounds->toString()) << endl - << "kp = " << redact(kp) << endl - << "scanDir = " << scanDir; + LOGV2(20933, + "INVALID BOUNDS: {bounds}\nkp = {kp}\nscanDir = {scanDir}", + "bounds"_attr = redact(bounds->toString()), + "kp"_attr = redact(kp), + "scanDir"_attr = scanDir); MONGO_UNREACHABLE; } } diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp index 9d03e0b1012..5e25131d41f 100644 --- a/src/mongo/db/query/plan_cache.cpp +++ b/src/mongo/db/query/plan_cache.cpp @@ -51,6 +51,7 @@ #include "mongo/db/query/planner_ixselect.h" #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/query_solution.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/hex.h" #include "mongo/util/log.h" @@ -438,8 +439,10 @@ std::unique_ptr<CachedSolution> PlanCache::getCacheEntryIfActive(const PlanCache PlanCache::GetResult res = get(key); if (res.state == PlanCache::CacheEntryState::kPresentInactive) { - LOG(2) << "Not using cached entry for " << redact(res.cachedSolution->toString()) - << " since it is inactive"; + LOGV2_DEBUG(20936, + 2, + "Not using cached entry for {res_cachedSolution} since it is inactive", + "res_cachedSolution"_attr = redact(res.cachedSolution->toString())); return nullptr; } @@ -460,9 +463,17 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query double growthCoefficient) { NewEntryState res; if (!oldEntry) { - LOG(1) << "Creating inactive cache entry for query shape " << redact(query.toStringShort()) - << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey " - << unsignedIntToFixedLengthHex(planCacheKey) << " with works value " << newWorks; + LOGV2_DEBUG(20937, + 1, + "Creating inactive cache entry for query shape {query_Short} queryHash " + "{unsignedIntToFixedLengthHex_queryHash} planCacheKey " + "{unsignedIntToFixedLengthHex_planCacheKey} with works value {newWorks}", + "query_Short"_attr = redact(query.toStringShort()), + "unsignedIntToFixedLengthHex_queryHash"_attr = + unsignedIntToFixedLengthHex(queryHash), + "unsignedIntToFixedLengthHex_planCacheKey"_attr = + unsignedIntToFixedLengthHex(planCacheKey), + "newWorks"_attr = newWorks); res.shouldBeCreated = true; res.shouldBeActive = false; return res; @@ -472,18 +483,35 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query // The new plan did better than the currently stored active plan. This case may // occur if many MultiPlanners are run simultaneously. - LOG(1) << "Replacing active cache entry for query " << redact(query.toStringShort()) - << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey " - << unsignedIntToFixedLengthHex(planCacheKey) << " with works " << oldEntry->works - << " with a plan with works " << newWorks; + LOGV2_DEBUG(20938, + 1, + "Replacing active cache entry for query {query_Short} queryHash " + "{unsignedIntToFixedLengthHex_queryHash} planCacheKey " + "{unsignedIntToFixedLengthHex_planCacheKey} with works {oldEntry_works} with a " + "plan with works {newWorks}", + "query_Short"_attr = redact(query.toStringShort()), + "unsignedIntToFixedLengthHex_queryHash"_attr = + unsignedIntToFixedLengthHex(queryHash), + "unsignedIntToFixedLengthHex_planCacheKey"_attr = + unsignedIntToFixedLengthHex(planCacheKey), + "oldEntry_works"_attr = oldEntry->works, + "newWorks"_attr = newWorks); res.shouldBeCreated = true; res.shouldBeActive = true; } else if (oldEntry->isActive) { - LOG(1) << "Attempt to write to the planCache for query " << redact(query.toStringShort()) - << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey " - << unsignedIntToFixedLengthHex(planCacheKey) << " with a plan with works " - << newWorks << " is a noop, since there's already a plan with works value " - << oldEntry->works; + LOGV2_DEBUG(20939, + 1, + "Attempt to write to the planCache for query {query_Short} queryHash " + "{unsignedIntToFixedLengthHex_queryHash} planCacheKey " + "{unsignedIntToFixedLengthHex_planCacheKey} with a plan with works {newWorks} " + "is a noop, since there's already a plan with works value {oldEntry_works}", + "query_Short"_attr = redact(query.toStringShort()), + "unsignedIntToFixedLengthHex_queryHash"_attr = + unsignedIntToFixedLengthHex(queryHash), + "unsignedIntToFixedLengthHex_planCacheKey"_attr = + unsignedIntToFixedLengthHex(planCacheKey), + "newWorks"_attr = newWorks, + "oldEntry_works"_attr = oldEntry->works); // There is already an active cache entry with a higher works value. // We do nothing. res.shouldBeCreated = false; @@ -499,11 +527,18 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query const double increasedWorks = std::max( oldEntry->works + 1u, static_cast<size_t>(oldEntry->works * growthCoefficient)); - LOG(1) << "Increasing work value associated with cache entry for query " - << redact(query.toStringShort()) << " queryHash " - << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey " - << unsignedIntToFixedLengthHex(planCacheKey) << " from " << oldEntry->works << " to " - << increasedWorks; + LOGV2_DEBUG( + 20940, + 1, + "Increasing work value associated with cache entry for query {query_Short} queryHash " + "{unsignedIntToFixedLengthHex_queryHash} planCacheKey " + "{unsignedIntToFixedLengthHex_planCacheKey} from {oldEntry_works} to {increasedWorks}", + "query_Short"_attr = redact(query.toStringShort()), + "unsignedIntToFixedLengthHex_queryHash"_attr = unsignedIntToFixedLengthHex(queryHash), + "unsignedIntToFixedLengthHex_planCacheKey"_attr = + unsignedIntToFixedLengthHex(planCacheKey), + "oldEntry_works"_attr = oldEntry->works, + "increasedWorks"_attr = increasedWorks); oldEntry->works = increasedWorks; // Don't create a new entry. @@ -512,10 +547,19 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query // This plan performed just as well or better than we expected, based on the // inactive entry's works. We use this as an indicator that it's safe to // cache (as an active entry) the plan this query used for the future. - LOG(1) << "Inactive cache entry for query " << redact(query.toStringShort()) - << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey " - << unsignedIntToFixedLengthHex(planCacheKey) << " with works " << oldEntry->works - << " is being promoted to active entry with works value " << newWorks; + LOGV2_DEBUG(20941, + 1, + "Inactive cache entry for query {query_Short} queryHash " + "{unsignedIntToFixedLengthHex_queryHash} planCacheKey " + "{unsignedIntToFixedLengthHex_planCacheKey} with works {oldEntry_works} is " + "being promoted to active entry with works value {newWorks}", + "query_Short"_attr = redact(query.toStringShort()), + "unsignedIntToFixedLengthHex_queryHash"_attr = + unsignedIntToFixedLengthHex(queryHash), + "unsignedIntToFixedLengthHex_planCacheKey"_attr = + unsignedIntToFixedLengthHex(planCacheKey), + "oldEntry_works"_attr = oldEntry->works, + "newWorks"_attr = newWorks); // We'll replace the old inactive entry with an active entry. res.shouldBeCreated = true; res.shouldBeActive = true; @@ -594,8 +638,12 @@ Status PlanCache::set(const CanonicalQuery& query, std::unique_ptr<PlanCacheEntry> evictedEntry = _cache.add(key, newEntry.release()); if (nullptr != evictedEntry.get()) { - LOG(1) << query.nss() << ": plan cache maximum size exceeded - " - << "removed least recently used entry " << redact(evictedEntry->toString()); + LOGV2_DEBUG(20942, + 1, + "{query_nss}: plan cache maximum size exceeded - removed least recently used " + "entry {evictedEntry}", + "query_nss"_attr = query.nss(), + "evictedEntry"_attr = redact(evictedEntry->toString())); } return Status::OK(); diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp index f213e98c6c9..733b17056eb 100644 --- a/src/mongo/db/query/plan_enumerator.cpp +++ b/src/mongo/db/query/plan_enumerator.cpp @@ -35,6 +35,7 @@ #include "mongo/db/query/index_tag.h" #include "mongo/db/query/indexability.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/string_map.h" @@ -340,7 +341,7 @@ PlanEnumerator::MemoID PlanEnumerator::memoIDForNode(MatchExpression* node) { stdx::unordered_map<MatchExpression*, MemoID>::iterator it = _nodeToId.find(node); if (_nodeToId.end() == it) { - error() << "Trying to look up memo entry for node, none found."; + LOGV2_ERROR(20945, "Trying to look up memo entry for node, none found."); MONGO_UNREACHABLE; } @@ -359,7 +360,8 @@ unique_ptr<MatchExpression> PlanEnumerator::getNext() { tagForSort(tree.get()); _root->resetTag(); - LOG(5) << "Enumerator: memo just before moving:" << endl << dumpMemo(); + LOGV2_DEBUG( + 20943, 5, "Enumerator: memo just before moving:\n{dumpMemo}", "dumpMemo"_attr = dumpMemo()); _done = nextMemo(memoIDForNode(_root)); return tree; } @@ -1568,7 +1570,7 @@ void PlanEnumerator::compound(const vector<MatchExpression*>& tryCompound, // void PlanEnumerator::tagMemo(size_t id) { - LOG(5) << "Tagging memoID " << id; + LOGV2_DEBUG(20944, 5, "Tagging memoID {id}", "id"_attr = id); NodeAssignment* assign = _memo[id]; verify(nullptr != assign); diff --git a/src/mongo/db/query/plan_executor_impl.cpp b/src/mongo/db/query/plan_executor_impl.cpp index c4e1bb83c7d..fae86c1e8ce 100644 --- a/src/mongo/db/query/plan_executor_impl.cpp +++ b/src/mongo/db/query/plan_executor_impl.cpp @@ -56,6 +56,7 @@ #include "mongo/db/query/plan_yield_policy.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -635,8 +636,9 @@ PlanExecutor::ExecState PlanExecutorImpl::_getNextImpl(Snapshotted<Document>* ob } return true; }))) { - log() << "PlanExecutor - planExecutorHangBeforeShouldWaitForInserts fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(20946, + "PlanExecutor - planExecutorHangBeforeShouldWaitForInserts fail point " + "enabled. Blocking until fail point is disabled."); planExecutorHangBeforeShouldWaitForInserts.pauseWhileSet(); } if (!_shouldWaitForInserts()) { diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp index 7b998c6d583..2c5abd7cad6 100644 --- a/src/mongo/db/query/plan_ranker.cpp +++ b/src/mongo/db/query/plan_ranker.cpp @@ -44,6 +44,7 @@ #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/query_solution.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace { @@ -93,25 +94,42 @@ StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan( // Compute score for each tree. Record the best. for (size_t i = 0; i < statTrees.size(); ++i) { if (!candidates[i].failed) { - LOG(5) << "Scoring plan " << i << ":" << endl - << redact(candidates[i].solution->toString()) << "Stats:\n" - << redact(Explain::statsToBSON(*statTrees[i]) - .jsonString(ExtendedRelaxedV2_0_0, true)); - LOG(2) << "Scoring query plan: " << Explain::getPlanSummary(candidates[i].root) - << " planHitEOF=" << statTrees[i]->common.isEOF; + LOGV2_DEBUG( + 20956, + 5, + "Scoring plan " + "{i}:\n{candidates_i_solution}Stats:\n{Explain_statsToBSON_statTrees_i_jsonString_" + "ExtendedRelaxedV2_0_0_true}", + "i"_attr = i, + "candidates_i_solution"_attr = redact(candidates[i].solution->toString()), + "Explain_statsToBSON_statTrees_i_jsonString_ExtendedRelaxedV2_0_0_true"_attr = + redact(Explain::statsToBSON(*statTrees[i]) + .jsonString(ExtendedRelaxedV2_0_0, true))); + LOGV2_DEBUG(20957, + 2, + "Scoring query plan: {Explain_getPlanSummary_candidates_i_root} " + "planHitEOF={statTrees_i_common_isEOF}", + "Explain_getPlanSummary_candidates_i_root"_attr = + Explain::getPlanSummary(candidates[i].root), + "statTrees_i_common_isEOF"_attr = statTrees[i]->common.isEOF); double score = scoreTree(statTrees[i].get()); - LOG(5) << "score = " << score; + LOGV2_DEBUG(20958, 5, "score = {score}", "score"_attr = score); if (statTrees[i]->common.isEOF) { - LOG(5) << "Adding +" << eofBonus << " EOF bonus to score."; + LOGV2_DEBUG( + 20959, 5, "Adding +{eofBonus} EOF bonus to score.", "eofBonus"_attr = eofBonus); score += 1; } scoresAndCandidateindices.push_back(std::make_pair(score, i)); } else { failed.push_back(i); - LOG(2) << "Not scording plan: " << Explain::getPlanSummary(candidates[i].root) - << " because the plan failed."; + LOGV2_DEBUG(20960, + 2, + "Not scording plan: {Explain_getPlanSummary_candidates_i_root} because the " + "plan failed.", + "Explain_getPlanSummary_candidates_i_root"_attr = + Explain::getPlanSummary(candidates[i].root)); } } @@ -265,14 +283,17 @@ double PlanRanker::scoreTree(const PlanStageStats* stats) { << str::convertDoubleToString(noSortBonus) << " noSortBonus + " << str::convertDoubleToString(noIxisectBonus) << " noIxisectBonus = " << str::convertDoubleToString(tieBreakers) << ")"; - LOG(2) << sb.str(); + LOGV2_DEBUG(20961, 2, "{sb_str}", "sb_str"_attr = sb.str()); if (internalQueryForceIntersectionPlans.load()) { if (hasStage(STAGE_AND_HASH, stats) || hasStage(STAGE_AND_SORTED, stats)) { // The boost should be >2.001 to make absolutely sure the ixisect plan will win due // to the combination of 1) productivity, 2) eof bonus, and 3) no ixisect bonus. score += 3; - LOG(5) << "Score boosted to " << score << " due to intersection forcing."; + LOGV2_DEBUG(20962, + 5, + "Score boosted to {score} due to intersection forcing.", + "score"_attr = score); } } diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp index 7a09019424c..9510cc85481 100644 --- a/src/mongo/db/query/planner_access.cpp +++ b/src/mongo/db/query/planner_access.cpp @@ -50,6 +50,7 @@ #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_common.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" @@ -1112,8 +1113,10 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedAnd( } else { // We can't use sort-based intersection, and hash-based intersection is disabled. // Clean up the index scans and bail out by returning NULL. - LOG(5) << "Can't build index intersection solution: " - << "AND_SORTED is not possible and AND_HASH is disabled."; + LOGV2_DEBUG(20947, + 5, + "Can't build index intersection solution: AND_SORTED is not possible and " + "AND_HASH is disabled."); return nullptr; } } @@ -1180,7 +1183,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedOr( // when any of our children lack index tags. If a node lacks an index tag it cannot // be answered via an index. if (!inArrayOperator && 0 != root->numChildren()) { - warning() << "planner OR error, non-indexed child of OR."; + LOGV2_WARNING(20948, "planner OR error, non-indexed child of OR."); // We won't enumerate an OR without indices for each child, so this isn't an issue, even // if we have an AND with an OR child -- we won't get here unless the OR is fully // indexed. diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index 0dcde5c00d7..942d27d7512 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -42,6 +42,7 @@ #include "mongo/db/matcher/expression_geo.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_common.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -344,7 +345,10 @@ std::unique_ptr<QuerySolutionNode> addSortKeyGeneratorStageIfNeeded( std::unique_ptr<ProjectionNode> analyzeProjection(const CanonicalQuery& query, std::unique_ptr<QuerySolutionNode> solnRoot, const bool hasSortStage) { - LOG(5) << "PROJECTION: Current plan is:\n" << redact(solnRoot->toString()); + LOGV2_DEBUG(20949, + 5, + "PROJECTION: Current plan is:\n{solnRoot}", + "solnRoot"_attr = redact(solnRoot->toString())); // If the projection requires the entire document we add a fetch stage if not present. Otherwise // we add a fetch stage if we are not covered. @@ -644,8 +648,11 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query, // Too many ixscans spoil the performance. if (totalNumScans > (size_t)internalQueryMaxScansToExplode.load()) { - LOG(5) << "Could expand ixscans to pull out sort order but resulting scan count" - << "(" << totalNumScans << ") is too high."; + LOGV2_DEBUG(20950, + 5, + "Could expand ixscans to pull out sort order but resulting scan " + "count({totalNumScans}) is too high.", + "totalNumScans"_attr = totalNumScans); return false; } @@ -705,7 +712,10 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query BSONObj reverseSort = QueryPlannerCommon::reverseSortObj(sortObj); if (sorts.end() != sorts.find(reverseSort)) { QueryPlannerCommon::reverseScans(solnRoot); - LOG(5) << "Reversing ixscan to provide sort. Result: " << redact(solnRoot->toString()); + LOGV2_DEBUG(20951, + 5, + "Reversing ixscan to provide sort. Result: {solnRoot}", + "solnRoot"_attr = redact(solnRoot->toString())); return solnRoot; } diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp index b97433015f5..27ad04ac703 100644 --- a/src/mongo/db/query/planner_ixselect.cpp +++ b/src/mongo/db/query/planner_ixselect.cpp @@ -47,6 +47,7 @@ #include "mongo/db/query/indexability.h" #include "mongo/db/query/planner_wildcard_helpers.h" #include "mongo/db/query/query_planner_common.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -287,15 +288,20 @@ std::vector<IndexEntry> QueryPlannerIXSelect::findIndexesByHint( auto hintName = firstHintElt.valueStringData(); for (auto&& entry : allIndices) { if (entry.identifier.catalogName == hintName) { - LOG(5) << "Hint by name specified, restricting indices to " - << entry.keyPattern.toString(); + LOGV2_DEBUG(20952, + 5, + "Hint by name specified, restricting indices to {entry_keyPattern}", + "entry_keyPattern"_attr = entry.keyPattern.toString()); out.push_back(entry); } } } else { for (auto&& entry : allIndices) { if (SimpleBSONObjComparator::kInstance.evaluate(entry.keyPattern == hintedIndex)) { - LOG(5) << "Hint specified, restricting indices to " << hintedIndex.toString(); + LOGV2_DEBUG(20953, + 5, + "Hint specified, restricting indices to {hintedIndex}", + "hintedIndex"_attr = hintedIndex.toString()); out.push_back(entry); } } @@ -579,8 +585,10 @@ bool QueryPlannerIXSelect::_compatible(const BSONElement& keyPatternElt, } else if (IndexNames::GEO_HAYSTACK == indexedFieldType) { return false; } else { - warning() << "Unknown indexing for node " << node->debugString() << " and field " - << keyPatternElt.toString(); + LOGV2_WARNING(20954, + "Unknown indexing for node {node_debugString} and field {keyPatternElt}", + "node_debugString"_attr = node->debugString(), + "keyPatternElt"_attr = keyPatternElt.toString()); verify(0); } } diff --git a/src/mongo/db/query/planner_wildcard_helpers.cpp b/src/mongo/db/query/planner_wildcard_helpers.cpp index 4f1743d7316..c04c33e02d0 100644 --- a/src/mongo/db/query/planner_wildcard_helpers.cpp +++ b/src/mongo/db/query/planner_wildcard_helpers.cpp @@ -39,6 +39,7 @@ #include "mongo/db/exec/projection_executor_utils.h" #include "mongo/db/index/wildcard_key_generator.h" #include "mongo/db/query/index_bounds.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -245,9 +246,14 @@ bool validateNumericPathComponents(const MultikeyPaths& multikeyPaths, // all paths with and without array indices. Because this is O(2^n), we decline to answer // queries that traverse more than 8 levels of array indices. if (arrayIndices.size() > kWildcardMaxArrayIndexTraversalDepth) { - LOG(2) << "Declining to answer query on field '" << queryPath.dottedField() - << "' with $** index, as it traverses through more than " - << kWildcardMaxArrayIndexTraversalDepth << " nested array indices."; + LOGV2_DEBUG(20955, + 2, + "Declining to answer query on field '{queryPath_dottedField}' with $** index, " + "as it traverses through more than {kWildcardMaxArrayIndexTraversalDepth} " + "nested array indices.", + "queryPath_dottedField"_attr = queryPath.dottedField(), + "kWildcardMaxArrayIndexTraversalDepth"_attr = + kWildcardMaxArrayIndexTraversalDepth); return false; } diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp index d95ff7dd03f..966fb61275e 100644 --- a/src/mongo/db/query/query_planner.cpp +++ b/src/mongo/db/query/query_planner.cpp @@ -54,6 +54,7 @@ #include "mongo/db/query/planner_ixselect.h" #include "mongo/db/query/query_planner_common.h" #include "mongo/db/query/query_solution.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -475,10 +476,12 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache( // Create a copy of the expression tree. We use cachedSoln to annotate this with indices. unique_ptr<MatchExpression> clone = query.root()->shallowClone(); - LOG(5) << "Tagging the match expression according to cache data: " << endl - << "Filter:" << endl - << redact(clone->debugString()) << "Cache data:" << endl - << redact(winnerCacheData.toString()); + LOGV2_DEBUG(20963, + 5, + "Tagging the match expression according to cache data: " + "\nFilter:\n{clone_debugString}Cache data:\n{winnerCacheData}", + "clone_debugString"_attr = redact(clone->debugString()), + "winnerCacheData"_attr = redact(winnerCacheData.toString())); stdx::unordered_set<string> fields; QueryPlannerIXSelect::getFields(query.root(), &fields); @@ -492,7 +495,11 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache( const auto insertionRes = indexMap.insert(std::make_pair(ie.identifier, i)); // Be sure the key was not already in the map. invariant(insertionRes.second); - LOG(5) << "Index " << i << ": " << ie.identifier; + LOGV2_DEBUG(20964, + 5, + "Index {i}: {ie_identifier}", + "i"_attr = i, + "ie_identifier"_attr = ie.identifier); } Status s = tagAccordingToCache(clone.get(), winnerCacheData.tree.get(), indexMap); @@ -503,7 +510,10 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache( // The MatchExpression tree is in canonical order. We must order the nodes for access planning. prepareForAccessPlanning(clone.get()); - LOG(5) << "Tagged tree:" << endl << redact(clone->debugString()); + LOGV2_DEBUG(20965, + 5, + "Tagged tree:\n{clone_debugString}", + "clone_debugString"_attr = redact(clone->debugString())); // Use the cached index assignments to build solnRoot. std::unique_ptr<QuerySolutionNode> solnRoot(QueryPlannerAccess::buildIndexedDataAccess( @@ -522,21 +532,30 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache( << "Failed to analyze plan from cache. Query: " << query.toStringShort()); } - LOG(5) << "Planner: solution constructed from the cache:\n" << redact(soln->toString()); + LOGV2_DEBUG(20966, + 5, + "Planner: solution constructed from the cache:\n{soln}", + "soln"_attr = redact(soln->toString())); return {std::move(soln)}; } // static StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( const CanonicalQuery& query, const QueryPlannerParams& params) { - LOG(5) << "Beginning planning..." << endl - << "=============================" << endl - << "Options = " << optionString(params.options) << endl - << "Canonical query:" << endl - << redact(query.toString()) << "============================="; + LOGV2_DEBUG( + 20967, + 5, + "Beginning planning...\n=============================\nOptions = " + "{optionString_params_options}\nCanonical query:\n{query}=============================", + "optionString_params_options"_attr = optionString(params.options), + "query"_attr = redact(query.toString())); for (size_t i = 0; i < params.indices.size(); ++i) { - LOG(5) << "Index " << i << " is " << params.indices[i].toString(); + LOGV2_DEBUG(20968, + 5, + "Index {i} is {params_indices_i}", + "i"_attr = i, + "params_indices_i"_attr = params.indices[i].toString()); } const bool canTableScan = !(params.options & QueryPlannerParams::NO_TABLE_SCAN); @@ -572,7 +591,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( BSONElement naturalHint = dps::extractElementAtPath(hintObj, "$natural"); if (naturalHint) { - LOG(5) << "Forcing a table scan due to hinted $natural"; + LOGV2_DEBUG(20969, 5, "Forcing a table scan due to hinted $natural"); if (!canTableScan) { return Status(ErrorCodes::NoQueryExecutionPlans, "hint $natural is not allowed, because 'notablescan' is enabled"); @@ -632,7 +651,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( stdx::unordered_set<string> fields; QueryPlannerIXSelect::getFields(query.root(), &fields); for (auto&& field : fields) { - LOG(5) << "Predicate over field '" << field << "'"; + LOGV2_DEBUG(20970, 5, "Predicate over field '{field}'", "field"_attr = field); } fullIndexList = QueryPlannerIXSelect::expandIndexes(fields, std::move(fullIndexList)); @@ -706,7 +725,11 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( } for (size_t i = 0; i < relevantIndices.size(); ++i) { - LOG(2) << "Relevant index " << i << " is " << relevantIndices[i].toString(); + LOGV2_DEBUG(20971, + 2, + "Relevant index {i} is {relevantIndices_i}", + "i"_attr = i, + "relevantIndices_i"_attr = relevantIndices[i].toString()); } // Figure out how useful each index is to each predicate. @@ -728,7 +751,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( } // query.root() is now annotated with RelevantTag(s). - LOG(5) << "Rated tree:" << endl << redact(query.root()->debugString()); + LOGV2_DEBUG(20972, + 5, + "Rated tree:\n{query_root_debugString}", + "query_root_debugString"_attr = redact(query.root()->debugString())); // If there is a GEO_NEAR it must have an index it can use directly. const MatchExpression* gnNode = nullptr; @@ -736,14 +762,17 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // No index for GEO_NEAR? No query. RelevantTag* tag = static_cast<RelevantTag*>(gnNode->getTag()); if (!tag || (0 == tag->first.size() && 0 == tag->notFirst.size())) { - LOG(5) << "Unable to find index for $geoNear query."; + LOGV2_DEBUG(20973, 5, "Unable to find index for $geoNear query."); // Don't leave tags on query tree. query.root()->resetTag(); return Status(ErrorCodes::NoQueryExecutionPlans, "unable to find index for $geoNear query"); } - LOG(5) << "Rated tree after geonear processing:" << redact(query.root()->debugString()); + LOGV2_DEBUG(20974, + 5, + "Rated tree after geonear processing:{query_root_debugString}", + "query_root_debugString"_attr = redact(query.root()->debugString())); } // Likewise, if there is a TEXT it must have an index it can use directly. @@ -780,7 +809,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // assigned to it. invariant(1 == tag->first.size() + tag->notFirst.size()); - LOG(5) << "Rated tree after text processing:" << redact(query.root()->debugString()); + LOGV2_DEBUG(20975, + 5, + "Rated tree after text processing:{query_root_debugString}", + "query_root_debugString"_attr = redact(query.root()->debugString())); } std::vector<std::unique_ptr<QuerySolution>> out; @@ -798,8 +830,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( unique_ptr<MatchExpression> nextTaggedTree; while ((nextTaggedTree = isp.getNext()) && (out.size() < params.maxIndexedSolutions)) { - LOG(5) << "About to build solntree from tagged tree:" << endl - << redact(nextTaggedTree->debugString()); + LOGV2_DEBUG(20976, + 5, + "About to build solntree from tagged tree:\n{nextTaggedTree_debugString}", + "nextTaggedTree_debugString"_attr = redact(nextTaggedTree->debugString())); // Store the plan cache index tree before calling prepareForAccessingPlanning(), so that // the PlanCacheIndexTree has the same sort as the MatchExpression used to generate the @@ -808,8 +842,11 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( std::unique_ptr<PlanCacheIndexTree> cacheData; auto statusWithCacheData = cacheDataFromTaggedTree(clone.get(), relevantIndices); if (!statusWithCacheData.isOK()) { - LOG(5) << "Query is not cachable: " - << redact(statusWithCacheData.getStatus().reason()); + LOGV2_DEBUG(20977, + 5, + "Query is not cachable: {statusWithCacheData_getStatus_reason}", + "statusWithCacheData_getStatus_reason"_attr = + redact(statusWithCacheData.getStatus().reason())); } else { cacheData = std::move(statusWithCacheData.getValue()); } @@ -828,7 +865,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( auto soln = QueryPlannerAnalysis::analyzeDataAccess(query, params, std::move(solnRoot)); if (soln) { - LOG(5) << "Planner: adding solution:" << endl << redact(soln->toString()); + LOGV2_DEBUG(20978, + 5, + "Planner: adding solution:\n{soln}", + "soln"_attr = redact(soln->toString())); if (statusWithCacheData.isOK()) { SolutionCacheData* scd = new SolutionCacheData(); scd->tree = std::move(cacheData); @@ -842,7 +882,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // Don't leave tags on query tree. query.root()->resetTag(); - LOG(5) << "Planner: outputted " << out.size() << " indexed solutions."; + LOGV2_DEBUG( + 20979, 5, "Planner: outputted {out_size} indexed solutions.", "out_size"_attr = out.size()); // Produce legible error message for failed OR planning with a TEXT child. // TODO: support collection scan for non-TEXT children of OR. @@ -877,7 +918,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( return Status(ErrorCodes::NoQueryExecutionPlans, "Failed to build whole-index solution for $hint"); } - LOG(5) << "Planner: outputting soln that uses hinted index as scan."; + LOGV2_DEBUG(20980, 5, "Planner: outputting soln that uses hinted index as scan."); std::vector<std::unique_ptr<QuerySolution>> out; out.push_back(std::move(soln)); return {std::move(out)}; @@ -938,7 +979,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( const BSONObj kp = QueryPlannerAnalysis::getSortPattern(index.keyPattern); if (providesSort(query, kp)) { - LOG(5) << "Planner: outputting soln that uses index to provide sort."; + LOGV2_DEBUG( + 20981, 5, "Planner: outputting soln that uses index to provide sort."); auto soln = buildWholeIXSoln(fullIndexList[i], query, params); if (soln) { PlanCacheIndexTree* indexTree = new PlanCacheIndexTree(); @@ -953,8 +995,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( } } if (providesSort(query, QueryPlannerCommon::reverseSortObj(kp))) { - LOG(5) << "Planner: outputting soln that uses (reverse) index " - << "to provide sort."; + LOGV2_DEBUG( + 20982, + 5, + "Planner: outputting soln that uses (reverse) index to provide sort."); auto soln = buildWholeIXSoln(fullIndexList[i], query, params, -1); if (soln) { PlanCacheIndexTree* indexTree = new PlanCacheIndexTree(); @@ -988,7 +1032,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( QueryPlannerParams paramsForCoveredIxScan; auto soln = buildWholeIXSoln(index, query, paramsForCoveredIxScan); if (soln && !soln->root->fetched()) { - LOG(5) << "Planner: outputting soln that uses index to provide projection."; + LOGV2_DEBUG( + 20983, 5, "Planner: outputting soln that uses index to provide projection."); PlanCacheIndexTree* indexTree = new PlanCacheIndexTree(); indexTree->setIndexEntry(index); @@ -1030,7 +1075,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( "Failed to build collection scan soln"); } if (collscan) { - LOG(5) << "Planner: outputting a collscan:" << endl << redact(collscan->toString()); + LOGV2_DEBUG(20984, + 5, + "Planner: outputting a collscan:\n{collscan}", + "collscan"_attr = redact(collscan->toString())); SolutionCacheData* scd = new SolutionCacheData(); scd->solnType = SolutionCacheData::COLLSCAN_SOLN; collscan->cacheData.reset(scd); diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp index db4ae678f87..c7c9bd342c6 100644 --- a/src/mongo/db/query/query_planner_test_fixture.cpp +++ b/src/mongo/db/query/query_planner_test_fixture.cpp @@ -42,6 +42,7 @@ #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_test_lib.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" @@ -478,7 +479,7 @@ size_t QueryPlannerTest::getNumSolutions() const { void QueryPlannerTest::dumpSolutions() const { str::stream ost; dumpSolutions(ost); - log() << std::string(ost); + LOGV2(20985, "{std_string_ost}", "std_string_ost"_attr = std::string(ost)); } void QueryPlannerTest::dumpSolutions(str::stream& ost) const { diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp index 3569bc526c0..2af9934eff4 100644 --- a/src/mongo/db/read_concern_mongod.cpp +++ b/src/mongo/db/read_concern_mongod.cpp @@ -45,6 +45,7 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/server_options.h" #include "mongo/db/storage/recovery_unit.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/util/concurrency/notification.h" #include "mongo/util/log.h" @@ -121,8 +122,13 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { auto waitStatus = replCoord->waitUntilOpTimeForReadUntil(opCtx, readConcernArgs, deadline); lastAppliedOpTime = LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp()); if (!waitStatus.isOK()) { - LOG(1) << "Wait for clusterTime: " << clusterTime.toString() - << " until deadline: " << deadline << " failed with " << waitStatus.toString(); + LOGV2_DEBUG(20986, + 1, + "Wait for clusterTime: {clusterTime} until deadline: {deadline} failed " + "with {waitStatus}", + "clusterTime"_attr = clusterTime.toString(), + "deadline"_attr = deadline, + "waitStatus"_attr = waitStatus.toString()); } } @@ -163,8 +169,12 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { auto myWriteRequest = writeRequests.getOrCreateWriteRequest(clusterTime); if (std::get<0>(myWriteRequest)) { // Its a new request try { - LOG(2) << "New appendOplogNote request on clusterTime: " << clusterTime.toString() - << " remaining attempts: " << remainingAttempts; + LOGV2_DEBUG(20987, + 2, + "New appendOplogNote request on clusterTime: {clusterTime} remaining " + "attempts: {remainingAttempts}", + "clusterTime"_attr = clusterTime.toString(), + "remainingAttempts"_attr = remainingAttempts); auto swRes = myShard.getValue()->runCommand( opCtx, ReadPreferenceSetting(ReadPreference::PrimaryOnly), @@ -183,8 +193,12 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { writeRequests.deleteWriteRequest(clusterTime); } } else { - LOG(2) << "Join appendOplogNote request on clusterTime: " << clusterTime.toString() - << " remaining attempts: " << remainingAttempts; + LOGV2_DEBUG(20988, + 2, + "Join appendOplogNote request on clusterTime: {clusterTime} remaining " + "attempts: {remainingAttempts}", + "clusterTime"_attr = clusterTime.toString(), + "remainingAttempts"_attr = remainingAttempts); try { status = std::get<1>(myWriteRequest)->get(opCtx); } catch (const DBException& ex) { @@ -199,8 +213,11 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { } // This is when the noop write failed but the opLog caught up to clusterTime by replicating. if (!status.isOK()) { - LOG(1) << "Reached clusterTime " << lastAppliedOpTime.toString() - << " but failed noop write due to " << status.toString(); + LOGV2_DEBUG(20989, + 1, + "Reached clusterTime {lastAppliedOpTime} but failed noop write due to {status}", + "lastAppliedOpTime"_attr = lastAppliedOpTime.toString(), + "status"_attr = status.toString()); } return Status::OK(); } @@ -316,8 +333,10 @@ Status waitForReadConcernImpl(OperationContext* opCtx, auto status = makeNoopWriteIfNeeded(opCtx, *targetClusterTime); if (!status.isOK()) { - LOG(0) << "Failed noop write at clusterTime: " << targetClusterTime->toString() - << " due to " << status.toString(); + LOGV2(20990, + "Failed noop write at clusterTime: {targetClusterTime} due to {status}", + "targetClusterTime"_attr = targetClusterTime->toString(), + "status"_attr = status.toString()); } } @@ -361,15 +380,19 @@ Status waitForReadConcernImpl(OperationContext* opCtx, const int debugLevel = serverGlobalParams.clusterRole == ClusterRole::ConfigServer ? 1 : 2; - LOG(debugLevel) << "Waiting for 'committed' snapshot to be available for reading: " - << readConcernArgs; + LOGV2_DEBUG( + 20991, + logSeverityV1toV2(debugLevel).toInt(), + "Waiting for 'committed' snapshot to be available for reading: {readConcernArgs}", + "readConcernArgs"_attr = readConcernArgs); opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted); Status status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot(); // Wait until a snapshot is available. while (status == ErrorCodes::ReadConcernMajorityNotAvailableYet) { - LOG(debugLevel) << "Snapshot not available yet."; + LOGV2_DEBUG( + 20992, logSeverityV1toV2(debugLevel).toInt(), "Snapshot not available yet."); replCoord->waitUntilSnapshotCommitted(opCtx, Timestamp()); status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot(); } @@ -378,8 +401,13 @@ Status waitForReadConcernImpl(OperationContext* opCtx, return status; } - LOG(debugLevel) << "Using 'committed' snapshot: " << CurOp::get(opCtx)->opDescription() - << " with readTs: " << opCtx->recoveryUnit()->getPointInTimeReadTimestamp(); + LOGV2_DEBUG(20993, + logSeverityV1toV2(debugLevel).toInt(), + "Using 'committed' snapshot: {CurOp_get_opCtx_opDescription} with readTs: " + "{opCtx_recoveryUnit_getPointInTimeReadTimestamp}", + "CurOp_get_opCtx_opDescription"_attr = CurOp::get(opCtx)->opDescription(), + "opCtx_recoveryUnit_getPointInTimeReadTimestamp"_attr = + opCtx->recoveryUnit()->getPointInTimeReadTimestamp()); } return Status::OK(); } @@ -387,8 +415,9 @@ Status waitForReadConcernImpl(OperationContext* opCtx, Status waitForLinearizableReadConcernImpl(OperationContext* opCtx, const int readConcernTimeout) { CurOpFailpointHelpers::waitWhileFailPointEnabled( &hangBeforeLinearizableReadConcern, opCtx, "hangBeforeLinearizableReadConcern", [opCtx]() { - log() << "batch update - hangBeforeLinearizableReadConcern fail point enabled. " - "Blocking until fail point is disabled."; + LOGV2(20994, + "batch update - hangBeforeLinearizableReadConcern fail point enabled. " + "Blocking until fail point is disabled."); }); repl::ReplicationCoordinator* replCoord = @@ -460,8 +489,12 @@ Status waitForSpeculativeMajorityReadConcernImpl( } // Block to make sure returned data is majority committed. - LOG(1) << "Servicing speculative majority read, waiting for timestamp " << waitTs - << " to become committed, current commit point: " << replCoord->getLastCommittedOpTime(); + LOGV2_DEBUG(20995, + 1, + "Servicing speculative majority read, waiting for timestamp {waitTs} to become " + "committed, current commit point: {replCoord_getLastCommittedOpTime}", + "waitTs"_attr = waitTs, + "replCoord_getLastCommittedOpTime"_attr = replCoord->getLastCommittedOpTime()); if (!opCtx->hasDeadline()) { // This hard-coded value represents the maximum time we are willing to wait for a timestamp @@ -476,8 +509,12 @@ Status waitForSpeculativeMajorityReadConcernImpl( Timer t; auto waitStatus = replCoord->awaitTimestampCommitted(opCtx, waitTs); if (waitStatus.isOK()) { - LOG(1) << "Timestamp " << waitTs << " became majority committed, waited " << t.millis() - << "ms for speculative majority read to be satisfied."; + LOGV2_DEBUG(20996, + 1, + "Timestamp {waitTs} became majority committed, waited {t_millis}ms for " + "speculative majority read to be satisfied.", + "waitTs"_attr = waitTs, + "t_millis"_attr = t.millis()); } return waitStatus; } diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp index a008c489e8b..4f4113e1db8 100644 --- a/src/mongo/db/read_write_concern_defaults.cpp +++ b/src/mongo/db/read_write_concern_defaults.cpp @@ -34,6 +34,7 @@ #include "mongo/db/read_write_concern_defaults.h" #include "mongo/db/logical_clock.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -180,7 +181,9 @@ void ReadWriteConcernDefaults::refreshIfNecessary(OperationContext* opCtx) { (possibleNewDefaults->getEpoch() > currentDefaultsHandle->getEpoch())) { // Use the new defaults if they have a higher epoch, if there are no defaults in the cache, // or if the found defaults have no epoch, meaning there are no defaults in config.settings. - log() << "refreshed RWC defaults to " << possibleNewDefaults->toBSON(); + LOGV2(20997, + "refreshed RWC defaults to {possibleNewDefaults}", + "possibleNewDefaults"_attr = possibleNewDefaults->toBSON()); setDefault(std::move(*possibleNewDefaults)); } } diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 65e6bfd350e..07fed07a646 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -58,6 +58,7 @@ #include "mongo/db/rebuild_indexes.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/storage_engine.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -90,7 +91,7 @@ Status repairCollections(OperationContext* opCtx, for (const auto& nss : colls) { opCtx->checkForInterrupt(); - log() << "Repairing collection " << nss; + LOGV2(21027, "Repairing collection {nss}", "nss"_attr = nss); auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss); Status status = engine->repairRecordStore(opCtx, collection->getCatalogId(), nss); @@ -128,7 +129,9 @@ Status repairCollections(OperationContext* opCtx, return status; } - log() << "Collection validation results: " << output.done(); + LOGV2(21028, + "Collection validation results: {output_done}", + "output_done"_attr = output.done()); if (!validateResults.valid) { status = rebuildIndexesForNamespace(opCtx, nss, engine); @@ -148,7 +151,7 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: invariant(opCtx->lockState()->isW()); invariant(dbName.find('.') == std::string::npos); - log() << "repairDatabase " << dbName; + LOGV2(21029, "repairDatabase {dbName}", "dbName"_attr = dbName); BackgroundOperation::assertNoBgOpInProgForDb(dbName); @@ -163,7 +166,10 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: auto status = repairCollections(opCtx, engine, dbName); if (!status.isOK()) { - severe() << "Failed to repair database " << dbName << ": " << status.reason(); + LOGV2_FATAL(21030, + "Failed to repair database {dbName}: {status_reason}", + "dbName"_attr = dbName, + "status_reason"_attr = status.reason()); } try { @@ -189,7 +195,8 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: // have a UUID. throw; } catch (...) { - severe() << "Unexpected exception encountered while reopening database after repair."; + LOGV2_FATAL(21031, + "Unexpected exception encountered while reopening database after repair."); std::terminate(); // Logs additional info about the specific error. } diff --git a/src/mongo/db/repair_database_and_check_version.cpp b/src/mongo/db/repair_database_and_check_version.cpp index f152e9c378c..2f1e1c70c75 100644 --- a/src/mongo/db/repair_database_and_check_version.cpp +++ b/src/mongo/db/repair_database_and_check_version.cpp @@ -57,6 +57,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/storage_repair_observer.h" +#include "mongo/logv2/log.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -89,7 +90,7 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx auto databaseHolder = DatabaseHolder::get(opCtx); auto db = databaseHolder->getDb(opCtx, fcvNss.db()); if (!db) { - log() << "Re-creating admin database that was dropped."; + LOGV2(20998, "Re-creating admin database that was dropped."); } db = databaseHolder->openDb(opCtx, fcvNss.db()); invariant(db); @@ -98,8 +99,9 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx // create it. if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace( opCtx, NamespaceString::kServerConfigurationNamespace)) { - log() << "Re-creating the server configuration collection (admin.system.version) that was " - "dropped."; + LOGV2(20999, + "Re-creating the server configuration collection (admin.system.version) that was " + "dropped."); uassertStatusOK( createCollection(opCtx, fcvNss.db().toString(), BSON("create" << fcvNss.coll()))); } @@ -114,8 +116,11 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx fcvColl, BSON("_id" << FeatureCompatibilityVersionParser::kParameterName), featureCompatibilityVersion)) { - log() << "Re-creating featureCompatibilityVersion document that was deleted with version " - << FeatureCompatibilityVersionParser::kVersion42 << "."; + LOGV2(21000, + "Re-creating featureCompatibilityVersion document that was deleted with version " + "{FeatureCompatibilityVersionParser_kVersion42}.", + "FeatureCompatibilityVersionParser_kVersion42"_attr = + FeatureCompatibilityVersionParser::kVersion42); BSONObj fcvObj = BSON("_id" << FeatureCompatibilityVersionParser::kParameterName << FeatureCompatibilityVersionParser::kVersionField @@ -224,11 +229,15 @@ Status ensureCollectionProperties(OperationContext* opCtx, // does not exist before attempting to build it or returning an error. if (requiresIndex && !hasAutoIndexIdField && !checkIdIndexExists(opCtx, coll->getCatalogId())) { - log() << "collection " << coll->ns() << " is missing an _id index; building it now"; + LOGV2(21001, + "collection {coll_ns} is missing an _id index; building it now", + "coll_ns"_attr = coll->ns()); auto status = buildMissingIdIndex(opCtx, coll); if (!status.isOK()) { - error() << "could not build an _id index on collection " << coll->ns() << ": " - << status; + LOGV2_ERROR(21021, + "could not build an _id index on collection {coll_ns}: {status}", + "coll_ns"_attr = coll->ns(), + "status"_attr = status); return downgradeError; } } @@ -259,8 +268,10 @@ void checkForCappedOplog(OperationContext* opCtx, Database* db) { Collection* oplogCollection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, oplogNss); if (oplogCollection && !oplogCollection->isCapped()) { - severe() << "The oplog collection " << oplogNss - << " is not capped; a capped oplog is a requirement for replication to function."; + LOGV2_FATAL(21022, + "The oplog collection {oplogNss} is not capped; a capped oplog is a " + "requirement for replication to function.", + "oplogNss"_attr = oplogNss); fassertFailedNoTrace(40115); } } @@ -269,12 +280,11 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) { auto reconcileResult = fassert(40593, storageEngine->reconcileCatalogAndIdents(opCtx)); if (!reconcileResult.indexesToRebuild.empty() && serverGlobalParams.indexBuildRetry) { - log() << "note: restart the server with --noIndexBuildRetry " - << "to skip index rebuilds"; + LOGV2(21002, "note: restart the server with --noIndexBuildRetry to skip index rebuilds"); } if (!serverGlobalParams.indexBuildRetry) { - log() << " not rebuilding interrupted indexes"; + LOGV2(21003, " not rebuilding interrupted indexes"); return; } @@ -309,7 +319,10 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) { auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, collNss); for (const auto& indexName : entry.second.first) { - log() << "Rebuilding index. Collection: " << collNss << " Index: " << indexName; + LOGV2(21004, + "Rebuilding index. Collection: {collNss} Index: {indexName}", + "collNss"_attr = collNss, + "indexName"_attr = indexName); } std::vector<BSONObj> indexSpecs = entry.second.second; @@ -321,7 +334,7 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) { // Therefore, when a replica set member is started in standalone mode, we cannot restart the // index build. if (getReplSetMemberInStandaloneMode(opCtx->getServiceContext())) { - log() << "Not restarting unfinished index builds because we are in standalone mode"; + LOGV2(21005, "Not restarting unfinished index builds because we are in standalone mode"); return; } @@ -388,7 +401,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { invariant(!storageGlobalParams.readOnly); if (MONGO_unlikely(exitBeforeDataRepair.shouldFail())) { - log() << "Exiting because 'exitBeforeDataRepair' fail point was set."; + LOGV2(21006, "Exiting because 'exitBeforeDataRepair' fail point was set."); quickExit(EXIT_ABRUPT); } @@ -402,7 +415,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { } for (const auto& dbName : dbNames) { - LOG(1) << " Repairing database: " << dbName; + LOGV2_DEBUG(21007, 1, " Repairing database: {dbName}", "dbName"_attr = dbName); fassertNoTrace(18506, repairDatabase(opCtx, storageEngine, dbName)); } @@ -447,7 +460,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { if (storageGlobalParams.repair) { if (MONGO_unlikely(exitBeforeRepairInvalidatesConfig.shouldFail())) { - log() << "Exiting because 'exitBeforeRepairInvalidatesConfig' fail point was set."; + LOGV2(21008, "Exiting because 'exitBeforeRepairInvalidatesConfig' fail point was set."); quickExit(EXIT_ABRUPT); } // This must be done after opening the "local" database as it modifies the replica set @@ -455,23 +468,28 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { auto repairObserver = StorageRepairObserver::get(opCtx->getServiceContext()); repairObserver->onRepairDone(opCtx); if (repairObserver->getModifications().size() > 0) { - warning() << "Modifications made by repair:"; + LOGV2_WARNING(21018, "Modifications made by repair:"); const auto& mods = repairObserver->getModifications(); for (const auto& mod : mods) { - warning() << " " << mod.getDescription(); + LOGV2_WARNING(21019, + " {mod_getDescription}", + "mod_getDescription"_attr = mod.getDescription()); } } if (repairObserver->isDataInvalidated()) { if (hasReplSetConfigDoc(opCtx)) { - warning() << "WARNING: Repair may have modified replicated data. This node will no " - "longer be able to join a replica set without a full re-sync"; + LOGV2_WARNING( + 21020, + "WARNING: Repair may have modified replicated data. This node will no " + "longer be able to join a replica set without a full re-sync"); } } // There were modifications, but only benign ones. if (repairObserver->getModifications().size() > 0 && !repairObserver->isDataInvalidated()) { - log() << "Repair has made modifications to unreplicated data. The data is healthy and " - "the node is eligible to be returned to the replica set."; + LOGV2(21009, + "Repair has made modifications to unreplicated data. The data is healthy and " + "the node is eligible to be returned to the replica set."); } } @@ -504,7 +522,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { if (dbName != "local") { nonLocalDatabases = true; } - LOG(1) << " Recovering database: " << dbName; + LOGV2_DEBUG(21010, 1, " Recovering database: {dbName}", "dbName"_attr = dbName); auto db = databaseHolder->openDb(opCtx, dbName); invariant(db); @@ -521,11 +539,13 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { // current version of mongod with --repair and then proceed with normal startup. status = {ErrorCodes::MustUpgrade, status.reason()}; } - severe() << "Unable to start mongod due to an incompatibility with the data files and" - " this version of mongod: " - << redact(status); - severe() << "Please consult our documentation when trying to downgrade to a previous" - " major release"; + LOGV2_FATAL(21023, + "Unable to start mongod due to an incompatibility with the data files and" + " this version of mongod: {status}", + "status"_attr = redact(status)); + LOGV2_FATAL(21024, + "Please consult our documentation when trying to downgrade to a previous" + " major release"); quickExit(EXIT_NEED_UPGRADE); MONGO_UNREACHABLE; } @@ -566,23 +586,39 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { // warning. if (version == ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo44) { - log() << "** WARNING: A featureCompatibilityVersion upgrade did not " - << "complete. " << startupWarningsLog; - log() << "** The current featureCompatibilityVersion is " - << FeatureCompatibilityVersionParser::toString(version) << "." - << startupWarningsLog; - log() << "** To fix this, use the setFeatureCompatibilityVersion " - << "command to resume upgrade to 4.4." << startupWarningsLog; + LOGV2_OPTIONS( + 21011, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: A featureCompatibilityVersion upgrade did not complete. "); + LOGV2_OPTIONS(21012, + {logv2::LogTag::kStartupWarnings}, + "** The current featureCompatibilityVersion is " + "{FeatureCompatibilityVersionParser_version}.", + "FeatureCompatibilityVersionParser_version"_attr = + FeatureCompatibilityVersionParser::toString(version)); + LOGV2_OPTIONS( + 21013, + {logv2::LogTag::kStartupWarnings}, + "** To fix this, use the setFeatureCompatibilityVersion " + "command to resume upgrade to 4.4."); } else if (version == ServerGlobalParams::FeatureCompatibility::Version:: kDowngradingTo42) { - log() << "** WARNING: A featureCompatibilityVersion downgrade did not " - << "complete. " << startupWarningsLog; - log() << "** The current featureCompatibilityVersion is " - << FeatureCompatibilityVersionParser::toString(version) << "." - << startupWarningsLog; - log() << "** To fix this, use the setFeatureCompatibilityVersion " - << "command to resume downgrade to 4.2." << startupWarningsLog; + LOGV2_OPTIONS(21014, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: A featureCompatibilityVersion downgrade did not " + "complete. "); + LOGV2_OPTIONS(21015, + {logv2::LogTag::kStartupWarnings}, + "** The current featureCompatibilityVersion is " + "{FeatureCompatibilityVersionParser_version}.", + "FeatureCompatibilityVersionParser_version"_attr = + FeatureCompatibilityVersionParser::toString(version)); + LOGV2_OPTIONS( + 21016, + {logv2::LogTag::kStartupWarnings}, + "** To fix this, use the setFeatureCompatibilityVersion " + "command to resume downgrade to 4.2."); } } } @@ -614,13 +650,14 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) { // Fail to start up if there is no featureCompatibilityVersion document and there are non-local // databases present and we do not need to start up via initial sync. if (!fcvDocumentExists && nonLocalDatabases && !needInitialSync) { - severe() - << "Unable to start up mongod due to missing featureCompatibilityVersion document."; - severe() << "Please run with --repair to restore the document."; + LOGV2_FATAL( + 21025, + "Unable to start up mongod due to missing featureCompatibilityVersion document."); + LOGV2_FATAL(21026, "Please run with --repair to restore the document."); fassertFailedNoTrace(40652); } - LOG(1) << "done repairDatabases"; + LOGV2_DEBUG(21017, 1, "done repairDatabases"); return nonLocalDatabases; } diff --git a/src/mongo/db/repl/abstract_oplog_fetcher.cpp b/src/mongo/db/repl/abstract_oplog_fetcher.cpp index 56a5fb710dd..c9bfaace0e9 100644 --- a/src/mongo/db/repl/abstract_oplog_fetcher.cpp +++ b/src/mongo/db/repl/abstract_oplog_fetcher.cpp @@ -40,6 +40,7 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/jsobj.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -211,8 +212,12 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result, Status responseStatus = _checkForShutdownAndConvertStatus(result.getStatus(), "error in fetcher batch callback"); if (ErrorCodes::CallbackCanceled == responseStatus) { - LOG(1) << _getComponentName() << " oplog query cancelled to " << _getSource() << ": " - << redact(responseStatus); + LOGV2_DEBUG(21032, + 1, + "{getComponentName} oplog query cancelled to {getSource}: {responseStatus}", + "getComponentName"_attr = _getComponentName(), + "getSource"_attr = _getSource(), + "responseStatus"_attr = redact(responseStatus)); _finishCallback(responseStatus); return; } @@ -235,11 +240,16 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result, auto scheduleStatus = _scheduleFetcher_inlock(); if (scheduleStatus.isOK()) { - log() << "Scheduled new oplog query " << _fetcher->toString(); + LOGV2(21033, + "Scheduled new oplog query {fetcher}", + "fetcher"_attr = _fetcher->toString()); return; } - error() << "Error scheduling new oplog query: " << redact(scheduleStatus) - << ". Returning current oplog query error: " << redact(responseStatus); + LOGV2_ERROR(21037, + "Error scheduling new oplog query: {scheduleStatus}. Returning current " + "oplog query error: {responseStatus}", + "scheduleStatus"_attr = redact(scheduleStatus), + "responseStatus"_attr = redact(responseStatus)); } } _finishCallback(responseStatus); @@ -290,8 +300,11 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result, return; } auto lastDoc = lastDocRes.getValue(); - LOG(3) << _getComponentName() - << " setting last fetched optime ahead after batch: " << lastDoc; + LOGV2_DEBUG(21034, + 3, + "{getComponentName} setting last fetched optime ahead after batch: {lastDoc}", + "getComponentName"_attr = _getComponentName(), + "lastDoc"_attr = lastDoc); stdx::lock_guard<Latch> lock(_mutex); _lastFetched = lastDoc; @@ -348,13 +361,18 @@ std::unique_ptr<Fetcher> AbstractOplogFetcher::_makeFetcher(const BSONObj& findC bool AbstractOplogFetcher::OplogFetcherRestartDecisionDefault::shouldContinue( AbstractOplogFetcher* fetcher, Status status) { if (_fetcherRestarts == _maxFetcherRestarts) { - log() << "Error returned from oplog query (no more query restarts left): " - << redact(status); + LOGV2(21035, + "Error returned from oplog query (no more query restarts left): {status}", + "status"_attr = redact(status)); return false; } - log() << "Restarting oplog query due to error: " << redact(status) - << ". Last fetched optime: " << fetcher->_getLastOpTimeFetched() - << ". Restarts remaining: " << (_maxFetcherRestarts - _fetcherRestarts); + LOGV2( + 21036, + "Restarting oplog query due to error: {status}. Last fetched optime: " + "{fetcher_getLastOpTimeFetched}. Restarts remaining: {maxFetcherRestarts_fetcherRestarts}", + "status"_attr = redact(status), + "fetcher_getLastOpTimeFetched"_attr = fetcher->_getLastOpTimeFetched(), + "maxFetcherRestarts_fetcherRestarts"_attr = (_maxFetcherRestarts - _fetcherRestarts)); _fetcherRestarts++; return true; } diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp b/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp index 7c35e08ab76..5fe87c8530c 100644 --- a/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <memory> @@ -35,8 +37,10 @@ #include "mongo/db/repl/abstract_oplog_fetcher_test_fixture.h" #include "mongo/db/repl/oplog_entry.h" #include "mongo/db/repl/task_executor_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/task_executor_proxy.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" #include "mongo/util/scopeguard.h" namespace { @@ -300,20 +304,20 @@ TEST_F(AbstractOplogFetcherTest, OplogFetcherStopsRestartingFetcherIfRestartLimi ASSERT_OK(oplogFetcher.startup()); - unittest::log() << "processing find request from first fetcher"; + LOGV2(21038, "processing find request from first fetcher"); _assertFindCommandTimestampEquals( ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true)); - unittest::log() << "sending error response to getMore request from first fetcher"; + LOGV2(21039, "sending error response to getMore request from first fetcher"); assertRemoteCommandNameEquals( "getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "fail 1"}, true)); - unittest::log() << "sending error response to find request from second fetcher"; + LOGV2(21040, "sending error response to find request from second fetcher"); _assertFindCommandTimestampEquals( ops[2], processNetworkResponse({ErrorCodes::IllegalOperation, "fail 2"}, true)); - unittest::log() << "sending error response to find request from third fetcher"; + LOGV2(21041, "sending error response to find request from third fetcher"); _assertFindCommandTimestampEquals( ops[2], processNetworkResponse({ErrorCodes::OperationFailed, "fail 3"}, false)); @@ -335,28 +339,28 @@ TEST_F(AbstractOplogFetcherTest, OplogFetcherResetsRestartCounterOnSuccessfulFet ASSERT_OK(oplogFetcher.startup()); - unittest::log() << "processing find request from first fetcher"; + LOGV2(21042, "processing find request from first fetcher"); _assertFindCommandTimestampEquals( ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true)); - unittest::log() << "sending error response to getMore request from first fetcher"; + LOGV2(21043, "sending error response to getMore request from first fetcher"); assertRemoteCommandNameEquals( "getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "fail 1"}, true)); - unittest::log() << "processing find request from second fetcher"; + LOGV2(21044, "processing find request from second fetcher"); _assertFindCommandTimestampEquals( ops[2], processNetworkResponse({makeCursorResponse(1, {ops[2], ops[3], ops[4]})}, true)); - unittest::log() << "sending error response to getMore request from second fetcher"; + LOGV2(21045, "sending error response to getMore request from second fetcher"); assertRemoteCommandNameEquals( "getMore", processNetworkResponse({ErrorCodes::IllegalOperation, "fail 2"}, true)); - unittest::log() << "sending error response to find request from third fetcher"; + LOGV2(21046, "sending error response to find request from third fetcher"); _assertFindCommandTimestampEquals( ops[4], processNetworkResponse({ErrorCodes::InternalError, "fail 3"}, true)); - unittest::log() << "sending error response to find request from fourth fetcher"; + LOGV2(21047, "sending error response to find request from fourth fetcher"); _assertFindCommandTimestampEquals( ops[4], processNetworkResponse({ErrorCodes::OperationFailed, "fail 4"}, false)); @@ -406,12 +410,12 @@ TEST_F(AbstractOplogFetcherTest, ASSERT_OK(oplogFetcher.startup()); ASSERT_TRUE(oplogFetcher.isActive()); - unittest::log() << "processing find request from first fetcher"; + LOGV2(21048, "processing find request from first fetcher"); _assertFindCommandTimestampEquals( ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true)); - unittest::log() << "sending error response to getMore request from first fetcher"; + LOGV2(21049, "sending error response to getMore request from first fetcher"); shouldFailSchedule = true; assertRemoteCommandNameEquals( "getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "dead cursor"}, false)); diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp index 9f748b283c5..68d8e861ddd 100644 --- a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp +++ b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp @@ -27,13 +27,17 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/repl/abstract_oplog_fetcher_test_fixture.h" #include "mongo/db/repl/oplog_entry.h" #include "mongo/executor/thread_pool_task_executor_test_fixture.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace mongo { namespace repl { @@ -119,13 +123,13 @@ executor::RemoteCommandRequest AbstractOplogFetcherTest::processNetworkResponse( auto net = getNet(); executor::NetworkInterfaceMock::InNetworkGuard guard(net); - unittest::log() << "scheduling response."; + LOGV2(21050, "scheduling response."); auto request = net->scheduleSuccessfulResponse(response); - unittest::log() << "running network ops."; + LOGV2(21051, "running network ops."); net->runReadyNetworkOperations(); - unittest::log() << "checking for more requests"; + LOGV2(21052, "checking for more requests"); ASSERT_EQUALS(expectReadyRequestsAfterProcessing, net->hasReadyRequests()); - unittest::log() << "returning consumed request"; + LOGV2(21053, "returning consumed request"); return request; } diff --git a/src/mongo/db/repl/all_database_cloner.cpp b/src/mongo/db/repl/all_database_cloner.cpp index c9c1345e982..ca47cac6aef 100644 --- a/src/mongo/db/repl/all_database_cloner.cpp +++ b/src/mongo/db/repl/all_database_cloner.cpp @@ -35,6 +35,7 @@ #include "mongo/base/string_data.h" #include "mongo/db/repl/all_database_cloner.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" namespace mongo { @@ -56,7 +57,7 @@ BaseCloner::ClonerStages AllDatabaseCloner::getStages() { Status AllDatabaseCloner::ensurePrimaryOrSecondary( const executor::RemoteCommandResponse& isMasterReply) { if (!isMasterReply.isOK()) { - log() << "Cannot reconnect because isMaster command failed."; + LOGV2(21054, "Cannot reconnect because isMaster command failed."); return isMasterReply.status; } if (isMasterReply.data["ismaster"].trueValue() || isMasterReply.data["secondary"].trueValue()) @@ -104,14 +105,19 @@ BaseCloner::AfterStageBehavior AllDatabaseCloner::listDatabasesStage() { auto databasesArray = getClient()->getDatabaseInfos(BSONObj(), true /* nameOnly */); for (const auto& dbBSON : databasesArray) { if (!dbBSON.hasField("name")) { - LOG(1) << "Excluding database due to the 'listDatabases' response not containing a " - "'name' field for this entry: " - << dbBSON; + LOGV2_DEBUG(21055, + 1, + "Excluding database due to the 'listDatabases' response not containing a " + "'name' field for this entry: {dbBSON}", + "dbBSON"_attr = dbBSON); continue; } const auto& dbName = dbBSON["name"].str(); if (dbName == "local") { - LOG(1) << "Excluding database from the 'listDatabases' response: " << dbBSON; + LOGV2_DEBUG(21056, + 1, + "Excluding database from the 'listDatabases' response: {dbBSON}", + "dbBSON"_attr = dbBSON); continue; } else { _databases.emplace_back(dbName); @@ -146,15 +152,24 @@ void AllDatabaseCloner::postStage() { } auto dbStatus = _currentDatabaseCloner->run(); if (dbStatus.isOK()) { - LOG(1) << "Database clone for '" << dbName << "' finished: " << dbStatus; + LOGV2_DEBUG(21057, + 1, + "Database clone for '{dbName}' finished: {dbStatus}", + "dbName"_attr = dbName, + "dbStatus"_attr = dbStatus); } else { - warning() << "database '" << dbName << "' (" << (_stats.databasesCloned + 1) << " of " - << _databases.size() << ") clone failed due to " << dbStatus.toString(); + LOGV2_WARNING(21060, + "database '{dbName}' ({stats_databasesCloned_1} of {databases_size}) " + "clone failed due to {dbStatus}", + "dbName"_attr = dbName, + "stats_databasesCloned_1"_attr = (_stats.databasesCloned + 1), + "databases_size"_attr = _databases.size(), + "dbStatus"_attr = dbStatus.toString()); setInitialSyncFailedStatus(dbStatus); return; } if (StringData(dbName).equalCaseInsensitive("admin")) { - LOG(1) << "Finished the 'admin' db, now validating it."; + LOGV2_DEBUG(21058, 1, "Finished the 'admin' db, now validating it."); // Do special checks for the admin database because of auth. collections. auto adminStatus = Status(ErrorCodes::NotYetInitialized, ""); { @@ -167,7 +182,10 @@ void AllDatabaseCloner::postStage() { adminStatus = getStorageInterface()->isAdminDbValid(opCtx); } if (!adminStatus.isOK()) { - LOG(1) << "Validation failed on 'admin' db due to " << adminStatus; + LOGV2_DEBUG(21059, + 1, + "Validation failed on 'admin' db due to {adminStatus}", + "adminStatus"_attr = adminStatus); setInitialSyncFailedStatus(adminStatus); return; } diff --git a/src/mongo/db/repl/all_database_cloner_test.cpp b/src/mongo/db/repl/all_database_cloner_test.cpp index ffc72c8d2fa..bbbc8a66c67 100644 --- a/src/mongo/db/repl/all_database_cloner_test.cpp +++ b/src/mongo/db/repl/all_database_cloner_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/repl/all_database_cloner.h" @@ -35,9 +37,11 @@ #include "mongo/db/repl/storage_interface_mock.h" #include "mongo/db/service_context_test_fixture.h" #include "mongo/dbtests/mock/mock_dbclient_connection.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" #include "mongo/util/concurrency/thread_pool.h" +#include "mongo/util/log.h" namespace mongo { namespace repl { @@ -114,7 +118,7 @@ TEST_F(AllDatabaseClonerTest, RetriesConnect) { ASSERT_EQ(2, _sharedData->getTotalRetries(WithLock::withoutLock())); // Bring the server up. - unittest::log() << "Bringing mock server back up."; + LOGV2(21061, "Bringing mock server back up."); _mockServer->reboot(); // Allow the cloner to finish. @@ -229,7 +233,7 @@ TEST_F(AllDatabaseClonerTest, RetriesListDatabases) { ASSERT_EQ(2, _sharedData->getTotalRetries(WithLock::withoutLock())); // Bring the server up. - unittest::log() << "Bringing mock server back up."; + LOGV2(21062, "Bringing mock server back up."); _mockServer->reboot(); // Allow the cloner to finish. @@ -277,7 +281,7 @@ TEST_F(AllDatabaseClonerTest, RetriesListDatabasesButRollBackIdChanges) { _mockServer->setCommandReply("replSetGetRBID", fromjson("{ok:1, rbid:2}")); // Bring the server up. - unittest::log() << "Bringing mock server back up."; + LOGV2(21063, "Bringing mock server back up."); _mockServer->reboot(); // Allow the cloner to finish. diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index 2df9c7428be..8f5be92b221 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -55,6 +55,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -266,7 +267,7 @@ Status _applyOps(OperationContext* opCtx, ab.append(status.isOK()); if (!status.isOK()) { - log() << "applyOps error applying: " << status; + LOGV2(21064, "applyOps error applying: {status}", "status"_attr = status); errors++; } diff --git a/src/mongo/db/repl/base_cloner.cpp b/src/mongo/db/repl/base_cloner.cpp index 68411039509..99b38605c4f 100644 --- a/src/mongo/db/repl/base_cloner.cpp +++ b/src/mongo/db/repl/base_cloner.cpp @@ -32,6 +32,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/repl/base_cloner.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -91,8 +92,10 @@ Status BaseCloner::run() { } stdx::lock_guard<InitialSyncSharedData> lk(*_sharedData); if (!_sharedData->getInitialSyncStatus(lk).isOK()) { - log() << "Failing data clone because initial sync failed outside data clone: " - << _sharedData->getInitialSyncStatus(lk); + LOGV2(21065, + "Failing data clone because initial sync failed outside data clone: " + "{sharedData_getInitialSyncStatus_lk}", + "sharedData_getInitialSyncStatus_lk"_attr = _sharedData->getInitialSyncStatus(lk)); } return _sharedData->getInitialSyncStatus(lk); } @@ -116,13 +119,14 @@ void BaseCloner::pauseForFuzzer(BaseClonerStage* stage) { // nb: This log message is specifically checked for in // initial_sync_test_fixture_test.js, so if you change it here you will need to change // it there. - log() << "Collection Cloner scheduled a remote command on the " - << describeForFuzzer(stage); - log() << "initialSyncFuzzerSynchronizationPoint1 fail point enabled."; + LOGV2(21066, + "Collection Cloner scheduled a remote command on the {describeForFuzzer_stage}", + "describeForFuzzer_stage"_attr = describeForFuzzer(stage)); + LOGV2(21067, "initialSyncFuzzerSynchronizationPoint1 fail point enabled."); initialSyncFuzzerSynchronizationPoint1.pauseWhileSet(); if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint2.shouldFail())) { - log() << "initialSyncFuzzerSynchronizationPoint2 fail point enabled."; + LOGV2(21068, "initialSyncFuzzerSynchronizationPoint2 fail point enabled."); initialSyncFuzzerSynchronizationPoint2.pauseWhileSet(); } } @@ -130,15 +134,21 @@ void BaseCloner::pauseForFuzzer(BaseClonerStage* stage) { } BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) { - LOG(1) << "Cloner " << getClonerName() << " running stage " << stage->getName(); + LOGV2_DEBUG(21069, + 1, + "Cloner {getClonerName} running stage {stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); pauseForFuzzer(stage); auto isThisStageFailPoint = [this, stage](const BSONObj& data) { return data["stage"].str() == stage->getName() && isMyFailPoint(data); }; hangBeforeClonerStage.executeIf( [&](const BSONObj& data) { - log() << "Cloner " << getClonerName() << " hanging before running stage " - << stage->getName(); + LOGV2(21070, + "Cloner {getClonerName} hanging before running stage {stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); while (!mustExit() && hangBeforeClonerStage.shouldFail(isThisStageFailPoint)) { sleepmillis(100); } @@ -147,14 +157,20 @@ BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) { auto afterStageBehavior = runStageWithRetries(stage); hangAfterClonerStage.executeIf( [&](const BSONObj& data) { - log() << "Cloner " << getClonerName() << " hanging after running stage " - << stage->getName(); + LOGV2(21071, + "Cloner {getClonerName} hanging after running stage {stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); while (!mustExit() && hangAfterClonerStage.shouldFail(isThisStageFailPoint)) { sleepmillis(100); } }, isThisStageFailPoint); - LOG(1) << "Cloner " << getClonerName() << " finished running stage " << stage->getName(); + LOGV2_DEBUG(21072, + 1, + "Cloner {getClonerName} finished running stage {stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); return afterStageBehavior; } @@ -170,7 +186,7 @@ Status BaseCloner::checkRollBackIdIsUnchanged() { if (ErrorCodes::isRetriableError(e)) { auto status = e.toStatus().withContext( ": failed while attempting to retrieve rollBackId after re-connect"); - LOG(1) << status; + LOGV2_DEBUG(21073, 1, "{status}", "status"_attr = status); return status; } throw; @@ -200,16 +216,23 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage* // If lastError is set, this is a retry. hangBeforeRetryingClonerStage.executeIf( [&](const BSONObj& data) { - log() << "Cloner " << getClonerName() << " hanging before retrying stage " - << stage->getName(); + LOGV2( + 21074, + "Cloner {getClonerName} hanging before retrying stage {stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); while (!mustExit() && hangBeforeRetryingClonerStage.shouldFail(isThisStageFailPoint)) { sleepmillis(100); } }, isThisStageFailPoint); - log() << "Initial Sync retrying " << getClonerName() << " stage " - << stage->getName() << " due to " << lastError; + LOGV2(21075, + "Initial Sync retrying {getClonerName} stage {stage_getName} due to " + "{lastError}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName(), + "lastError"_attr = lastError); bool shouldRetry = [&] { stdx::lock_guard<InitialSyncSharedData> lk(*_sharedData); return _sharedData->shouldRetryOperation(lk, &_retryableOp); @@ -225,9 +248,11 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage* } hangBeforeCheckingRollBackIdClonerStage.executeIf( [&](const BSONObj& data) { - log() << "Cloner " << getClonerName() - << " hanging before checking rollBackId for stage " - << stage->getName(); + LOGV2(21076, + "Cloner {getClonerName} hanging before checking rollBackId for stage " + "{stage_getName}", + "getClonerName"_attr = getClonerName(), + "stage_getName"_attr = stage->getName()); while (!mustExit() && hangBeforeCheckingRollBackIdClonerStage.shouldFail( isThisStageFailPoint)) { @@ -248,12 +273,21 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage* } catch (DBException& e) { lastError = e.toStatus(); if (!stage->isTransientError(lastError)) { - log() << "Non-retryable error occured during cloner " << getClonerName() - << " stage " + stage->getName() << ": " << lastError; + LOGV2(21077, + "Non-retryable error occured during cloner " + "{getClonerName}{stage_stage_getName}: {lastError}", + "getClonerName"_attr = getClonerName(), + "stage_stage_getName"_attr = " stage " + stage->getName(), + "lastError"_attr = lastError); throw; } - LOG(1) << "Transient error occured during cloner " << getClonerName() - << " stage " + stage->getName() << ": " << lastError; + LOGV2_DEBUG(21078, + 1, + "Transient error occured during cloner " + "{getClonerName}{stage_stage_getName}: {lastError}", + "getClonerName"_attr = getClonerName(), + "stage_stage_getName"_attr = " stage " + stage->getName(), + "lastError"_attr = lastError); } } } diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index bbe81147ee0..270dc41626c 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -58,6 +58,7 @@ #include "mongo/db/repl/rs_rollback.h" #include "mongo/db/repl/storage_interface.h" #include "mongo/db/s/shard_identity_rollback_notifier.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/util/log.h" @@ -211,12 +212,13 @@ void BackgroundSync::_run() { _runProducer(); } catch (const DBException& e) { std::string msg(str::stream() << "sync producer problem: " << redact(e)); - error() << msg; + LOGV2_ERROR(21125, "{msg}", "msg"_attr = msg); _replCoord->setMyHeartbeatMessage(msg); sleepmillis(100); // sleep a bit to keep from hammering this thread with temp. errors. } catch (const std::exception& e2) { // redact(std::exception&) doesn't work - severe() << "sync producer exception: " << redact(e2.what()); + LOGV2_FATAL( + 21127, "sync producer exception: {e2_what}", "e2_what"_attr = redact(e2.what())); fassertFailed(28546); } } @@ -253,8 +255,9 @@ void BackgroundSync::_runProducer() { void BackgroundSync::_produce() { if (MONGO_unlikely(stopReplProducer.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "bgsync - stopReplProducer fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21079, + "bgsync - stopReplProducer fail point " + "enabled. Blocking until fail point is disabled."); mongo::sleepsecs(1); return; } @@ -296,7 +299,9 @@ void BackgroundSync::_produce() { const auto requiredOpTime = (minValidSaved > _lastOpTimeFetched) ? minValidSaved : OpTime(); lastOpTimeFetched = _lastOpTimeFetched; if (!_syncSourceHost.empty()) { - log() << "Clearing sync source " << _syncSourceHost << " to choose a new one."; + LOGV2(21080, + "Clearing sync source {syncSourceHost} to choose a new one.", + "syncSourceHost"_attr = _syncSourceHost); } _syncSourceHost = HostAndPort(); _syncSourceResolver = std::make_unique<SyncSourceResolver>( @@ -328,14 +333,22 @@ void BackgroundSync::_produce() { if (syncSourceResp.syncSourceStatus == ErrorCodes::OplogStartMissing) { // All (accessible) sync sources are too far ahead of us. if (_replCoord->getMemberState().primary()) { - warning() << "Too stale to catch up."; - log() << "Our newest OpTime : " << lastOpTimeFetched; - log() << "Earliest OpTime available is " << syncSourceResp.earliestOpTimeSeen - << " from " << syncSourceResp.getSyncSource(); + LOGV2_WARNING(21115, "Too stale to catch up."); + LOGV2(21081, + "Our newest OpTime : {lastOpTimeFetched}", + "lastOpTimeFetched"_attr = lastOpTimeFetched); + LOGV2(21082, + "Earliest OpTime available is {syncSourceResp_earliestOpTimeSeen} from " + "{syncSourceResp_getSyncSource}", + "syncSourceResp_earliestOpTimeSeen"_attr = syncSourceResp.earliestOpTimeSeen, + "syncSourceResp_getSyncSource"_attr = syncSourceResp.getSyncSource()); auto status = _replCoord->abortCatchupIfNeeded( ReplicationCoordinator::PrimaryCatchUpConclusionReason::kFailedWithError); if (!status.isOK()) { - LOG(1) << "Aborting catch-up failed with status: " << status; + LOGV2_DEBUG(21083, + 1, + "Aborting catch-up failed with status: {status}", + "status"_attr = status); } return; } @@ -349,22 +362,33 @@ void BackgroundSync::_produce() { auto opCtx = cc().makeOperationContext(); ReplicationStateTransitionLockGuard transitionGuard(opCtx.get(), MODE_X); - error() << "too stale to catch up -- entering maintenance mode"; - log() << "Our newest OpTime : " << lastOpTimeFetched; - log() << "Earliest OpTime available is " << syncSourceResp.earliestOpTimeSeen; - log() << "See http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember"; + LOGV2_ERROR(21126, "too stale to catch up -- entering maintenance mode"); + LOGV2(21084, + "Our newest OpTime : {lastOpTimeFetched}", + "lastOpTimeFetched"_attr = lastOpTimeFetched); + LOGV2(21085, + "Earliest OpTime available is {syncSourceResp_earliestOpTimeSeen}", + "syncSourceResp_earliestOpTimeSeen"_attr = syncSourceResp.earliestOpTimeSeen); + LOGV2(21086, "See http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember"); // Activate maintenance mode and transition to RECOVERING. auto status = _replCoord->setMaintenanceMode(true); if (!status.isOK()) { - warning() << "Failed to transition into maintenance mode: " << status; + LOGV2_WARNING(21116, + "Failed to transition into maintenance mode: {status}", + "status"_attr = status); // Do not mark ourselves too stale on errors so we can try again next time. return; } status = _replCoord->setFollowerMode(MemberState::RS_RECOVERING); if (!status.isOK()) { - warning() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING) - << ". Current state: " << _replCoord->getMemberState() << causedBy(status); + LOGV2_WARNING(21117, + "Failed to transition into {MemberState_MemberState_RS_RECOVERING}. " + "Current state: {replCoord_getMemberState}{causedBy_status}", + "MemberState_MemberState_RS_RECOVERING"_attr = + MemberState(MemberState::RS_RECOVERING), + "replCoord_getMemberState"_attr = _replCoord->getMemberState(), + "causedBy_status"_attr = causedBy(status)); // Do not mark ourselves too stale on errors so we can try again next time. return; } @@ -384,22 +408,31 @@ void BackgroundSync::_produce() { forceBgSyncSyncSourceRetryWaitMS.execute( [&](const BSONObj& data) { sleepMS = data["sleepMS"].numberInt(); }); - log() << "Chose same sync source candidate as last time, " << source - << ". Sleeping for " << sleepMS - << "ms to avoid immediately choosing a new sync source for the same reason as " - "last time."; + LOGV2( + 21087, + "Chose same sync source candidate as last time, {source}. Sleeping for {sleepMS}ms " + "to avoid immediately choosing a new sync source for the same reason as " + "last time.", + "source"_attr = source, + "sleepMS"_attr = sleepMS); numTimesChoseSameSyncSource.increment(1); mongo::sleepmillis(sleepMS); } else { - log() << "Changed sync source from " - << (oldSource.empty() ? std::string("empty") : oldSource.toString()) << " to " - << source; + LOGV2( + 21088, + "Changed sync source from {oldSource_empty_std_string_empty_oldSource} to {source}", + "oldSource_empty_std_string_empty_oldSource"_attr = + (oldSource.empty() ? std::string("empty") : oldSource.toString()), + "source"_attr = source); numTimesChoseDifferentSyncSource.increment(1); } } else { if (!syncSourceResp.isOK()) { - log() << "failed to find sync source, received error " - << syncSourceResp.syncSourceStatus.getStatus(); + LOGV2(21089, + "failed to find sync source, received error " + "{syncSourceResp_syncSourceStatus_getStatus}", + "syncSourceResp_syncSourceStatus_getStatus"_attr = + syncSourceResp.syncSourceStatus.getStatus()); } long long sleepMS = 1000; @@ -407,8 +440,10 @@ void BackgroundSync::_produce() { [&](const BSONObj& data) { sleepMS = data["sleepMS"].numberInt(); }); // No sync source found. - LOG(1) << "Could not find a sync source. Sleeping for " << sleepMS - << "ms before trying again."; + LOGV2_DEBUG(21090, + 1, + "Could not find a sync source. Sleeping for {sleepMS}ms before trying again.", + "sleepMS"_attr = sleepMS); numTimesCouldNotFindSyncSource.increment(1); mongo::sleepmillis(sleepMS); return; @@ -417,10 +452,11 @@ void BackgroundSync::_produce() { // If we find a good sync source after having gone too stale, disable maintenance mode so we can // transition to SECONDARY. if (_tooStale.swap(false)) { - log() << "No longer too stale. Able to sync from " << source; + LOGV2(21091, "No longer too stale. Able to sync from {source}", "source"_attr = source); auto status = _replCoord->setMaintenanceMode(false); if (!status.isOK()) { - warning() << "Failed to leave maintenance mode: " << status; + LOGV2_WARNING( + 21118, "Failed to leave maintenance mode: {status}", "status"_attr = status); } } @@ -484,24 +520,34 @@ void BackgroundSync::_produce() { } const auto logLevel = getTestCommandsEnabled() ? 0 : 1; - LOG(logLevel) << "scheduling fetcher to read remote oplog on " << source << " starting at " - << oplogFetcher->getFindQuery_forTest()["filter"]; + LOGV2_DEBUG(21092, + logSeverityV1toV2(logLevel).toInt(), + "scheduling fetcher to read remote oplog on {source} starting at " + "{oplogFetcher_getFindQuery_forTest_filter}", + "source"_attr = source, + "oplogFetcher_getFindQuery_forTest_filter"_attr = + oplogFetcher->getFindQuery_forTest()["filter"]); auto scheduleStatus = oplogFetcher->startup(); if (!scheduleStatus.isOK()) { - warning() << "unable to schedule fetcher to read remote oplog on " << source << ": " - << scheduleStatus; + LOGV2_WARNING( + 21119, + "unable to schedule fetcher to read remote oplog on {source}: {scheduleStatus}", + "source"_attr = source, + "scheduleStatus"_attr = scheduleStatus); return; } oplogFetcher->join(); - LOG(1) << "fetcher stopped reading remote oplog on " << source; + LOGV2_DEBUG( + 21093, 1, "fetcher stopped reading remote oplog on {source}", "source"_attr = source); // If the background sync is stopped after the fetcher is started, we need to // re-evaluate our sync source and oplog common point. if (getState() != ProducerState::Running) { - log() << "Replication producer stopped after oplog fetcher finished returning a batch from " - "our sync source. Abandoning this batch of oplog entries and re-evaluating our " - "sync source."; + LOGV2(21094, + "Replication producer stopped after oplog fetcher finished returning a batch from " + "our sync source. Abandoning this batch of oplog entries and re-evaluating our " + "sync source."); return; } @@ -509,7 +555,9 @@ void BackgroundSync::_produce() { // This is bad because it means that our source // has not returned oplog entries in ascending ts order, and they need to be. - warning() << redact(fetcherReturnStatus); + LOGV2_WARNING(21120, + "{fetcherReturnStatus}", + "fetcherReturnStatus"_attr = redact(fetcherReturnStatus)); // Do not blacklist the server here, it will be blacklisted when we try to reuse it, // if it can't return a matching oplog start from the last fetch oplog ts field. return; @@ -520,19 +568,23 @@ void BackgroundSync::_produce() { opCtx.get(), fetcherReturnStatus, source, syncSourceResp.rbid, storageInterface); if (bgSyncHangAfterRunRollback.shouldFail()) { - log() << "bgSyncHangAfterRunRollback failpoint is set."; + LOGV2(21095, "bgSyncHangAfterRunRollback failpoint is set."); while (MONGO_unlikely(bgSyncHangAfterRunRollback.shouldFail()) && !inShutdown()) { mongo::sleepmillis(100); } } } else if (fetcherReturnStatus == ErrorCodes::InvalidBSON) { Seconds blacklistDuration(60); - warning() << "Fetcher got invalid BSON while querying oplog. Blacklisting sync source " - << source << " for " << blacklistDuration << "."; + LOGV2_WARNING(21121, + "Fetcher got invalid BSON while querying oplog. Blacklisting sync source " + "{source} for {blacklistDuration}.", + "source"_attr = source, + "blacklistDuration"_attr = blacklistDuration); _replCoord->blacklistSyncSource(source, Date_t::now() + blacklistDuration); } else if (!fetcherReturnStatus.isOK()) { - warning() << "Fetcher stopped querying remote oplog with error: " - << redact(fetcherReturnStatus); + LOGV2_WARNING(21122, + "Fetcher stopped querying remote oplog with error: {fetcherReturnStatus}", + "fetcherReturnStatus"_attr = redact(fetcherReturnStatus)); } } @@ -564,7 +616,10 @@ Status BackgroundSync::_enqueueDocuments(Fetcher::Documents::const_iterator begi // Update last fetched info. _lastOpTimeFetched = info.lastDocument; - LOG(3) << "batch resetting _lastOpTimeFetched: " << _lastOpTimeFetched; + LOGV2_DEBUG(21096, + 3, + "batch resetting _lastOpTimeFetched: {lastOpTimeFetched}", + "lastOpTimeFetched"_attr = _lastOpTimeFetched); } // Check some things periodically (whenever we run out of items in the current cursor batch). @@ -587,11 +642,13 @@ void BackgroundSync::_runRollback(OperationContext* opCtx, int requiredRBID, StorageInterface* storageInterface) { if (_replCoord->getMemberState().primary()) { - warning() << "Rollback situation detected in catch-up mode. Aborting catch-up mode."; + LOGV2_WARNING(21123, + "Rollback situation detected in catch-up mode. Aborting catch-up mode."); auto status = _replCoord->abortCatchupIfNeeded( ReplicationCoordinator::PrimaryCatchUpConclusionReason::kFailedWithError); if (!status.isOK()) { - LOG(1) << "Aborting catch-up failed with status: " << status; + LOGV2_DEBUG( + 21097, 1, "Aborting catch-up failed with status: {status}", "status"_attr = status); } return; } @@ -610,8 +667,12 @@ void BackgroundSync::_runRollback(OperationContext* opCtx, lastOpTimeFetched = _lastOpTimeFetched; } - log() << "Starting rollback due to " << redact(fetcherReturnStatus); - log() << "Replication commit point: " << _replCoord->getLastCommittedOpTime(); + LOGV2(21098, + "Starting rollback due to {fetcherReturnStatus}", + "fetcherReturnStatus"_attr = redact(fetcherReturnStatus)); + LOGV2(21099, + "Replication commit point: {replCoord_getLastCommittedOpTime}", + "replCoord_getLastCommittedOpTime"_attr = _replCoord->getLastCommittedOpTime()); // TODO: change this to call into the Applier directly to block until the applier is // drained. @@ -619,8 +680,11 @@ void BackgroundSync::_runRollback(OperationContext* opCtx, // Wait till all buffered oplog entries have drained and been applied. auto lastApplied = _replCoord->getMyLastAppliedOpTime(); if (lastApplied != lastOpTimeFetched) { - log() << "Waiting for all operations from " << lastApplied << " until " << lastOpTimeFetched - << " to be applied before starting rollback."; + LOGV2(21100, + "Waiting for all operations from {lastApplied} until {lastOpTimeFetched} to be " + "applied before starting rollback.", + "lastApplied"_attr = lastApplied, + "lastOpTimeFetched"_attr = lastOpTimeFetched); while (lastOpTimeFetched > (lastApplied = _replCoord->getMyLastAppliedOpTime())) { sleepmillis(10); if (getState() != ProducerState::Running) { @@ -631,8 +695,9 @@ void BackgroundSync::_runRollback(OperationContext* opCtx, if (MONGO_unlikely(rollbackHangBeforeStart.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "rollback - rollbackHangBeforeStart fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21101, + "rollback - rollbackHangBeforeStart fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(rollbackHangBeforeStart.shouldFail()) && !inShutdown()) { mongo::sleepsecs(1); } @@ -659,11 +724,11 @@ void BackgroundSync::_runRollback(OperationContext* opCtx, auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); if (!forceRollbackViaRefetch.load() && storageEngine->supportsRecoverToStableTimestamp()) { - log() << "Rollback using 'recoverToStableTimestamp' method."; + LOGV2(21102, "Rollback using 'recoverToStableTimestamp' method."); _runRollbackViaRecoverToCheckpoint( opCtx, source, &localOplog, storageInterface, getConnection); } else { - log() << "Rollback using the 'rollbackViaRefetch' method."; + LOGV2(21103, "Rollback using the 'rollbackViaRefetch' method."); _fallBackOnRollbackViaRefetch( opCtx, source, abortedIndexBuilds, requiredRBID, &localOplog, getConnection); } @@ -695,15 +760,17 @@ void BackgroundSync::_runRollbackViaRecoverToCheckpoint( _rollback = std::make_unique<RollbackImpl>( localOplog, &remoteOplog, storageInterface, _replicationProcess, _replCoord); - log() << "Scheduling rollback (sync source: " << source << ")"; + LOGV2(21104, "Scheduling rollback (sync source: {source})", "source"_attr = source); auto status = _rollback->runRollback(opCtx); if (status.isOK()) { - log() << "Rollback successful."; + LOGV2(21105, "Rollback successful."); } else if (status == ErrorCodes::UnrecoverableRollbackError) { - severe() << "Rollback failed with unrecoverable error: " << status; + LOGV2_FATAL( + 21128, "Rollback failed with unrecoverable error: {status}", "status"_attr = status); fassertFailedWithStatusNoTrace(50666, status); } else { - warning() << "Rollback failed with retryable error: " << status; + LOGV2_WARNING( + 21124, "Rollback failed with retryable error: {status}", "status"_attr = status); } } @@ -736,7 +803,9 @@ HostAndPort BackgroundSync::getSyncTarget() const { void BackgroundSync::clearSyncTarget() { stdx::unique_lock<Latch> lock(_mutex); - log() << "Resetting sync source to empty, which was " << _syncSourceHost; + LOGV2(21106, + "Resetting sync source to empty, which was {syncSourceHost}", + "syncSourceHost"_attr = _syncSourceHost); _syncSourceHost = HostAndPort(); } @@ -744,13 +813,13 @@ void BackgroundSync::stop(bool resetLastFetchedOptime) { stdx::lock_guard<Latch> lock(_mutex); _state = ProducerState::Stopped; - log() << "Stopping replication producer"; + LOGV2(21107, "Stopping replication producer"); _syncSourceHost = HostAndPort(); if (resetLastFetchedOptime) { invariant(_oplogApplier->getBuffer()->isEmpty()); _lastOpTimeFetched = OpTime(); - log() << "Resetting last fetched optimes in bgsync"; + LOGV2(21108, "Resetting last fetched optimes in bgsync"); } if (_syncSourceResolver) { @@ -779,21 +848,28 @@ void BackgroundSync::start(OperationContext* opCtx) { // If a node steps down during drain mode, then the buffer may not be empty at the beginning // of secondary state. if (!_oplogApplier->getBuffer()->isEmpty()) { - log() << "going to start syncing, but buffer is not empty"; + LOGV2(21109, "going to start syncing, but buffer is not empty"); } _state = ProducerState::Running; // When a node steps down during drain mode, the last fetched optime would be newer than // the last applied. if (_lastOpTimeFetched <= lastAppliedOpTime) { - LOG(1) << "Setting bgsync _lastOpTimeFetched=" << lastAppliedOpTime - << ". Previous _lastOpTimeFetched: " << _lastOpTimeFetched; + LOGV2_DEBUG(21110, + 1, + "Setting bgsync _lastOpTimeFetched={lastAppliedOpTime}. Previous " + "_lastOpTimeFetched: {lastOpTimeFetched}", + "lastAppliedOpTime"_attr = lastAppliedOpTime, + "lastOpTimeFetched"_attr = _lastOpTimeFetched); _lastOpTimeFetched = lastAppliedOpTime; } // Reload the last applied optime from disk if it has been changed. } while (lastAppliedOpTime != _replCoord->getMyLastAppliedOpTime()); - LOG(1) << "bgsync fetch queue set to: " << _lastOpTimeFetched; + LOGV2_DEBUG(21111, + 1, + "bgsync fetch queue set to: {lastOpTimeFetched}", + "lastOpTimeFetched"_attr = _lastOpTimeFetched); } OpTime BackgroundSync::_readLastAppliedOpTime(OperationContext* opCtx) { @@ -812,27 +888,35 @@ OpTime BackgroundSync::_readLastAppliedOpTime(OperationContext* opCtx) { } catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) { throw; } catch (const DBException& ex) { - severe() << "Problem reading " << NamespaceString::kRsOplogNamespace.ns() << ": " - << redact(ex); + LOGV2_FATAL(21129, + "Problem reading {NamespaceString_kRsOplogNamespace_ns}: {ex}", + "NamespaceString_kRsOplogNamespace_ns"_attr = + NamespaceString::kRsOplogNamespace.ns(), + "ex"_attr = redact(ex)); fassertFailed(18904); } OplogEntry parsedEntry(oplogEntry); - LOG(1) << "Successfully read last entry of oplog while starting bgsync: " << redact(oplogEntry); + LOGV2_DEBUG(21112, + 1, + "Successfully read last entry of oplog while starting bgsync: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry)); return parsedEntry.getOpTime(); } bool BackgroundSync::shouldStopFetching() const { // Check if we have been stopped. if (getState() != ProducerState::Running) { - LOG(2) << "Stopping oplog fetcher due to stop request."; + LOGV2_DEBUG(21113, 2, "Stopping oplog fetcher due to stop request."); return true; } // Check current sync source. if (getSyncTarget().empty()) { - LOG(1) << "Stopping oplog fetcher; canceling oplog query because we have no valid sync " - "source."; + LOGV2_DEBUG(21114, + 1, + "Stopping oplog fetcher; canceling oplog query because we have no valid sync " + "source."); return true; } diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp index 944776aee8f..08393acd715 100644 --- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp +++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp @@ -45,6 +45,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/collection_bulk_loader_impl.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/destructor_guard.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -212,7 +213,7 @@ Status CollectionBulkLoaderImpl::insertDocuments(const std::vector<BSONObj>::con Status CollectionBulkLoaderImpl::commit() { return _runTaskReleaseResourcesOnFailure([&] { _stats.startBuildingIndexes = Date_t::now(); - LOG(2) << "Creating indexes for ns: " << _nss.ns(); + LOGV2_DEBUG(21130, 2, "Creating indexes for ns: {nss_ns}", "nss_ns"_attr = _nss.ns()); UnreplicatedWritesBlock uwb(_opCtx.get()); // Commit before deleting dups, so the dups will be removed from secondary indexes when @@ -309,7 +310,11 @@ Status CollectionBulkLoaderImpl::commit() { } _stats.endBuildingIndexes = Date_t::now(); - LOG(2) << "Done creating indexes for ns: " << _nss.ns() << ", stats: " << _stats.toString(); + LOGV2_DEBUG(21131, + 2, + "Done creating indexes for ns: {nss_ns}, stats: {stats}", + "nss_ns"_attr = _nss.ns(), + "stats"_attr = _stats.toString()); _releaseResources(); return Status::OK(); diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp index 119239e1acf..8ad5135f5eb 100644 --- a/src/mongo/db/repl/collection_cloner.cpp +++ b/src/mongo/db/repl/collection_cloner.cpp @@ -38,6 +38,7 @@ #include "mongo/db/repl/database_cloner_gen.h" #include "mongo/db/repl/repl_server_parameters_gen.h" #include "mongo/db/wire_version.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -117,9 +118,12 @@ BaseCloner::AfterStageBehavior CollectionCloner::CollectionClonerStage::run() { try { return ClonerStage<CollectionCloner>::run(); } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - log() << "CollectionCloner ns: '" << getCloner()->getSourceNss() << "' uuid: UUID(\"" - << getCloner()->getSourceUuid() - << "\") stopped because collection was dropped on source."; + LOGV2( + 21132, + "CollectionCloner ns: '{getCloner_getSourceNss}' uuid: " + "UUID(\"{getCloner_getSourceUuid}\") stopped because collection was dropped on source.", + "getCloner_getSourceNss"_attr = getCloner()->getSourceNss(), + "getCloner_getSourceUuid"_attr = getCloner()->getSourceUuid()); getCloner()->waitForDatabaseWorkToComplete(); return kSkipRemainingStages; } catch (const DBException&) { @@ -135,8 +139,9 @@ BaseCloner::AfterStageBehavior CollectionCloner::countStage() { // so we set it to zero here to avoid aborting the collection clone. // Note that this count value is only used for reporting purposes. if (count < 0) { - warning() << "Count command returned negative value. Updating to 0 to allow progress " - "meter to function properly. "; + LOGV2_WARNING(21142, + "Count command returned negative value. Updating to 0 to allow progress " + "meter to function properly. "); count = 0; } @@ -151,8 +156,11 @@ BaseCloner::AfterStageBehavior CollectionCloner::countStage() { BaseCloner::AfterStageBehavior CollectionCloner::listIndexesStage() { auto indexSpecs = getClient()->getIndexSpecs(_sourceDbAndUuid, QueryOption_SlaveOk); if (indexSpecs.empty()) { - warning() << "No indexes found for collection " << _sourceNss.ns() << " while cloning from " - << getSource(); + LOGV2_WARNING( + 21143, + "No indexes found for collection {sourceNss_ns} while cloning from {getSource}", + "sourceNss_ns"_attr = _sourceNss.ns(), + "getSource"_attr = getSource()); } for (auto&& spec : indexSpecs) { if (spec["name"].str() == "_id_"_sd) { @@ -167,9 +175,10 @@ BaseCloner::AfterStageBehavior CollectionCloner::listIndexesStage() { }; if (!_idIndexSpec.isEmpty() && _collectionOptions.autoIndexId == CollectionOptions::NO) { - warning() - << "Found the _id_ index spec but the collection specified autoIndexId of false on ns:" - << this->_sourceNss; + LOGV2_WARNING(21144, + "Found the _id_ index spec but the collection specified autoIndexId of false " + "on ns:{this_sourceNss}", + "this_sourceNss"_attr = this->_sourceNss); } return kContinueNormally; } @@ -200,12 +209,12 @@ void CollectionCloner::runQuery() { if (_resumeSupported) { if (_resumeToken) { // Resume the query from where we left off. - LOG(1) << "Collection cloner will resume the last successful query"; + LOGV2_DEBUG(21133, 1, "Collection cloner will resume the last successful query"); query = QUERY("query" << BSONObj() << "$readOnce" << true << "$_requestResumeToken" << true << "$_resumeAfter" << _resumeToken.get()); } else { // New attempt at a resumable query. - LOG(1) << "Collection cloner will run a new query"; + LOGV2_DEBUG(21134, 1, "Collection cloner will run a new query"); query = QUERY("query" << BSONObj() << "$readOnce" << true << "$_requestResumeToken" << true); } @@ -247,7 +256,9 @@ void CollectionCloner::runQuery() { // Collection has changed upstream. This will trigger the code block above next round, // (unless we find out the collection was dropped via getting a NamespaceNotFound). if (_queryStage.isCursorError(status)) { - log() << "Lost cursor during non-resumable query: " << status; + LOGV2(21135, + "Lost cursor during non-resumable query: {status}", + "status"_attr = status); _lostNonResumableCursor = true; throw; } @@ -268,7 +279,7 @@ void CollectionCloner::handleNextBatch(DBClientCursorBatchIterator& iter) { std::string message = str::stream() << "Collection cloning cancelled due to initial sync failure: " << getSharedData()->getInitialSyncStatus(lk).toString(); - log() << message; + LOGV2(21136, "{message}", "message"_attr = message); uasserted(ErrorCodes::CallbackCanceled, message); } } @@ -316,9 +327,10 @@ void CollectionCloner::handleNextBatch(DBClientCursorBatchIterator& iter) { while (MONGO_unlikely( initialSyncHangCollectionClonerAfterHandlingBatchResponse.shouldFail()) && !mustExit()) { - log() << "initialSyncHangCollectionClonerAfterHandlingBatchResponse fail point " - "enabled for " - << _sourceNss.toString() << ". Blocking until fail point is disabled."; + LOGV2(21137, + "initialSyncHangCollectionClonerAfterHandlingBatchResponse fail point " + "enabled for {sourceNss}. Blocking until fail point is disabled.", + "sourceNss"_attr = _sourceNss.toString()); mongo::sleepsecs(1); } }, @@ -336,8 +348,9 @@ void CollectionCloner::insertDocumentsCallback(const executor::TaskExecutor::Cal stdx::lock_guard<Latch> lk(_mutex); std::vector<BSONObj> docs; if (_documentsToInsert.size() == 0) { - warning() << "insertDocumentsCallback, but no documents to insert for ns:" - << _sourceNss; + LOGV2_WARNING(21145, + "insertDocumentsCallback, but no documents to insert for ns:{sourceNss}", + "sourceNss"_attr = _sourceNss); return; } _documentsToInsert.swap(docs); @@ -353,8 +366,9 @@ void CollectionCloner::insertDocumentsCallback(const executor::TaskExecutor::Cal initialSyncHangDuringCollectionClone.executeIf( [&](const BSONObj&) { - log() << "initial sync - initialSyncHangDuringCollectionClone fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21138, + "initial sync - initialSyncHangDuringCollectionClone fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(initialSyncHangDuringCollectionClone.shouldFail()) && !mustExit()) { mongo::sleepsecs(1); @@ -386,11 +400,11 @@ void CollectionCloner::killOldQueryCursor() { auto id = _remoteCursorId; auto cmdObj = BSON("killCursors" << nss.coll() << "cursors" << BSON_ARRAY(id)); - LOG(1) << "Attempting to kill old remote cursor with id: " << id; + LOGV2_DEBUG(21139, 1, "Attempting to kill old remote cursor with id: {id}", "id"_attr = id); try { getClient()->runCommand(nss.db().toString(), cmdObj, infoObj); } catch (...) { - log() << "Error while trying to kill remote cursor after transient query error"; + LOGV2(21140, "Error while trying to kill remote cursor after transient query error"); } // Clear the stored cursorId on success. @@ -404,7 +418,7 @@ void CollectionCloner::forgetOldQueryCursor() { // Throws. void CollectionCloner::abortNonResumableClone(const Status& status) { invariant(!_resumeSupported); - log() << "Error during non-resumable clone: " << status; + LOGV2(21141, "Error during non-resumable clone: {status}", "status"_attr = status); std::string message = str::stream() << "Collection clone failed and is not resumable. nss: " << _sourceNss; uasserted(ErrorCodes::InitialSyncFailure, message); diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.cpp b/src/mongo/db/repl/data_replicator_external_state_impl.cpp index 33ea1ea0d16..bed866625c6 100644 --- a/src/mongo/db/repl/data_replicator_external_state_impl.cpp +++ b/src/mongo/db/repl/data_replicator_external_state_impl.cpp @@ -43,6 +43,7 @@ #include "mongo/db/repl/replication_coordinator_external_state.h" #include "mongo/db/repl/replication_process.h" #include "mongo/db/repl/storage_interface.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -101,16 +102,22 @@ bool DataReplicatorExternalStateImpl::shouldStopFetching( // If OplogQueryMetadata was provided, its values were used to determine if we should // change sync sources. if (oqMetadata) { - log() << "Canceling oplog query due to OplogQueryMetadata. We have to choose a new " - "sync source. Current source: " - << source << ", OpTime " << oqMetadata->getLastOpApplied() - << ", its sync source index:" << oqMetadata->getSyncSourceIndex(); + LOGV2(21150, + "Canceling oplog query due to OplogQueryMetadata. We have to choose a new " + "sync source. Current source: {source}, OpTime {oqMetadata_getLastOpApplied}, " + "its sync source index:{oqMetadata_getSyncSourceIndex}", + "source"_attr = source, + "oqMetadata_getLastOpApplied"_attr = oqMetadata->getLastOpApplied(), + "oqMetadata_getSyncSourceIndex"_attr = oqMetadata->getSyncSourceIndex()); } else { - log() << "Canceling oplog query due to ReplSetMetadata. We have to choose a new sync " - "source. Current source: " - << source << ", OpTime " << replMetadata.getLastOpVisible() - << ", its sync source index:" << replMetadata.getSyncSourceIndex(); + LOGV2(21151, + "Canceling oplog query due to ReplSetMetadata. We have to choose a new sync " + "source. Current source: {source}, OpTime {replMetadata_getLastOpVisible}, its " + "sync source index:{replMetadata_getSyncSourceIndex}", + "source"_attr = source, + "replMetadata_getLastOpVisible"_attr = replMetadata.getLastOpVisible(), + "replMetadata_getSyncSourceIndex"_attr = replMetadata.getSyncSourceIndex()); } return true; } diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp index d896ee08d0e..5dbabe1cb92 100644 --- a/src/mongo/db/repl/database_cloner.cpp +++ b/src/mongo/db/repl/database_cloner.cpp @@ -35,6 +35,7 @@ #include "mongo/db/commands/list_collections_filter.h" #include "mongo/db/repl/database_cloner.h" #include "mongo/db/repl/database_cloner_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -88,10 +89,13 @@ BaseCloner::AfterStageBehavior DatabaseCloner::listCollectionsStage() { } NamespaceString collectionNamespace(_dbName, result.getName()); if (collectionNamespace.isSystem() && !collectionNamespace.isLegalClientSystemNS()) { - LOG(1) << "Skipping 'system' collection: " << collectionNamespace.ns(); + LOGV2_DEBUG(21146, + 1, + "Skipping 'system' collection: {collectionNamespace_ns}", + "collectionNamespace_ns"_attr = collectionNamespace.ns()); continue; } - LOG(2) << "Allowing cloning of collectionInfo: " << info; + LOGV2_DEBUG(21147, 2, "Allowing cloning of collectionInfo: {info}", "info"_attr = info); bool isDuplicate = seen.insert(result.getName().toString()).second; uassert(51005, @@ -137,10 +141,13 @@ void DatabaseCloner::postStage() { } auto collStatus = _currentCollectionCloner->run(); if (collStatus.isOK()) { - LOG(1) << "collection clone finished: " << sourceNss; + LOGV2_DEBUG( + 21148, 1, "collection clone finished: {sourceNss}", "sourceNss"_attr = sourceNss); } else { - error() << "collection clone for '" << sourceNss << "' failed due to " - << collStatus.toString(); + LOGV2_ERROR(21149, + "collection clone for '{sourceNss}' failed due to {collStatus}", + "sourceNss"_attr = sourceNss, + "collStatus"_attr = collStatus.toString()); setInitialSyncFailedStatus( {ErrorCodes::InitialSyncFailure, collStatus diff --git a/src/mongo/db/repl/drop_pending_collection_reaper.cpp b/src/mongo/db/repl/drop_pending_collection_reaper.cpp index 4c380e4c8c5..cf3e1e54843 100644 --- a/src/mongo/db/repl/drop_pending_collection_reaper.cpp +++ b/src/mongo/db/repl/drop_pending_collection_reaper.cpp @@ -40,6 +40,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/storage_interface.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -89,8 +90,11 @@ void DropPendingCollectionReaper::addDropPendingNamespace( }; if (std::find_if(lowerBound, upperBound, matcher) != upperBound) { - severe() << "Failed to add drop-pending collection " << dropPendingNamespace - << " with drop optime " << dropOpTime << ": duplicate optime and namespace pair."; + LOGV2_FATAL(21156, + "Failed to add drop-pending collection {dropPendingNamespace} with drop optime " + "{dropOpTime}: duplicate optime and namespace pair.", + "dropPendingNamespace"_attr = dropPendingNamespace, + "dropOpTime"_attr = dropOpTime); fassertFailedNoTrace(40448); } @@ -136,16 +140,23 @@ bool DropPendingCollectionReaper::rollBackDropPendingCollection( auto matcher = [&pendingNss](const auto& pair) { return pair.second == pendingNss; }; auto it = std::find_if(lowerBound, upperBound, matcher); if (it == upperBound) { - warning() << "Cannot find drop-pending namespace at OpTime " << opTime - << " for collection " << collectionNamespace << " to roll back."; + LOGV2_WARNING(21154, + "Cannot find drop-pending namespace at OpTime {opTime} for collection " + "{collectionNamespace} to roll back.", + "opTime"_attr = opTime, + "collectionNamespace"_attr = collectionNamespace); return false; } _dropPendingNamespaces.erase(it); } - log() << "Rolling back collection drop for " << pendingNss << " with drop OpTime " << opTime - << " to namespace " << collectionNamespace; + LOGV2(21152, + "Rolling back collection drop for {pendingNss} with drop OpTime {opTime} to namespace " + "{collectionNamespace}", + "pendingNss"_attr = pendingNss, + "opTime"_attr = opTime, + "collectionNamespace"_attr = collectionNamespace); return true; } @@ -174,8 +185,12 @@ void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opC for (const auto& opTimeAndNamespace : toDrop) { const auto& dropOpTime = opTimeAndNamespace.first; const auto& nss = opTimeAndNamespace.second; - log() << "Completing collection drop for " << nss << " with drop optime " << dropOpTime - << " (notification optime: " << opTime << ")"; + LOGV2(21153, + "Completing collection drop for {nss} with drop optime {dropOpTime} " + "(notification optime: {opTime})", + "nss"_attr = nss, + "dropOpTime"_attr = dropOpTime, + "opTime"_attr = opTime); Status status = Status::OK(); try { // dropCollection could throw an interrupt exception, since it acquires db locks. @@ -184,9 +199,13 @@ void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opC status = exceptionToStatus(); } if (!status.isOK()) { - warning() << "Failed to remove drop-pending collection " << nss - << " with drop optime " << dropOpTime - << " (notification optime: " << opTime << "): " << status; + LOGV2_WARNING(21155, + "Failed to remove drop-pending collection {nss} with drop optime " + "{dropOpTime} (notification optime: {opTime}): {status}", + "nss"_attr = nss, + "dropOpTime"_attr = dropOpTime, + "opTime"_attr = opTime, + "status"_attr = status); } } } diff --git a/src/mongo/db/repl/idempotency_test.cpp b/src/mongo/db/repl/idempotency_test.cpp index 4eacc99fb52..89b3a37de5b 100644 --- a/src/mongo/db/repl/idempotency_test.cpp +++ b/src/mongo/db/repl/idempotency_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/catalog/index_catalog.h" @@ -40,7 +42,9 @@ #include "mongo/db/repl/idempotency_update_sequence.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace mongo { namespace repl { @@ -114,7 +118,10 @@ std::vector<OplogEntry> RandomizedIdempotencyTest::createUpdateSequence( std::string RandomizedIdempotencyTest::getStatesString(const std::vector<CollectionState>& state1, const std::vector<CollectionState>& state2, const std::vector<OplogEntry>& ops) { - unittest::log() << IdempotencyTest::getStatesString(state1, state2, ops); + LOGV2(21157, + "{IdempotencyTest_getStatesString_state1_state2_ops}", + "IdempotencyTest_getStatesString_state1_state2_ops"_attr = + IdempotencyTest::getStatesString(state1, state2, ops)); StringBuilder sb; sb << "Ran update ops: "; sb << "[ "; diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index 13f2f099ded..2d33f06f66e 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -63,6 +63,7 @@ #include "mongo/db/session_txn_record_gen.h" #include "mongo/executor/task_executor.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/util/assert_util.h" #include "mongo/util/destructor_guard.h" @@ -174,13 +175,13 @@ void pauseAtInitialSyncFuzzerSyncronizationPoints(std::string msg) { // Set and unset by the InitialSyncTest fixture to cause initial sync to pause so that the // Initial Sync Fuzzer can run commands on the sync source. if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint1.shouldFail())) { - log() << msg; - log() << "initialSyncFuzzerSynchronizationPoint1 fail point enabled."; + LOGV2(21158, "{msg}", "msg"_attr = msg); + LOGV2(21159, "initialSyncFuzzerSynchronizationPoint1 fail point enabled."); initialSyncFuzzerSynchronizationPoint1.pauseWhileSet(); } if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint2.shouldFail())) { - log() << "initialSyncFuzzerSynchronizationPoint2 fail point enabled."; + LOGV2(21160, "initialSyncFuzzerSynchronizationPoint2 fail point enabled."); initialSyncFuzzerSynchronizationPoint2.pauseWhileSet(); } } @@ -446,7 +447,7 @@ BSONObj InitialSyncer::_getInitialSyncProgress_inlock() const { } return bob.obj(); } catch (const DBException& e) { - log() << "Error creating initial sync progress object: " << e.toString(); + LOGV2(21161, "Error creating initial sync progress object: {e}", "e"_attr = e.toString()); } BSONObjBuilder bob; _appendInitialSyncProgressMinimal_inlock(&bob); @@ -495,7 +496,7 @@ void InitialSyncer::_setUp_inlock(OperationContext* opCtx, std::uint32_t initial _storage->setInitialDataTimestamp(serviceCtx, Timestamp::kAllowUnstableCheckpointsSentinel); _storage->setStableTimestamp(serviceCtx, Timestamp::min()); - LOG(1) << "Creating oplogBuffer."; + LOGV2_DEBUG(21162, 1, "Creating oplogBuffer."); _oplogBuffer = _dataReplicatorExternalState->makeInitialSyncOplogBuffer(opCtx); _oplogBuffer->startup(opCtx); @@ -542,8 +543,11 @@ void InitialSyncer::_tearDown_inlock(OperationContext* opCtx, invariant(currentLastAppliedOpTime == lastAppliedOpTime); } - log() << "initial sync done; took " - << duration_cast<Seconds>(_stats.initialSyncEnd - _stats.initialSyncStart) << "."; + LOGV2(21163, + "initial sync done; took " + "{duration_cast_Seconds_stats_initialSyncEnd_stats_initialSyncStart}.", + "duration_cast_Seconds_stats_initialSyncEnd_stats_initialSyncStart"_attr = + duration_cast<Seconds>(_stats.initialSyncEnd - _stats.initialSyncStart)); initialSyncCompletes.increment(); } @@ -560,8 +564,10 @@ void InitialSyncer::_startInitialSyncAttemptCallback( return; } - log() << "Starting initial sync (attempt " << (initialSyncAttempt + 1) << " of " - << initialSyncMaxAttempts << ")"; + LOGV2(21164, + "Starting initial sync (attempt {initialSyncAttempt_1} of {initialSyncMaxAttempts})", + "initialSyncAttempt_1"_attr = (initialSyncAttempt + 1), + "initialSyncMaxAttempts"_attr = initialSyncMaxAttempts); // This completion guard invokes _finishInitialSyncAttempt on destruction. auto cancelRemainingWorkInLock = [this]() { _cancelRemainingWork_inlock(); }; @@ -577,15 +583,18 @@ void InitialSyncer::_startInitialSyncAttemptCallback( _oplogApplier = {}; - LOG(2) << "Resetting sync source so a new one can be chosen for this initial sync attempt."; + LOGV2_DEBUG(21165, + 2, + "Resetting sync source so a new one can be chosen for this initial sync attempt."); _syncSource = HostAndPort(); - LOG(2) << "Resetting all optimes before starting this initial sync attempt."; + LOGV2_DEBUG(21166, 2, "Resetting all optimes before starting this initial sync attempt."); _opts.resetOptimes(); _lastApplied = {OpTime(), Date_t()}; _lastFetched = {}; - LOG(2) << "Resetting the oldest timestamp before starting this initial sync attempt."; + LOGV2_DEBUG( + 21167, 2, "Resetting the oldest timestamp before starting this initial sync attempt."); auto storageEngine = getGlobalServiceContext()->getStorageEngine(); if (storageEngine) { // Set the oldestTimestamp to one because WiredTiger does not allow us to set it to zero @@ -595,9 +604,11 @@ void InitialSyncer::_startInitialSyncAttemptCallback( storageEngine->setOldestTimestamp(kTimestampOne); } - LOG(2) << "Resetting feature compatibility version to last-stable. If the sync source is in " - "latest feature compatibility version, we will find out when we clone the " - "server configuration collection (admin.system.version)."; + LOGV2_DEBUG(21168, + 2, + "Resetting feature compatibility version to last-stable. If the sync source is in " + "latest feature compatibility version, we will find out when we clone the " + "server configuration collection (admin.system.version)."); serverGlobalParams.featureCompatibility.reset(); // Clear the oplog buffer. @@ -656,9 +667,17 @@ void InitialSyncer::_chooseSyncSourceCallback( } auto when = _exec->now() + _opts.syncSourceRetryWait; - LOG(1) << "Error getting sync source: '" << syncSource.getStatus() << "', trying again in " - << _opts.syncSourceRetryWait << " at " << when.toString() << ". Attempt " - << (chooseSyncSourceAttempt + 1) << " of " << numInitialSyncConnectAttempts.load(); + LOGV2_DEBUG(21169, + 1, + "Error getting sync source: '{syncSource_getStatus}', trying again in " + "{opts_syncSourceRetryWait} at {when}. Attempt {chooseSyncSourceAttempt_1} of " + "{numInitialSyncConnectAttempts_load}", + "syncSource_getStatus"_attr = syncSource.getStatus(), + "opts_syncSourceRetryWait"_attr = _opts.syncSourceRetryWait, + "when"_attr = when.toString(), + "chooseSyncSourceAttempt_1"_attr = (chooseSyncSourceAttempt + 1), + "numInitialSyncConnectAttempts_load"_attr = + numInitialSyncConnectAttempts.load()); auto status = _scheduleWorkAtAndSaveHandle_inlock( when, [=](const executor::TaskExecutor::CallbackArgs& args) { @@ -678,8 +697,9 @@ void InitialSyncer::_chooseSyncSourceCallback( if (MONGO_unlikely(initialSyncHangBeforeCreatingOplog.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "initial sync - initialSyncHangBeforeCreatingOplog fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21170, + "initial sync - initialSyncHangBeforeCreatingOplog fail point " + "enabled. Blocking until fail point is disabled."); lock.unlock(); while (MONGO_unlikely(initialSyncHangBeforeCreatingOplog.shouldFail()) && !_isShuttingDown()) { @@ -714,8 +734,11 @@ void InitialSyncer::_chooseSyncSourceCallback( Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() { // truncate oplog; drop user databases. - LOG(1) << "About to truncate the oplog, if it exists, ns:" << _opts.localOplogNS - << ", and drop all user databases (so that we can clone them)."; + LOGV2_DEBUG(21171, + 1, + "About to truncate the oplog, if it exists, ns:{opts_localOplogNS}, and drop all " + "user databases (so that we can clone them).", + "opts_localOplogNS"_attr = _opts.localOplogNS); auto opCtx = makeOpCtx(); @@ -723,13 +746,21 @@ Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() { UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx.get()); // 1.) Truncate the oplog. - LOG(2) << "Truncating the existing oplog: " << _opts.localOplogNS; + LOGV2_DEBUG(21172, + 2, + "Truncating the existing oplog: {opts_localOplogNS}", + "opts_localOplogNS"_attr = _opts.localOplogNS); Timer timer; auto status = _storage->truncateCollection(opCtx.get(), _opts.localOplogNS); - log() << "Initial syncer oplog truncation finished in: " << timer.millis() << "ms"; + LOGV2(21173, + "Initial syncer oplog truncation finished in: {timer_millis}ms", + "timer_millis"_attr = timer.millis()); if (!status.isOK()) { // 1a.) Create the oplog. - LOG(2) << "Creating the oplog: " << _opts.localOplogNS; + LOGV2_DEBUG(21174, + 2, + "Creating the oplog: {opts_localOplogNS}", + "opts_localOplogNS"_attr = _opts.localOplogNS); status = _storage->createOplog(opCtx.get(), _opts.localOplogNS); if (!status.isOK()) { return status; @@ -737,7 +768,7 @@ Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() { } // 2.) Drop user databases. - LOG(2) << "Dropping user databases"; + LOGV2_DEBUG(21175, 2, "Dropping user databases"); return _storage->dropReplicatedDatabases(opCtx.get()); } @@ -895,7 +926,7 @@ void InitialSyncer::_getBeginFetchingOpTimeCallback( pauseAtInitialSyncFuzzerSyncronizationPoints(logMsg); if (MONGO_unlikely(initialSyncHangAfterGettingBeginFetchingTimestamp.shouldFail())) { - log() << "initialSyncHangAfterGettingBeginFetchingTimestamp fail point enabled."; + LOGV2(21176, "initialSyncHangAfterGettingBeginFetchingTimestamp fail point enabled."); initialSyncHangAfterGettingBeginFetchingTimestamp.pauseWhileSet(); } @@ -1064,10 +1095,16 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> << _initialSyncState->beginFetchingTimestamp.toBSON()); invariant(!result.getValue().documents.empty()); - LOG(2) << "Setting begin applying timestamp to " << _initialSyncState->beginApplyingTimestamp - << " using last oplog entry: " << redact(result.getValue().documents.front()) - << ", ns: " << _opts.localOplogNS << " and the begin fetching timestamp to " - << _initialSyncState->beginFetchingTimestamp; + LOGV2_DEBUG( + 21177, + 2, + "Setting begin applying timestamp to {initialSyncState_beginApplyingTimestamp} using last " + "oplog entry: {result_getValue_documents_front}, ns: {opts_localOplogNS} and the begin " + "fetching timestamp to {initialSyncState_beginFetchingTimestamp}", + "initialSyncState_beginApplyingTimestamp"_attr = _initialSyncState->beginApplyingTimestamp, + "result_getValue_documents_front"_attr = redact(result.getValue().documents.front()), + "opts_localOplogNS"_attr = _opts.localOplogNS, + "initialSyncState_beginFetchingTimestamp"_attr = _initialSyncState->beginFetchingTimestamp); const auto configResult = _dataReplicatorExternalState->getCurrentConfig(); status = configResult.getStatus(); @@ -1098,7 +1135,10 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> initialSyncOplogFetcherBatchSize, OplogFetcher::StartingPoint::kEnqueueFirstDoc); - LOG(2) << "Starting OplogFetcher: " << _oplogFetcher->toString(); + LOGV2_DEBUG(21178, + 2, + "Starting OplogFetcher: {oplogFetcher}", + "oplogFetcher"_attr = _oplogFetcher->toString()); // _startupComponent_inlock is shutdown-aware. status = _startupComponent_inlock(_oplogFetcher); @@ -1113,8 +1153,9 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> // This could have been done with a scheduleWorkAt but this is used only by JS tests where // we run with multiple threads so it's fine to spin on this thread. // This log output is used in js tests so please leave it. - log() << "initial sync - initialSyncHangBeforeCopyingDatabases fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21179, + "initial sync - initialSyncHangBeforeCopyingDatabases fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(initialSyncHangBeforeCopyingDatabases.shouldFail()) && !_isShuttingDown()) { mongo::sleepsecs(1); @@ -1122,7 +1163,11 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> lock.lock(); } - LOG(2) << "Starting AllDatabaseCloner: " << _initialSyncState->allDatabaseCloner->toString(); + LOGV2_DEBUG(21180, + 2, + "Starting AllDatabaseCloner: {initialSyncState_allDatabaseCloner}", + "initialSyncState_allDatabaseCloner"_attr = + _initialSyncState->allDatabaseCloner->toString()); auto [startClonerFuture, startCloner] = _initialSyncState->allDatabaseCloner->runOnExecutorEvent(_clonerExec); @@ -1166,8 +1211,11 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus, std::shared_ptr<OnCompletionGuard> onCompletionGuard) { stdx::lock_guard<Latch> lock(_mutex); - log() << "Finished fetching oplog during initial sync: " << redact(oplogFetcherFinishStatus) - << ". Last fetched optime: " << _lastFetched.toString(); + LOGV2(21181, + "Finished fetching oplog during initial sync: {oplogFetcherFinishStatus}. Last fetched " + "optime: {lastFetched}", + "oplogFetcherFinishStatus"_attr = redact(oplogFetcherFinishStatus), + "lastFetched"_attr = _lastFetched.toString()); auto status = _checkForShutdownAndConvertStatus_inlock( oplogFetcherFinishStatus, "error fetching oplog during initial sync"); @@ -1182,8 +1230,9 @@ void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus // an OK status is when the 'stopReplProducer' fail point is enabled, which causes the // OplogFetcher to ignore the current sync source response and return early. if (status.isOK()) { - log() << "Finished fetching oplog fetching early. Last fetched optime: " - << _lastFetched.toString(); + LOGV2(21182, + "Finished fetching oplog fetching early. Last fetched optime: {lastFetched}", + "lastFetched"_attr = _lastFetched.toString()); return; } @@ -1199,16 +1248,18 @@ void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus void InitialSyncer::_allDatabaseClonerCallback( const Status& databaseClonerFinishStatus, std::shared_ptr<OnCompletionGuard> onCompletionGuard) { - log() << "Finished cloning data: " << redact(databaseClonerFinishStatus) - << ". Beginning oplog replay."; + LOGV2(21183, + "Finished cloning data: {databaseClonerFinishStatus}. Beginning oplog replay.", + "databaseClonerFinishStatus"_attr = redact(databaseClonerFinishStatus)); _client->shutdownAndDisallowReconnect(); if (MONGO_unlikely(initialSyncHangAfterDataCloning.shouldFail())) { // This could have been done with a scheduleWorkAt but this is used only by JS tests where // we run with multiple threads so it's fine to spin on this thread. // This log output is used in js tests so please leave it. - log() << "initial sync - initialSyncHangAfterDataCloning fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21184, + "initial sync - initialSyncHangAfterDataCloning fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(initialSyncHangAfterDataCloning.shouldFail()) && !_isShuttingDown()) { mongo::sleepsecs(1); } @@ -1309,7 +1360,10 @@ void InitialSyncer::_lastOplogEntryFetcherCallbackForStopTimestamp( const auto& documents = result.getValue().documents; invariant(!documents.empty()); const BSONObj oplogSeedDoc = documents.front(); - LOG(2) << "Inserting oplog seed document: " << oplogSeedDoc; + LOGV2_DEBUG(21185, + 2, + "Inserting oplog seed document: {oplogSeedDoc}", + "oplogSeedDoc"_attr = oplogSeedDoc); auto opCtx = makeOpCtx(); // StorageInterface::insertDocument() has to be called outside the lock because we may @@ -1333,8 +1387,9 @@ void InitialSyncer::_lastOplogEntryFetcherCallbackForStopTimestamp( stdx::lock_guard<Latch> lock(_mutex); _lastApplied = resultOpTimeAndWallTime; - log() << "No need to apply operations. (currently at " - << _initialSyncState->stopTimestamp.toBSON() << ")"; + LOGV2(21186, + "No need to apply operations. (currently at {initialSyncState_stopTimestamp})", + "initialSyncState_stopTimestamp"_attr = _initialSyncState->stopTimestamp.toBSON()); // This sets the error in 'onCompletionGuard' and shuts down the OplogFetcher on error. _scheduleRollbackCheckerCheckForRollback_inlock(lock, onCompletionGuard); @@ -1353,7 +1408,9 @@ void InitialSyncer::_getNextApplierBatchCallback( auto batchResult = _getNextApplierBatch_inlock(); if (!batchResult.isOK()) { - warning() << "Failure creating next apply batch: " << redact(batchResult.getStatus()); + LOGV2_WARNING(21196, + "Failure creating next apply batch: {batchResult_getStatus}", + "batchResult_getStatus"_attr = redact(batchResult.getStatus())); onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, batchResult.getStatus()); return; } @@ -1364,8 +1421,9 @@ void InitialSyncer::_getNextApplierBatchCallback( pauseAtInitialSyncFuzzerSyncronizationPoints(logMsg); if (MONGO_unlikely(failInitialSyncBeforeApplyingBatch.shouldFail())) { - log() << "initial sync - failInitialSyncBeforeApplyingBatch fail point enabled. Pausing" - << "until fail point is disabled, then will fail initial sync."; + LOGV2(21187, + "initial sync - failInitialSyncBeforeApplyingBatch fail point enabled. Pausinguntil " + "fail point is disabled, then will fail initial sync."); failInitialSyncBeforeApplyingBatch.pauseWhileSet(); status = Status(ErrorCodes::CallbackCanceled, "failInitialSyncBeforeApplyingBatch fail point enabled"); @@ -1409,7 +1467,7 @@ void InitialSyncer::_getNextApplierBatchCallback( "in the oplog buffer. Aborting this initial sync attempt. Last applied: " << _lastApplied.opTime.toString() << ". Last fetched: " << _lastFetched.toString() << ". Number of operations applied: " << _initialSyncState->appliedOps; - log() << msg; + LOGV2(21188, "{msg}", "msg"_attr = msg); status = Status(ErrorCodes::RemoteResultsUnavailable, msg); onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, status); return; @@ -1441,12 +1499,13 @@ void InitialSyncer::_multiApplierCallback(const Status& multiApplierStatus, // Set to cause initial sync to fassert instead of restart if applying a batch fails, so that // tests can be robust to network errors but not oplog idempotency errors. if (MONGO_unlikely(initialSyncFassertIfApplyingBatchFails.shouldFail())) { - log() << "initialSyncFassertIfApplyingBatchFails fail point enabled."; + LOGV2(21189, "initialSyncFassertIfApplyingBatchFails fail point enabled."); fassert(31210, status); } if (!status.isOK()) { - error() << "Failed to apply batch due to '" << redact(status) << "'"; + LOGV2_ERROR( + 21199, "Failed to apply batch due to '{status}'", "status"_attr = redact(status)); onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, status); return; } @@ -1475,7 +1534,10 @@ void InitialSyncer::_rollbackCheckerCheckForRollbackCallback( auto status = _checkForShutdownAndConvertStatus_inlock(result.getStatus(), "error while getting last rollback ID"); if (_shouldRetryError(lock, status)) { - LOG(1) << "Retrying rollback checker because of network error " << status; + LOGV2_DEBUG(21190, + 1, + "Retrying rollback checker because of network error {status}", + "status"_attr = status); _scheduleRollbackCheckerCheckForRollback_inlock(lock, onCompletionGuard); return; } @@ -1519,17 +1581,20 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime auto scheduleResult = _exec->scheduleWork( [=](const mongo::executor::TaskExecutor::CallbackArgs&) { _finishCallback(result); }); if (!scheduleResult.isOK()) { - warning() << "Unable to schedule initial syncer completion task due to " - << redact(scheduleResult.getStatus()) - << ". Running callback on current thread."; + LOGV2_WARNING(21197, + "Unable to schedule initial syncer completion task due to " + "{scheduleResult_getStatus}. Running callback on current thread.", + "scheduleResult_getStatus"_attr = redact(scheduleResult.getStatus())); _finishCallback(result); } }); - log() << "Initial sync attempt finishing up."; + LOGV2(21191, "Initial sync attempt finishing up."); stdx::lock_guard<Latch> lock(_mutex); - log() << "Initial Sync Attempt Statistics: " << redact(_getInitialSyncProgress_inlock()); + LOGV2(21192, + "Initial Sync Attempt Statistics: {getInitialSyncProgress_inlock}", + "getInitialSyncProgress_inlock"_attr = redact(_getInitialSyncProgress_inlock())); auto runTime = _initialSyncState ? _initialSyncState->timer.millis() : 0; int rollBackId = -1; @@ -1552,7 +1617,7 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime totalTimeUnreachableMillis}); if (MONGO_unlikely(failAndHangInitialSync.shouldFail())) { - log() << "failAndHangInitialSync fail point enabled."; + LOGV2(21193, "failAndHangInitialSync fail point enabled."); failAndHangInitialSync.pauseWhileSet(); result = Status(ErrorCodes::InternalError, "failAndHangInitialSync fail point enabled"); } @@ -1570,15 +1635,19 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime // startup. initialSyncFailedAttempts.increment(); - error() << "Initial sync attempt failed -- attempts left: " - << (_stats.maxFailedInitialSyncAttempts - _stats.failedInitialSyncAttempts) - << " cause: " << redact(result.getStatus()); + LOGV2_ERROR(21200, + "Initial sync attempt failed -- attempts left: " + "{stats_maxFailedInitialSyncAttempts_stats_failedInitialSyncAttempts} cause: " + "{result_getStatus}", + "stats_maxFailedInitialSyncAttempts_stats_failedInitialSyncAttempts"_attr = + (_stats.maxFailedInitialSyncAttempts - _stats.failedInitialSyncAttempts), + "result_getStatus"_attr = redact(result.getStatus())); // Check if need to do more retries. if (_stats.failedInitialSyncAttempts >= _stats.maxFailedInitialSyncAttempts) { const std::string err = "The maximum number of retries have been exhausted for initial sync."; - severe() << err; + LOGV2_FATAL(21202, "{err}", "err"_attr = err); initialSyncFailures.increment(); @@ -1626,8 +1695,9 @@ void InitialSyncer::_finishCallback(StatusWith<OpTimeAndWallTime> lastApplied) { if (MONGO_unlikely(initialSyncHangBeforeFinish.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "initial sync - initialSyncHangBeforeFinish fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21194, + "initial sync - initialSyncHangBeforeFinish fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(initialSyncHangBeforeFinish.shouldFail()) && !_isShuttingDown()) { mongo::sleepsecs(1); } @@ -1637,8 +1707,9 @@ void InitialSyncer::_finishCallback(StatusWith<OpTimeAndWallTime> lastApplied) { try { onCompletion(lastApplied); } catch (...) { - warning() << "initial syncer finish callback threw exception: " - << redact(exceptionToStatus()); + LOGV2_WARNING(21198, + "initial syncer finish callback threw exception: {exceptionToStatus}", + "exceptionToStatus"_attr = redact(exceptionToStatus())); } // Destroy the remaining reference to the completion callback before we transition the state to @@ -1704,7 +1775,7 @@ void InitialSyncer::_checkApplierProgressAndScheduleGetNextApplierBatch_inlock( << "Possible rollback on sync source " << _syncSource.toString() << ". Currently at " << _initialSyncState->stopTimestamp.toBSON() << ". Started at " << _initialSyncState->beginApplyingTimestamp.toBSON(); - error() << msg; + LOGV2_ERROR(21201, "{msg}", "msg"_attr = msg); onCompletionGuard->setResultAndCancelRemainingWork_inlock( lock, Status(ErrorCodes::OplogOutOfOrder, msg)); return; @@ -1713,11 +1784,16 @@ void InitialSyncer::_checkApplierProgressAndScheduleGetNextApplierBatch_inlock( if (_lastApplied.opTime.isNull()) { // Check if any ops occurred while cloning or any ops need to be fetched. invariant(_initialSyncState->beginFetchingTimestamp < _initialSyncState->stopTimestamp); - log() << "Writing to the oplog and applying operations until " - << _initialSyncState->stopTimestamp.toBSON() - << " before initial sync can complete. (started fetching at " - << _initialSyncState->beginFetchingTimestamp.toBSON() << " and applying at " - << _initialSyncState->beginApplyingTimestamp.toBSON() << ")"; + LOGV2(21195, + "Writing to the oplog and applying operations until {initialSyncState_stopTimestamp} " + "before initial sync can complete. (started fetching at " + "{initialSyncState_beginFetchingTimestamp} and applying at " + "{initialSyncState_beginApplyingTimestamp})", + "initialSyncState_stopTimestamp"_attr = _initialSyncState->stopTimestamp.toBSON(), + "initialSyncState_beginFetchingTimestamp"_attr = + _initialSyncState->beginFetchingTimestamp.toBSON(), + "initialSyncState_beginApplyingTimestamp"_attr = + _initialSyncState->beginApplyingTimestamp.toBSON()); // Fall through to scheduling _getNextApplierBatchCallback(). } else if (_lastApplied.opTime.getTimestamp() >= _initialSyncState->stopTimestamp) { // Check for rollback if we have applied far enough to be consistent. diff --git a/src/mongo/db/repl/insert_group.cpp b/src/mongo/db/repl/insert_group.cpp index 24acf95b0d2..931ca0d3367 100644 --- a/src/mongo/db/repl/insert_group.cpp +++ b/src/mongo/db/repl/insert_group.cpp @@ -40,6 +40,7 @@ #include "mongo/db/ops/write_ops.h" #include "mongo/db/repl/oplog_applier_impl.h" #include "mongo/db/repl/oplog_entry.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -139,9 +140,9 @@ StatusWith<InsertGroup::ConstIterator> InsertGroup::groupAndApplyInserts(ConstIt // It's not an error during initial sync to encounter DuplicateKey errors. if (Mode::kInitialSync == _mode && ErrorCodes::DuplicateKey == status) { - LOG(2) << status; + LOGV2_DEBUG(21203, 2, "{status}", "status"_attr = status); } else { - error() << status; + LOGV2_ERROR(21204, "{status}", "status"_attr = status); } // Avoid quadratic run time from failed insert by not retrying until we diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp index b50a893efb8..b4af71d7fdb 100644 --- a/src/mongo/db/repl/isself.cpp +++ b/src/mongo/db/repl/isself.cpp @@ -44,6 +44,7 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/commands.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/scopeguard.h" @@ -119,8 +120,10 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost, int err = getaddrinfo(iporhost.c_str(), portNum.c_str(), &hints, &addrs); if (err) { - warning() << "getaddrinfo(\"" << iporhost << "\") failed: " << stringifyError(err) - << std::endl; + LOGV2_WARNING(21207, + "getaddrinfo(\"{iporhost}\") failed: {stringifyError_err}", + "iporhost"_attr = iporhost, + "stringifyError_err"_attr = stringifyError(err)); return out; } @@ -134,7 +137,9 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost, err = getnameinfo( addr->ai_addr, addr->ai_addrlen, host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST); if (err) { - warning() << "getnameinfo() failed: " << stringifyError(err) << std::endl; + LOGV2_WARNING(21208, + "getnameinfo() failed: {stringifyError_err}", + "stringifyError_err"_attr = stringifyError(err)); continue; } out.push_back(host); @@ -147,7 +152,7 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost, for (std::vector<std::string>::const_iterator o = out.begin(); o != out.end(); ++o) { builder << " [ " << *o << "]"; } - LOG(2) << builder.str(); + LOGV2_DEBUG(21205, 2, "{builder_str}", "builder_str"_attr = builder.str()); } return out; @@ -210,7 +215,10 @@ bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx) { return me; } catch (const std::exception& e) { - warning() << "couldn't check isSelf (" << hostAndPort << ") " << e.what() << std::endl; + LOGV2_WARNING(21209, + "couldn't check isSelf ({hostAndPort}) {e_what}", + "hostAndPort"_attr = hostAndPort, + "e_what"_attr = e.what()); } return false; @@ -229,7 +237,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { int err = getifaddrs(&addrs); if (err) { - warning() << "getifaddrs failure: " << errnoWithDescription(err) << std::endl; + LOGV2_WARNING(21210, + "getifaddrs failure: {errnoWithDescription_err}", + "errnoWithDescription_err"_attr = errnoWithDescription(err)); return out; } ON_BLOCK_EXIT([&] { freeifaddrs(addrs); }); @@ -251,7 +261,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { 0, NI_NUMERICHOST); if (err) { - warning() << "getnameinfo() failed: " << gai_strerror(err) << std::endl; + LOGV2_WARNING(21211, + "getnameinfo() failed: {gai_strerror_err}", + "gai_strerror_err"_attr = gai_strerror(err)); continue; } out.push_back(host); @@ -288,7 +300,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { } if (err != NO_ERROR) { - warning() << "GetAdaptersAddresses() failed: " << errnoWithDescription(err) << std::endl; + LOGV2_WARNING(21212, + "GetAdaptersAddresses() failed: {errnoWithDescription_err}", + "errnoWithDescription_err"_attr = errnoWithDescription(err)); return out; } @@ -306,8 +320,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { boost::asio::detail::socket_ops::inet_ntop( AF_INET, &(sock->sin_addr), addrstr, INET_ADDRSTRLEN, 0, ec); if (ec) { - warning() << "inet_ntop failed during IPv4 address conversion: " << ec.message() - << std::endl; + LOGV2_WARNING(21213, + "inet_ntop failed during IPv4 address conversion: {ec_message}", + "ec_message"_attr = ec.message()); continue; } out.push_back(addrstr); @@ -319,8 +334,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { boost::asio::detail::socket_ops::inet_ntop( AF_INET6, &(sock->sin6_addr), addrstr, INET6_ADDRSTRLEN, 0, ec); if (ec) { - warning() << "inet_ntop failed during IPv6 address conversion: " << ec.message() - << std::endl; + LOGV2_WARNING(21214, + "inet_ntop failed during IPv6 address conversion: {ec_message}", + "ec_message"_attr = ec.message()); continue; } out.push_back(addrstr); @@ -336,7 +352,7 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { for (std::vector<std::string>::const_iterator o = out.begin(); o != out.end(); ++o) { builder << " [ " << *o << "]"; } - LOG(2) << builder.str(); + LOGV2_DEBUG(21206, 2, "{builder_str}", "builder_str"_attr = builder.str()); } return out; } diff --git a/src/mongo/db/repl/member_data.cpp b/src/mongo/db/repl/member_data.cpp index 571e83d3a1c..56cc13619e3 100644 --- a/src/mongo/db/repl/member_data.cpp +++ b/src/mongo/db/repl/member_data.cpp @@ -35,6 +35,7 @@ #include "mongo/db/repl/member_data.h" #include "mongo/db/repl/rslog.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -69,8 +70,11 @@ bool MemberData::setUpValues(Date_t now, ReplSetHeartbeatResponse&& hbResponse) } // Log if the state changes if (_lastResponse.getState() != hbResponse.getState()) { - log() << "Member " << _hostAndPort.toString() << " is now in state " - << hbResponse.getState().toString() << rsLog; + LOGV2_OPTIONS(21215, + {logv2::LogTag::kRS}, + "Member {hostAndPort} is now in state {hbResponse_getState}", + "hostAndPort"_attr = _hostAndPort.toString(), + "hbResponse_getState"_attr = hbResponse.getState().toString()); } bool opTimeAdvanced = @@ -93,8 +97,11 @@ void MemberData::setDownValues(Date_t now, const std::string& heartbeatMessage) _lastHeartbeatMessage = heartbeatMessage; if (_lastResponse.getState() != MemberState::RS_DOWN) { - log() << "Member " << _hostAndPort.toString() << " is now in state RS_DOWN - " - << redact(heartbeatMessage) << rsLog; + LOGV2_OPTIONS(21216, + {logv2::LogTag::kRS}, + "Member {hostAndPort} is now in state RS_DOWN - {heartbeatMessage}", + "hostAndPort"_attr = _hostAndPort.toString(), + "heartbeatMessage"_attr = redact(heartbeatMessage)); } _lastResponse = ReplSetHeartbeatResponse(); @@ -116,8 +123,11 @@ void MemberData::setAuthIssue(Date_t now) { _lastHeartbeatMessage.clear(); if (_lastResponse.getState() != MemberState::RS_UNKNOWN) { - log() << "Member " << _hostAndPort.toString() - << " is now in state RS_UNKNOWN due to authentication issue." << rsLog; + LOGV2_OPTIONS( + 21217, + {logv2::LogTag::kRS}, + "Member {hostAndPort} is now in state RS_UNKNOWN due to authentication issue.", + "hostAndPort"_attr = _hostAndPort.toString()); } _lastResponse = ReplSetHeartbeatResponse(); @@ -142,12 +152,16 @@ void MemberData::setLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_ if (_lastAppliedOpTime < opTime.opTime) { // TODO(russotto): We think this should never happen, rollback or no rollback. Make this an // invariant and see what happens. - log() << "Durable progress (" << opTime.opTime << ") is ahead of the applied progress (" - << _lastAppliedOpTime - << ". This is likely due to a " - "rollback." - << " memberid: " << _memberId << _hostAndPort.toString() - << " previous durable progress: " << _lastDurableOpTime; + LOGV2(21218, + "Durable progress ({opTime_opTime}) is ahead of the applied progress " + "({lastAppliedOpTime}. This is likely due to a " + "rollback. memberid: {memberId}{hostAndPort} previous durable progress: " + "{lastDurableOpTime}", + "opTime_opTime"_attr = opTime.opTime, + "lastAppliedOpTime"_attr = _lastAppliedOpTime, + "memberId"_attr = _memberId, + "hostAndPort"_attr = _hostAndPort.toString(), + "lastDurableOpTime"_attr = _lastDurableOpTime); } else { _lastDurableOpTime = opTime.opTime; _lastDurableWallTime = opTime.wallTime; diff --git a/src/mongo/db/repl/noop_writer.cpp b/src/mongo/db/repl/noop_writer.cpp index 29ee8017bfb..67fba097925 100644 --- a/src/mongo/db/repl/noop_writer.cpp +++ b/src/mongo/db/repl/noop_writer.cpp @@ -43,6 +43,7 @@ #include "mongo/db/repl/noop_writer.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/log.h" @@ -150,14 +151,14 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) { Lock::GlobalLock lock( opCtx, MODE_IX, Date_t::now() + Milliseconds(1), Lock::InterruptBehavior::kLeaveUnlocked); if (!lock.isLocked()) { - LOG(1) << "Global lock is not available skipping noopWrite"; + LOGV2_DEBUG(21219, 1, "Global lock is not available skipping noopWrite"); return; } auto replCoord = ReplicationCoordinator::get(opCtx); // Its a proxy for being a primary if (!replCoord->canAcceptWritesForDatabase(opCtx, "admin")) { - LOG(1) << "Not a primary, skipping the noop write"; + LOGV2_DEBUG(21220, 1, "Not a primary, skipping the noop write"); return; } @@ -165,14 +166,20 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) { // _lastKnownOpTime is not protected by lock as its used only by one thread. if (lastAppliedOpTime != _lastKnownOpTime) { - LOG(1) << "Not scheduling a noop write. Last known OpTime: " << _lastKnownOpTime - << " != last primary OpTime: " << lastAppliedOpTime; + LOGV2_DEBUG(21221, + 1, + "Not scheduling a noop write. Last known OpTime: {lastKnownOpTime} != last " + "primary OpTime: {lastAppliedOpTime}", + "lastKnownOpTime"_attr = _lastKnownOpTime, + "lastAppliedOpTime"_attr = lastAppliedOpTime); } else { if (writePeriodicNoops.load()) { const auto logLevel = getTestCommandsEnabled() ? 0 : 1; - LOG(logLevel) - << "Writing noop to oplog as there has been no writes to this replica set in over " - << _writeInterval; + LOGV2_DEBUG(21222, + logSeverityV1toV2(logLevel).toInt(), + "Writing noop to oplog as there has been no writes to this replica set in " + "over {writeInterval}", + "writeInterval"_attr = _writeInterval); writeConflictRetry( opCtx, "writeNoop", NamespaceString::kRsOplogNamespace.ns(), [&opCtx] { WriteUnitOfWork uow(opCtx); @@ -184,7 +191,10 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) { } _lastKnownOpTime = replCoord->getMyLastAppliedOpTime(); - LOG(1) << "Set last known op time to " << _lastKnownOpTime; + LOGV2_DEBUG(21223, + 1, + "Set last known op time to {lastKnownOpTime}", + "lastKnownOpTime"_attr = _lastKnownOpTime); } } // namespace repl diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 7e74528cf6d..c792ba15917 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -127,8 +127,11 @@ bool shouldBuildInForeground(OperationContext* opCtx, const NamespaceString& indexNss, repl::OplogApplication::Mode mode) { if (mode == OplogApplication::Mode::kRecovering) { - LOG(3) << "apply op: building background index " << index - << " in the foreground because the node is in recovery"; + LOGV2_DEBUG(21241, + 3, + "apply op: building background index {index} in the foreground because the " + "node is in recovery", + "index"_attr = index); return true; } @@ -137,8 +140,11 @@ bool shouldBuildInForeground(OperationContext* opCtx, const bool isPrimary = repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, indexNss); if (isPrimary) { - LOG(3) << "apply op: not building background index " << index - << " in a background thread because this is a primary"; + LOGV2_DEBUG(21242, + 3, + "apply op: not building background index {index} in a background thread " + "because this is a primary", + "index"_attr = index); return true; } @@ -262,7 +268,7 @@ void _logOpsInner(OperationContext* opCtx, Status result = oplogCollection->insertDocumentsForOplog(opCtx, records, timestamps); if (!result.isOK()) { - severe() << "write to oplog failed: " << result.toString(); + LOGV2_FATAL(21263, "write to oplog failed: {result}", "result"_attr = result.toString()); fassertFailed(17322); } @@ -279,7 +285,7 @@ void _logOpsInner(OperationContext* opCtx, // Optionally hang before advancing lastApplied. if (MONGO_unlikely(hangBeforeLogOpAdvancesLastApplied.shouldFail())) { - log() << "hangBeforeLogOpAdvancesLastApplied fail point enabled."; + LOGV2(21243, "hangBeforeLogOpAdvancesLastApplied fail point enabled."); hangBeforeLogOpAdvancesLastApplied.pauseWhileSet(opCtx); } @@ -417,8 +423,13 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx, sleepBetweenInsertOpTimeGenerationAndLogOp.execute([&](const BSONObj& data) { auto numMillis = data["waitForMillis"].numberInt(); - log() << "Sleeping for " << numMillis << "ms after receiving " << count << " optimes from " - << opTimes.front() << " to " << opTimes.back(); + LOGV2(21244, + "Sleeping for {numMillis}ms after receiving {count} optimes from {opTimes_front} to " + "{opTimes_back}", + "numMillis"_attr = numMillis, + "count"_attr = count, + "opTimes_front"_attr = opTimes.front(), + "opTimes_back"_attr = opTimes.back()); sleepmillis(numMillis); }); @@ -470,7 +481,7 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl ProcessInfo pi; if (pi.getAddrSize() == 32) { const auto sz = 50LL * 1024LL * 1024LL; - LOG(3) << "32bit system; choosing " << sz << " bytes oplog"; + LOGV2_DEBUG(21245, 3, "32bit system; choosing {sz} bytes oplog", "sz"_attr = sz); return sz; } // First choose a minimum size. @@ -478,7 +489,7 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl #if defined(__APPLE__) // typically these are desktops (dev machines), so keep it smallish const auto sz = 192 * 1024 * 1024; - LOG(3) << "Apple system; choosing " << sz << " bytes oplog"; + LOGV2_DEBUG(21246, 3, "Apple system; choosing {sz} bytes oplog", "sz"_attr = sz); return sz; #else long long lowerBound = 0; @@ -487,14 +498,22 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl // in memory: 50MB minimum size lowerBound = 50LL * 1024 * 1024; bytes = pi.getMemSizeMB() * 1024 * 1024; - LOG(3) << "Ephemeral storage system; lowerBound: " << lowerBound << " bytes, " << bytes - << " bytes total memory"; + LOGV2_DEBUG( + 21247, + 3, + "Ephemeral storage system; lowerBound: {lowerBound} bytes, {bytes} bytes total memory", + "lowerBound"_attr = lowerBound, + "bytes"_attr = bytes); } else { // disk: 990MB minimum size lowerBound = 990LL * 1024 * 1024; bytes = File::freeSpace(storageGlobalParams.dbpath); //-1 if call not supported. - LOG(3) << "Disk storage system; lowerBound: " << lowerBound << " bytes, " << bytes - << " bytes free space on device"; + LOGV2_DEBUG(21248, + 3, + "Disk storage system; lowerBound: {lowerBound} bytes, {bytes} bytes free space " + "on device", + "lowerBound"_attr = lowerBound, + "bytes"_attr = bytes); } long long fivePct = static_cast<long long>(bytes * 0.05); auto sz = std::max(fivePct, lowerBound); @@ -531,7 +550,7 @@ void createOplog(OperationContext* opCtx, stringstream ss; ss << "cmdline oplogsize (" << n << ") different than existing (" << o << ") see: http://dochub.mongodb.org/core/increase-oplog"; - log() << ss.str() << endl; + LOGV2(21249, "{ss_str}", "ss_str"_attr = ss.str()); uasserted(13257, ss.str()); } } @@ -544,8 +563,10 @@ void createOplog(OperationContext* opCtx, /* create an oplog collection, if it doesn't yet exist. */ const auto sz = getNewOplogSizeBytes(opCtx, replSettings); - log() << "******" << endl; - log() << "creating replication oplog of size: " << (int)(sz / (1024 * 1024)) << "MB..." << endl; + LOGV2(21250, "******"); + LOGV2(21251, + "creating replication oplog of size: {int_sz_1024_1024}MB...", + "int_sz_1024_1024"_attr = (int)(sz / (1024 * 1024))); CollectionOptions options; options.capped = true; @@ -565,7 +586,7 @@ void createOplog(OperationContext* opCtx, /* sync here so we don't get any surprising lag later when we try to sync */ service->getStorageEngine()->flushAllFiles(opCtx, /*callerHoldsReadLock*/ false); - log() << "******" << endl; + LOGV2(21252, "******"); } void createOplog(OperationContext* opCtx) { @@ -778,10 +799,11 @@ const StringMap<ApplyOpMetadata> kOpsMap = { const auto& cmd = entry.getObject(); auto nss = extractNsFromUUIDorNs(opCtx, entry.getNss(), entry.getUuid(), cmd); if (nss.isDropPendingNamespace()) { - log() - << "applyCommand: " << nss - << " : collection is already in a drop-pending state: ignoring collection drop: " - << redact(cmd); + LOGV2(21253, + "applyCommand: {nss} : collection is already in a drop-pending state: ignoring " + "collection drop: {cmd}", + "nss"_attr = nss, + "cmd"_attr = redact(cmd)); return Status::OK(); } // Parse optime from oplog entry unless we are applying this command in standalone or on a @@ -920,8 +942,12 @@ Status applyOperation_inlock(OperationContext* opCtx, IncrementOpsAppliedStatsFn incrementOpsAppliedStats) { // Get the single oplog entry to be applied or the first oplog entry of grouped inserts. auto op = opOrGroupedInserts.getOp(); - LOG(3) << "applying op (or grouped inserts): " << redact(opOrGroupedInserts.toBSON()) - << ", oplog application mode: " << OplogApplication::modeToString(mode); + LOGV2_DEBUG(21254, + 3, + "applying op (or grouped inserts): {opOrGroupedInserts}, oplog application mode: " + "{OplogApplication_modeToString_mode}", + "opOrGroupedInserts"_attr = redact(opOrGroupedInserts.toBSON()), + "OplogApplication_modeToString_mode"_attr = OplogApplication::modeToString(mode)); // Choose opCounters based on running on standalone/primary or secondary by checking // whether writes are replicated. Atomic applyOps command is an exception, which runs @@ -1167,8 +1193,9 @@ Status applyOperation_inlock(OperationContext* opCtx, UpdateResult res = update(opCtx, db, request); if (res.numMatched == 0 && res.upserted.isEmpty()) { - error() << "No document was updated even though we got a DuplicateKey " - "error when inserting"; + LOGV2_ERROR(21257, + "No document was updated even though we got a DuplicateKey " + "error when inserting"); fassertFailedNoTrace(28750); } wuow.commit(); @@ -1225,7 +1252,7 @@ Status applyOperation_inlock(OperationContext* opCtx, // was a simple { _id : ... } update criteria string msg = str::stream() << "failed to apply update: " << redact(op.toBSON()); - error() << msg; + LOGV2_ERROR(21258, "{msg}", "msg"_attr = msg); return Status(ErrorCodes::UpdateOperationFailed, msg); } @@ -1242,7 +1269,7 @@ Status applyOperation_inlock(OperationContext* opCtx, Helpers::findOne(opCtx, collection, updateCriteria, false).isNull())) { string msg = str::stream() << "couldn't find doc: " << redact(op.toBSON()); - error() << msg; + LOGV2_ERROR(21259, "{msg}", "msg"_attr = msg); return Status(ErrorCodes::UpdateOperationFailed, msg); } @@ -1255,7 +1282,7 @@ Status applyOperation_inlock(OperationContext* opCtx, if (!upsert) { string msg = str::stream() << "update of non-mod failed: " << redact(op.toBSON()); - error() << msg; + LOGV2_ERROR(21260, "{msg}", "msg"_attr = msg); return Status(ErrorCodes::UpdateOperationFailed, msg); } } @@ -1324,8 +1351,12 @@ Status applyOperation_inlock(OperationContext* opCtx, Status applyCommand_inlock(OperationContext* opCtx, const OplogEntry& entry, OplogApplication::Mode mode) { - LOG(3) << "applying command op: " << redact(entry.toBSON()) - << ", oplog application mode: " << OplogApplication::modeToString(mode); + LOGV2_DEBUG(21255, + 3, + "applying command op: {entry}, oplog application mode: " + "{OplogApplication_modeToString_mode}", + "entry"_attr = redact(entry.toBSON()), + "OplogApplication_modeToString_mode"_attr = OplogApplication::modeToString(mode)); // Only commands are processed here. invariant(entry.getOpType() == OpTypeEnum::kCommand); @@ -1472,8 +1503,11 @@ Status applyCommand_inlock(OperationContext* opCtx, cmd->parse(opCtx, OpMsgRequest::fromDBAndBody(nss.db(), o))->ns().toString(); auto swUUID = entry.getUuid(); if (!swUUID) { - error() << "Failed command " << redact(o) << " on " << ns - << "during oplog application. Expected a UUID."; + LOGV2_ERROR( + 21261, + "Failed command {o} on {ns}during oplog application. Expected a UUID.", + "o"_attr = redact(o), + "ns"_attr = ns); } BackgroundOperation::awaitNoBgOpInProgForNs(ns); IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection( @@ -1492,8 +1526,12 @@ Status applyCommand_inlock(OperationContext* opCtx, } default: { if (!curOpToApply.acceptableErrors.count(status.code())) { - error() << "Failed command " << redact(o) << " on " << nss.db() - << " with status " << status << " during oplog application"; + LOGV2_ERROR(21262, + "Failed command {o} on {nss_db} with status {status} during oplog " + "application", + "o"_attr = redact(o), + "nss_db"_attr = nss.db(), + "status"_attr = status); return status; } @@ -1527,7 +1565,7 @@ void initTimestampFromOplog(OperationContext* opCtx, const NamespaceString& oplo c.findOne(oplogNss.ns(), Query().sort(reverseNaturalObj), nullptr, QueryOption_SlaveOk); if (!lastOp.isEmpty()) { - LOG(1) << "replSet setting last Timestamp"; + LOGV2_DEBUG(21256, 1, "replSet setting last Timestamp"); const OpTime opTime = fassert(28696, OpTime::parseFromOplogEntry(lastOp)); setNewTimestamp(opCtx->getServiceContext(), opTime.getTimestamp()); } diff --git a/src/mongo/db/repl/oplog_applier.cpp b/src/mongo/db/repl/oplog_applier.cpp index f505933bbdc..294930161ec 100644 --- a/src/mongo/db/repl/oplog_applier.cpp +++ b/src/mongo/db/repl/oplog_applier.cpp @@ -36,6 +36,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/time_support.h" @@ -63,9 +64,9 @@ Future<void> OplogApplier::startup() { auto callback = [ this, promise = std::move(pf.promise) ](const CallbackArgs& args) mutable noexcept { invariant(args.status); - log() << "Starting oplog application"; + LOGV2(21224, "Starting oplog application"); _run(_oplogBuffer); - log() << "Finished oplog application"; + LOGV2(21225, "Finished oplog application"); promise.setWith([] {}); }; invariant(_executor->scheduleWork(std::move(callback)).getStatus()); @@ -75,7 +76,7 @@ Future<void> OplogApplier::startup() { void OplogApplier::shutdown() { // Shutdown will hang if this failpoint is enabled. if (globalFailPointRegistry().find("rsSyncApplyStop")->shouldFail()) { - severe() << "Turn off rsSyncApplyStop before attempting clean shutdown"; + LOGV2_FATAL(21227, "Turn off rsSyncApplyStop before attempting clean shutdown"); fassertFailedNoTrace(40304); } @@ -110,7 +111,10 @@ void OplogApplier::enqueue(OperationContext* opCtx, OplogBuffer::Batch::const_iterator end) { static Occasionally sampler; if (sampler.tick()) { - LOG(2) << "oplog buffer has " << _oplogBuffer->getSize() << " bytes"; + LOGV2_DEBUG(21226, + 2, + "oplog buffer has {oplogBuffer_getSize} bytes", + "oplogBuffer_getSize"_attr = _oplogBuffer->getSize()); } _oplogBuffer->push(opCtx, begin, end); } diff --git a/src/mongo/db/repl/oplog_applier_impl.cpp b/src/mongo/db/repl/oplog_applier_impl.cpp index 1ac70f2a05e..e54bc128219 100644 --- a/src/mongo/db/repl/oplog_applier_impl.cpp +++ b/src/mongo/db/repl/oplog_applier_impl.cpp @@ -45,6 +45,7 @@ #include "mongo/db/repl/insert_group.h" #include "mongo/db/repl/transaction_oplog_application.h" #include "mongo/db/stats/timer_stats.h" +#include "mongo/logv2/log.h" #include "mongo/platform/basic.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -125,7 +126,7 @@ Status finishAndLogApply(OperationContext* opCtx, s << redact(entryOrGroupedInserts.toBSON()); s << ", took " << opDuration << "ms"; - log() << s.str(); + LOGV2(21228, "{s_str}", "s_str"_attr = s.str()); } } return finalStatus; @@ -434,8 +435,9 @@ void OplogApplierImpl::_run(OplogBuffer* oplogBuffer) { // For pausing replication in tests. if (MONGO_unlikely(rsSyncApplyStop.shouldFail())) { - log() << "Oplog Applier - rsSyncApplyStop fail point enabled. Blocking until fail " - "point is disabled."; + LOGV2(21229, + "Oplog Applier - rsSyncApplyStop fail point enabled. Blocking until fail " + "point is disabled."); rsSyncApplyStop.pauseWhileSet(&opCtx); } @@ -602,7 +604,7 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx, std::vector<OplogEntry> ops) { invariant(!ops.empty()); - LOG(2) << "replication batch size is " << ops.size(); + LOGV2_DEBUG(21230, 2, "replication batch size is {ops_size}", "ops_size"_attr = ops.size()); // Stop all readers until we're done. This also prevents doc-locking engines from deleting old // entries from the oplog until we finish writing. @@ -610,7 +612,7 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx, invariant(_replCoord); if (_replCoord->getApplierState() == ReplicationCoordinator::ApplierState::Stopped) { - severe() << "attempting to replicate ops while primary"; + LOGV2_FATAL(21234, "attempting to replicate ops while primary"); return {ErrorCodes::CannotApplyOplogWhilePrimary, "attempting to replicate ops while primary"}; } @@ -653,8 +655,9 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx, // Use this fail point to hold the PBWM lock after we have written the oplog entries but // before we have applied them. if (MONGO_unlikely(pauseBatchApplicationAfterWritingOplogEntries.shouldFail())) { - log() << "pauseBatchApplicationAfterWritingOplogEntries fail point enabled. Blocking " - "until fail point is disabled."; + LOGV2(21231, + "pauseBatchApplicationAfterWritingOplogEntries fail point enabled. Blocking " + "until fail point is disabled."); pauseBatchApplicationAfterWritingOplogEntries.pauseWhileSet(opCtx); } @@ -699,12 +702,17 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx, for (auto it = statusVector.cbegin(); it != statusVector.cend(); ++it) { const auto& status = *it; if (!status.isOK()) { - severe() - << "Failed to apply batch of operations. Number of operations in batch: " - << ops.size() << ". First operation: " << redact(ops.front().toBSON()) - << ". Last operation: " << redact(ops.back().toBSON()) - << ". Oplog application failed in writer thread " - << std::distance(statusVector.cbegin(), it) << ": " << redact(status); + LOGV2_FATAL(21235, + "Failed to apply batch of operations. Number of operations in " + "batch: {ops_size}. First operation: {ops_front}. Last operation: " + "{ops_back}. Oplog application failed in writer thread " + "{std_distance_statusVector_cbegin_it}: {status}", + "ops_size"_attr = ops.size(), + "ops_front"_attr = redact(ops.front().toBSON()), + "ops_back"_attr = redact(ops.back().toBSON()), + "std_distance_statusVector_cbegin_it"_attr = + std::distance(statusVector.cbegin(), it), + "status"_attr = redact(status)); return status; } } @@ -721,12 +729,14 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx, // Use this fail point to hold the PBWM lock and prevent the batch from completing. if (MONGO_unlikely(pauseBatchApplicationBeforeCompletion.shouldFail())) { - log() << "pauseBatchApplicationBeforeCompletion fail point enabled. Blocking until fail " - "point is disabled."; + LOGV2(21232, + "pauseBatchApplicationBeforeCompletion fail point enabled. Blocking until fail " + "point is disabled."); while (MONGO_unlikely(pauseBatchApplicationBeforeCompletion.shouldFail())) { if (inShutdown()) { - severe() << "Turn off pauseBatchApplicationBeforeCompletion before attempting " - "clean shutdown"; + LOGV2_FATAL(21236, + "Turn off pauseBatchApplicationBeforeCompletion before attempting " + "clean shutdown"); fassertFailedNoTrace(50798); } sleepmillis(100); @@ -904,10 +914,10 @@ Status applyOplogEntryOrGroupedInserts(OperationContext* opCtx, auto applyStartTime = clockSource->now(); if (MONGO_unlikely(hangAfterRecordingOpApplicationStartTime.shouldFail())) { - log() << "applyOplogEntryOrGroupedInserts - fail point " - "hangAfterRecordingOpApplicationStartTime " - "enabled. " - << "Blocking until fail point is disabled. "; + LOGV2(21233, + "applyOplogEntryOrGroupedInserts - fail point " + "hangAfterRecordingOpApplicationStartTime " + "enabled. Blocking until fail point is disabled. "); hangAfterRecordingOpApplicationStartTime.pauseWhileSet(); } @@ -1046,8 +1056,10 @@ Status OplogApplierImpl::applyOplogBatchPerWorker(OperationContext* opCtx, continue; } - severe() << "Error applying operation (" << redact(entry.toBSON()) - << "): " << causedBy(redact(status)); + LOGV2_FATAL(21237, + "Error applying operation ({entry}): {causedBy_status}", + "entry"_attr = redact(entry.toBSON()), + "causedBy_status"_attr = causedBy(redact(status))); return status; } } catch (const DBException& e) { @@ -1058,8 +1070,10 @@ Status OplogApplierImpl::applyOplogBatchPerWorker(OperationContext* opCtx, continue; } - severe() << "writer worker caught exception: " << redact(e) - << " on: " << redact(entry.toBSON()); + LOGV2_FATAL(21238, + "writer worker caught exception: {e} on: {entry}", + "e"_attr = redact(e), + "entry"_attr = redact(entry.toBSON())); return e.toStatus(); } } diff --git a/src/mongo/db/repl/oplog_batcher.cpp b/src/mongo/db/repl/oplog_batcher.cpp index 80f0ffbbec6..3d2348ad8a1 100644 --- a/src/mongo/db/repl/oplog_batcher.cpp +++ b/src/mongo/db/repl/oplog_batcher.cpp @@ -35,6 +35,7 @@ #include "mongo/db/commands/txn_cmds_gen.h" #include "mongo/db/repl/oplog_applier.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -173,7 +174,7 @@ StatusWith<std::vector<OplogEntry>> OplogBatcher::getNextApplierBatch( std::string message = str::stream() << "expected oplog version " << OplogEntry::kOplogVersion << " but found version " << entry.getVersion() << " in oplog entry: " << redact(entry.toBSON()); - severe() << message; + LOGV2_FATAL(21240, "{message}", "message"_attr = message); return {ErrorCodes::BadValue, message}; } @@ -319,7 +320,9 @@ void OplogBatcher::_run(StorageInterface* storageInterface) { // Check the oplog buffer after the applier state to ensure the producer is stopped. if (isDraining && _oplogBuffer->isEmpty()) { ops.setTermWhenExhausted(termWhenBufferIsEmpty); - log() << "Oplog buffer has been drained in term " << termWhenBufferIsEmpty; + LOGV2(21239, + "Oplog buffer has been drained in term {termWhenBufferIsEmpty}", + "termWhenBufferIsEmpty"_attr = termWhenBufferIsEmpty); } else { // Don't emit empty batches. continue; diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index afff88413c3..0609e46c634 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -41,6 +41,7 @@ #include "mongo/db/repl/replication_auth.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/stats/timer_stats.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" @@ -467,7 +468,7 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons [&](auto&&) { status = {ErrorCodes::FailPointEnabled, "stopReplProducerOnDocument fail point is enabled."}; - log() << status.reason(); + LOGV2(21264, "{status_reason}", "status_reason"_attr = status.reason()); }, [&](const BSONObj& data) { auto opCtx = cc().makeOperationContext(); @@ -485,17 +486,25 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons auto firstDocToApply = documents.cbegin(); if (!documents.empty()) { - LOG(2) << "oplog fetcher read " << documents.size() - << " operations from remote oplog starting at " << documents.front()["ts"] - << " and ending at " << documents.back()["ts"]; + LOGV2_DEBUG(21265, + 2, + "oplog fetcher read {documents_size} operations from remote oplog starting at " + "{documents_front_ts} and ending at {documents_back_ts}", + "documents_size"_attr = documents.size(), + "documents_front_ts"_attr = documents.front()["ts"], + "documents_back_ts"_attr = documents.back()["ts"]); } else { - LOG(2) << "oplog fetcher read 0 operations from remote oplog"; + LOGV2_DEBUG(21266, 2, "oplog fetcher read 0 operations from remote oplog"); } auto oqMetadataResult = parseOplogQueryMetadata(queryResponse); if (!oqMetadataResult.isOK()) { - error() << "invalid oplog query metadata from sync source " << _getSource() << ": " - << oqMetadataResult.getStatus() << ": " << queryResponse.otherFields.metadata; + LOGV2_ERROR(21276, + "invalid oplog query metadata from sync source {getSource}: " + "{oqMetadataResult_getStatus}: {queryResponse_otherFields_metadata}", + "getSource"_attr = _getSource(), + "oqMetadataResult_getStatus"_attr = oqMetadataResult.getStatus(), + "queryResponse_otherFields_metadata"_attr = queryResponse.otherFields.metadata); return oqMetadataResult.getStatus(); } auto oqMetadata = oqMetadataResult.getValue(); @@ -519,7 +528,10 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons return status; } - LOG(1) << "oplog fetcher successfully fetched from " << _getSource(); + LOGV2_DEBUG(21267, + 1, + "oplog fetcher successfully fetched from {getSource}", + "getSource"_attr = _getSource()); // We do not always enqueue the first document. We elect to skip it for the following // reasons: @@ -553,8 +565,12 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons const auto& metadataObj = queryResponse.otherFields.metadata; auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(metadataObj); if (!metadataResult.isOK()) { - error() << "invalid replication metadata from sync source " << _getSource() << ": " - << metadataResult.getStatus() << ": " << metadataObj; + LOGV2_ERROR(21277, + "invalid replication metadata from sync source {getSource}: " + "{metadataResult_getStatus}: {metadataObj}", + "getSource"_attr = _getSource(), + "metadataResult_getStatus"_attr = metadataResult.getStatus(), + "metadataObj"_attr = metadataObj); return metadataResult.getStatus(); } replSetMetadata = metadataResult.getValue(); @@ -838,7 +854,7 @@ void NewOplogFetcher::_runQuery(const executor::TaskExecutor::CallbackArgs& call if (MONGO_unlikely(logAfterOplogFetcherConnCreated.shouldFail())) { // Used in tests that wait for this failpoint to be entered to ensure the DBClientConnection // was created. - log() << "logAfterOplogFetcherConnCreated failpoint enabled."; + LOGV2(21268, "logAfterOplogFetcherConnCreated failpoint enabled."); } hangAfterOplogFetcherCallbackScheduled.pauseWhileSet(); @@ -1074,7 +1090,7 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { [&](auto&&) { status = {ErrorCodes::FailPointEnabled, "stopReplProducerOnDocument fail point is enabled."}; - log() << status.reason(); + LOGV2(21269, "{status_reason}", "status_reason"_attr = status.reason()); }, [&](const BSONObj& data) { auto opCtx = cc().makeOperationContext(); @@ -1091,17 +1107,25 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { auto firstDocToApply = documents.cbegin(); if (!documents.empty()) { - LOG(2) << "oplog fetcher read " << documents.size() - << " operations from remote oplog starting at " << documents.front()["ts"] - << " and ending at " << documents.back()["ts"]; + LOGV2_DEBUG(21270, + 2, + "oplog fetcher read {documents_size} operations from remote oplog starting at " + "{documents_front_ts} and ending at {documents_back_ts}", + "documents_size"_attr = documents.size(), + "documents_front_ts"_attr = documents.front()["ts"], + "documents_back_ts"_attr = documents.back()["ts"]); } else { - LOG(2) << "oplog fetcher read 0 operations from remote oplog"; + LOGV2_DEBUG(21271, 2, "oplog fetcher read 0 operations from remote oplog"); } auto oqMetadataResult = parseOplogQueryMetadata(_metadataObj); if (!oqMetadataResult.isOK()) { - error() << "invalid oplog query metadata from sync source " << _source << ": " - << oqMetadataResult.getStatus() << ": " << _metadataObj; + LOGV2_ERROR(21278, + "invalid oplog query metadata from sync source {source}: " + "{oqMetadataResult_getStatus}: {metadataObj}", + "source"_attr = _source, + "oqMetadataResult_getStatus"_attr = oqMetadataResult.getStatus(), + "metadataObj"_attr = _metadataObj); return oqMetadataResult.getStatus(); } auto oqMetadata = oqMetadataResult.getValue(); @@ -1124,7 +1148,8 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { return status; } - LOG(1) << "oplog fetcher successfully fetched from " << _source; + LOGV2_DEBUG( + 21272, 1, "oplog fetcher successfully fetched from {source}", "source"_attr = _source); // We do not always enqueue the first document. We elect to skip it for the following // reasons: @@ -1156,8 +1181,12 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { if (receivedReplMetadata) { auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(_metadataObj); if (!metadataResult.isOK()) { - error() << "invalid replication metadata from sync source " << _source << ": " - << metadataResult.getStatus() << ": " << _metadataObj; + LOGV2_ERROR(21279, + "invalid replication metadata from sync source {source}: " + "{metadataResult_getStatus}: {metadataObj}", + "source"_attr = _source, + "metadataResult_getStatus"_attr = metadataResult.getStatus(), + "metadataObj"_attr = _metadataObj); return metadataResult.getStatus(); } replSetMetadata = metadataResult.getValue(); @@ -1210,7 +1239,10 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { } auto lastDocOpTime = lastDocOpTimeRes.getValue(); - LOG(3) << "Oplog fetcher setting last fetched optime ahead after batch: " << lastDocOpTime; + LOGV2_DEBUG(21273, + 3, + "Oplog fetcher setting last fetched optime ahead after batch: {lastDocOpTime}", + "lastDocOpTime"_attr = lastDocOpTime); stdx::lock_guard<Latch> lock(_mutex); _lastFetched = lastDocOpTime; @@ -1223,13 +1255,17 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) { bool NewOplogFetcher::OplogFetcherRestartDecisionDefault::shouldContinue(NewOplogFetcher* fetcher, Status status) { if (_numRestarts == _maxRestarts) { - log() << "Error returned from oplog query (no more query restarts left): " - << redact(status); + LOGV2(21274, + "Error returned from oplog query (no more query restarts left): {status}", + "status"_attr = redact(status)); return false; } - log() << "Recreating cursor for oplog fetcher due to error: " << redact(status) - << ". Last fetched optime: " << fetcher->_getLastOpTimeFetched() - << ". Attempts remaining: " << (_maxRestarts - _numRestarts); + LOGV2(21275, + "Recreating cursor for oplog fetcher due to error: {status}. Last fetched optime: " + "{fetcher_getLastOpTimeFetched}. Attempts remaining: {maxRestarts_numRestarts}", + "status"_attr = redact(status), + "fetcher_getLastOpTimeFetched"_attr = fetcher->_getLastOpTimeFetched(), + "maxRestarts_numRestarts"_attr = (_maxRestarts - _numRestarts)); _numRestarts++; return true; } diff --git a/src/mongo/db/repl/repl_client_info.cpp b/src/mongo/db/repl/repl_client_info.cpp index 0690e7b483e..119ec569a65 100644 --- a/src/mongo/db/repl/repl_client_info.cpp +++ b/src/mongo/db/repl/repl_client_info.cpp @@ -36,6 +36,7 @@ #include "mongo/db/client.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/logv2/log.h" #include "mongo/util/decorable.h" #include "mongo/util/log.h" @@ -103,10 +104,13 @@ void ReplClientInfo::setLastOpToSystemLastOpTime(OperationContext* opCtx) { if (systemOpTime >= _lastOp) { _lastOp = systemOpTime; } else { - log() << "Not setting the last OpTime for this Client from " << _lastOp - << " to the current system time of " << systemOpTime - << " as that would be moving the OpTime backwards. This should only happen if " - "there was a rollback recently"; + LOGV2(21280, + "Not setting the last OpTime for this Client from {lastOp} to the current system " + "time of {systemOpTime} as that would be moving the OpTime backwards. This " + "should only happen if " + "there was a rollback recently", + "lastOp"_attr = _lastOp, + "systemOpTime"_attr = systemOpTime); } lastOpInfo(opCtx).lastOpSetExplicitly = true; @@ -122,7 +126,10 @@ void ReplClientInfo::setLastOpToSystemLastOpTimeIgnoringInterrupt(OperationConte } catch (const ExceptionForCat<ErrorCategory::Interruption>& e) { // In most cases, it is safe to ignore interruption errors because we cannot use the same // OperationContext to wait for writeConcern anyways. - LOG(2) << "Ignoring set last op interruption error: " << e.toStatus(); + LOGV2_DEBUG(21281, + 2, + "Ignoring set last op interruption error: {e_toStatus}", + "e_toStatus"_attr = e.toStatus()); } } diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp index a9c7bdc5336..8203c36f567 100644 --- a/src/mongo/db/repl/repl_set_commands.cpp +++ b/src/mongo/db/repl/repl_set_commands.cpp @@ -62,6 +62,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/executor/network_interface.h" +#include "mongo/logv2/log.h" #include "mongo/transport/session.h" #include "mongo/transport/transport_layer.h" #include "mongo/util/decimal_counter.h" @@ -103,7 +104,7 @@ public: const string&, const BSONObj& cmdObj, BSONObjBuilder& result) { - log() << "replSetTest command received: " << cmdObj.toString(); + LOGV2(21573, "replSetTest command received: {cmdObj}", "cmdObj"_attr = cmdObj.toString()); auto replCoord = ReplicationCoordinator::get(getGlobalServiceContext()); @@ -120,8 +121,10 @@ public: status = bsonExtractIntegerField(cmdObj, "timeoutMillis", &timeoutMillis); uassertStatusOK(status); Milliseconds timeout(timeoutMillis); - log() << "replSetTest: waiting " << timeout << " for member state to become " - << expectedState; + LOGV2(21574, + "replSetTest: waiting {timeout} for member state to become {expectedState}", + "timeout"_attr = timeout, + "expectedState"_attr = expectedState); status = replCoord->waitForMemberState(expectedState, timeout); @@ -132,7 +135,9 @@ public: auto status = bsonExtractIntegerField(cmdObj, "waitForDrainFinish", &timeoutMillis); uassertStatusOK(status); Milliseconds timeout(timeoutMillis); - log() << "replSetTest: waiting " << timeout << " for applier buffer to finish draining"; + LOGV2(21575, + "replSetTest: waiting {timeout} for applier buffer to finish draining", + "timeout"_attr = timeout); status = replCoord->waitForDrainFinish(timeout); @@ -275,7 +280,7 @@ void parseReplSetSeedList(ReplicationCoordinatorExternalState* externalState, seedSet.insert(m); // uassert(13101, "can't use localhost in replset host list", !m.isLocalHost()); if (externalState->isSelf(m, getGlobalServiceContext())) { - LOG(1) << "ignoring seed " << m.toString() << " (=self)"; + LOGV2_DEBUG(21576, 1, "ignoring seed {m} (=self)", "m"_attr = m.toString()); } else { seeds->push_back(m); } @@ -315,7 +320,7 @@ public: "no configuration specified. " "Using a default configuration for the set"; result.append("info2", noConfigMessage); - log() << "initiate : " << noConfigMessage; + LOGV2(21577, "initiate : {noConfigMessage}", "noConfigMessage"_attr = noConfigMessage); ReplicationCoordinatorExternalStateImpl externalState( opCtx->getServiceContext(), @@ -346,7 +351,9 @@ public: } b.appendArray("members", members.obj()); configObj = b.obj(); - log() << "created this configuration for initiation : " << configObj.toString(); + LOGV2(21578, + "created this configuration for initiation : {configObj}", + "configObj"_attr = configObj.toString()); } if (configObj.getField("version").eoo()) { @@ -522,12 +529,12 @@ public: uassertStatusOK(status); } - log() << "Attempting to step down in response to replSetStepDown command"; + LOGV2(21579, "Attempting to step down in response to replSetStepDown command"); ReplicationCoordinator::get(opCtx)->stepDown( opCtx, force, Seconds(secondaryCatchUpPeriodSecs), Seconds(stepDownForSecs)); - log() << "replSetStepDown command completed"; + LOGV2(21580, "replSetStepDown command completed"); onExitGuard.dismiss(); return true; @@ -726,13 +733,15 @@ public: Status status = ReplicationCoordinator::get(opCtx)->checkReplEnabledForCommand(&result); uassertStatusOK(status); - log() << "Received replSetStepUp request"; + LOGV2(21581, "Received replSetStepUp request"); const bool skipDryRun = cmdObj["skipDryRun"].trueValue(); status = ReplicationCoordinator::get(opCtx)->stepUpIfEligible(skipDryRun); if (!status.isOK()) { - log() << "replSetStepUp request failed" << causedBy(status); + LOGV2(21582, + "replSetStepUp request failed{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } uassertStatusOK(status); @@ -761,13 +770,15 @@ public: BSONObjBuilder& result) override { Status status = ReplicationCoordinator::get(opCtx)->checkReplEnabledForCommand(&result); uassertStatusOK(status); - log() << "Received replSetAbortPrimaryCatchUp request"; + LOGV2(21583, "Received replSetAbortPrimaryCatchUp request"); status = ReplicationCoordinator::get(opCtx)->abortCatchupIfNeeded( ReplicationCoordinator::PrimaryCatchUpConclusionReason:: kFailedWithReplSetAbortPrimaryCatchUpCmd); if (!status.isOK()) { - log() << "replSetAbortPrimaryCatchUp request failed" << causedBy(status); + LOGV2(21584, + "replSetAbortPrimaryCatchUp request failed{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } uassertStatusOK(status); return true; diff --git a/src/mongo/db/repl/replication_consistency_markers_impl.cpp b/src/mongo/db/repl/replication_consistency_markers_impl.cpp index 8d7046a89f2..6464b0311cc 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl.cpp @@ -39,6 +39,7 @@ #include "mongo/db/repl/optime.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/repl/storage_interface.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -93,7 +94,7 @@ void ReplicationConsistencyMarkersImpl::_updateMinValidDocument( } void ReplicationConsistencyMarkersImpl::initializeMinValidDocument(OperationContext* opCtx) { - LOG(3) << "Initializing minValid document"; + LOGV2_DEBUG(21282, 3, "Initializing minValid document"); // This initializes the values of the required fields if they are not already set. // If one of the fields is already set, the $max will prefer the existing value since it @@ -114,22 +115,25 @@ void ReplicationConsistencyMarkersImpl::initializeMinValidDocument(OperationCont bool ReplicationConsistencyMarkersImpl::getInitialSyncFlag(OperationContext* opCtx) const { auto doc = _getMinValidDocument(opCtx); if (!doc) { - LOG(3) << "No min valid document found, returning initial sync flag value of false."; + LOGV2_DEBUG( + 21283, 3, "No min valid document found, returning initial sync flag value of false."); return false; } boost::optional<bool> flag = doc->getInitialSyncFlag(); if (!flag) { - LOG(3) << "No initial sync flag set, returning initial sync flag value of false."; + LOGV2_DEBUG( + 21284, 3, "No initial sync flag set, returning initial sync flag value of false."); return false; } - LOG(3) << "returning initial sync flag value of " << flag.get(); + LOGV2_DEBUG( + 21285, 3, "returning initial sync flag value of {flag_get}", "flag_get"_attr = flag.get()); return flag.get(); } void ReplicationConsistencyMarkersImpl::setInitialSyncFlag(OperationContext* opCtx) { - LOG(3) << "setting initial sync flag"; + LOGV2_DEBUG(21286, 3, "setting initial sync flag"); TimestampedBSONObj update; update.obj = BSON("$set" << kInitialSyncFlag); @@ -143,7 +147,7 @@ void ReplicationConsistencyMarkersImpl::setInitialSyncFlag(OperationContext* opC } void ReplicationConsistencyMarkersImpl::clearInitialSyncFlag(OperationContext* opCtx) { - LOG(3) << "clearing initial sync flag"; + LOGV2_DEBUG(21287, 3, "clearing initial sync flag"); auto replCoord = repl::ReplicationCoordinator::get(opCtx); OpTimeAndWallTime opTimeAndWallTime = replCoord->getMyLastAppliedOpTimeAndWallTime(); @@ -184,15 +188,22 @@ OpTime ReplicationConsistencyMarkersImpl::getMinValid(OperationContext* opCtx) c auto minValid = OpTime(doc->getMinValidTimestamp(), doc->getMinValidTerm()); - LOG(3) << "returning minvalid: " << minValid.toString() << "(" << minValid.toBSON() << ")"; + LOGV2_DEBUG(21288, + 3, + "returning minvalid: {minValid}({minValid2})", + "minValid"_attr = minValid.toString(), + "minValid2"_attr = minValid.toBSON()); return minValid; } void ReplicationConsistencyMarkersImpl::setMinValid(OperationContext* opCtx, const OpTime& minValid) { - LOG(3) << "setting minvalid to exactly: " << minValid.toString() << "(" << minValid.toBSON() - << ")"; + LOGV2_DEBUG(21289, + 3, + "setting minvalid to exactly: {minValid}({minValid2})", + "minValid"_attr = minValid.toString(), + "minValid2"_attr = minValid.toBSON()); TimestampedBSONObj update; update.obj = BSON("$set" << BSON(MinValidDocument::kMinValidTimestampFieldName @@ -209,8 +220,11 @@ void ReplicationConsistencyMarkersImpl::setMinValid(OperationContext* opCtx, void ReplicationConsistencyMarkersImpl::setMinValidToAtLeast(OperationContext* opCtx, const OpTime& minValid) { - LOG(3) << "setting minvalid to at least: " << minValid.toString() << "(" << minValid.toBSON() - << ")"; + LOGV2_DEBUG(21290, + 3, + "setting minvalid to at least: {minValid}({minValid2})", + "minValid"_attr = minValid.toString(), + "minValid2"_attr = minValid.toBSON()); auto& termField = MinValidDocument::kMinValidTermFieldName; auto& tsField = MinValidDocument::kMinValidTimestampFieldName; @@ -250,7 +264,11 @@ void ReplicationConsistencyMarkersImpl::setAppliedThrough(OperationContext* opCt const OpTime& optime, bool setTimestamp) { invariant(!optime.isNull()); - LOG(3) << "setting appliedThrough to: " << optime.toString() << "(" << optime.toBSON() << ")"; + LOGV2_DEBUG(21291, + 3, + "setting appliedThrough to: {optime}({optime2})", + "optime"_attr = optime.toString(), + "optime2"_attr = optime.toBSON()); // We set the 'appliedThrough' to the provided timestamp. The 'appliedThrough' is only valid // in checkpoints that contain all writes through this timestamp since it indicates the top of @@ -266,7 +284,10 @@ void ReplicationConsistencyMarkersImpl::setAppliedThrough(OperationContext* opCt void ReplicationConsistencyMarkersImpl::clearAppliedThrough(OperationContext* opCtx, const Timestamp& writeTimestamp) { - LOG(3) << "clearing appliedThrough at: " << writeTimestamp.toString(); + LOGV2_DEBUG(21292, + 3, + "clearing appliedThrough at: {writeTimestamp}", + "writeTimestamp"_attr = writeTimestamp.toString()); TimestampedBSONObj update; update.timestamp = writeTimestamp; @@ -281,11 +302,15 @@ OpTime ReplicationConsistencyMarkersImpl::getAppliedThrough(OperationContext* op auto appliedThrough = doc->getAppliedThrough(); if (!appliedThrough) { - LOG(3) << "No appliedThrough OpTime set, returning empty appliedThrough OpTime."; + LOGV2_DEBUG( + 21293, 3, "No appliedThrough OpTime set, returning empty appliedThrough OpTime."); return {}; } - LOG(3) << "returning appliedThrough: " << appliedThrough->toString() << "(" - << appliedThrough->toBSON() << ")"; + LOGV2_DEBUG(21294, + 3, + "returning appliedThrough: {appliedThrough}({appliedThrough2})", + "appliedThrough"_attr = appliedThrough->toString(), + "appliedThrough2"_attr = appliedThrough->toBSON()); return appliedThrough.get(); } @@ -313,8 +338,11 @@ ReplicationConsistencyMarkersImpl::_getOplogTruncateAfterPointDocument( void ReplicationConsistencyMarkersImpl::ensureFastCountOnOplogTruncateAfterPoint( OperationContext* opCtx) { - LOG(3) << "Updating cached fast-count on collection " << _oplogTruncateAfterPointNss - << " in case an unclean shutdown caused it to become incorrect."; + LOGV2_DEBUG(21295, + 3, + "Updating cached fast-count on collection {oplogTruncateAfterPointNss} in case an " + "unclean shutdown caused it to become incorrect.", + "oplogTruncateAfterPointNss"_attr = _oplogTruncateAfterPointNss); auto result = _storageInterface->findSingleton(opCtx, _oplogTruncateAfterPointNss); @@ -354,7 +382,10 @@ void ReplicationConsistencyMarkersImpl::_upsertOplogTruncateAfterPointDocument( void ReplicationConsistencyMarkersImpl::setOplogTruncateAfterPoint(OperationContext* opCtx, const Timestamp& timestamp) { - LOG(3) << "setting oplog truncate after point to: " << timestamp.toBSON(); + LOGV2_DEBUG(21296, + 3, + "setting oplog truncate after point to: {timestamp}", + "timestamp"_attr = timestamp.toBSON()); _upsertOplogTruncateAfterPointDocument( opCtx, BSON("$set" << BSON(OplogTruncateAfterPointDocument::kOplogTruncateAfterPointFieldName @@ -365,13 +396,14 @@ Timestamp ReplicationConsistencyMarkersImpl::getOplogTruncateAfterPoint( OperationContext* opCtx) const { auto doc = _getOplogTruncateAfterPointDocument(opCtx); if (!doc) { - LOG(3) << "Returning empty oplog truncate after point since document did not exist"; + LOGV2_DEBUG( + 21297, 3, "Returning empty oplog truncate after point since document did not exist"); return {}; } Timestamp out = doc->getOplogTruncateAfterPoint(); - LOG(3) << "returning oplog truncate after point: " << out; + LOGV2_DEBUG(21298, 3, "returning oplog truncate after point: {out}", "out"_attr = out); return out; } diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 08bff69143a..29dfa758378 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -94,6 +94,7 @@ #include "mongo/executor/network_interface.h" #include "mongo/executor/network_interface_factory.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/egress_metadata_hook_list.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog_cache_loader.h" @@ -238,13 +239,13 @@ void ReplicationCoordinatorExternalStateImpl::startSteadyStateReplication( _bgSync = std::make_unique<BackgroundSync>(replCoord, this, _replicationProcess, _oplogApplier.get()); - log() << "Starting replication fetcher thread"; + LOGV2(21299, "Starting replication fetcher thread"); _bgSync->startup(opCtx); - log() << "Starting replication applier thread"; + LOGV2(21300, "Starting replication applier thread"); _oplogApplierShutdownFuture = _oplogApplier->startup(); - log() << "Starting replication reporter thread"; + LOGV2(21301, "Starting replication reporter thread"); invariant(!_syncSourceFeedbackThread); // Get the pointer while holding the lock so that _stopDataReplication_inlock() won't // leave the unique pointer empty if the _syncSourceFeedbackThread's function starts @@ -275,18 +276,18 @@ void ReplicationCoordinatorExternalStateImpl::_stopDataReplication_inlock( // _syncSourceFeedbackThread should be joined before _bgSync's shutdown because it has // a pointer of _bgSync. if (oldSSF) { - log() << "Stopping replication reporter thread"; + LOGV2(21302, "Stopping replication reporter thread"); _syncSourceFeedback.shutdown(); oldSSF->join(); } if (oldBgSync) { - log() << "Stopping replication fetcher thread"; + LOGV2(21303, "Stopping replication fetcher thread"); oldBgSync->shutdown(opCtx); } if (oldApplier) { - log() << "Stopping replication applier thread"; + LOGV2(21304, "Stopping replication applier thread"); oldApplier->shutdown(); } @@ -321,11 +322,12 @@ void ReplicationCoordinatorExternalStateImpl::startThreads(const ReplSettings& s return; } if (_inShutdown) { - log() << "Not starting replication storage threads because replication is shutting down."; + LOGV2(21305, + "Not starting replication storage threads because replication is shutting down."); return; } - log() << "Starting replication storage threads"; + LOGV2(21306, "Starting replication storage threads"); _service->getStorageEngine()->setJournalListener(this); _oplogApplierTaskExecutor = @@ -383,7 +385,7 @@ void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx) _stopDataReplication_inlock(opCtx, lk); - log() << "Stopping replication storage threads"; + LOGV2(21307, "Stopping replication storage threads"); _taskExecutor->shutdown(); _oplogApplierTaskExecutor->shutdown(); @@ -396,7 +398,7 @@ void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx) // itself can block on the ReplicationCoordinator mutex. It is safe to access _noopWriter // outside of _threadMutex because _noopWriter is protected by its own mutex. invariant(_noopWriter); - LOG(1) << "Stopping noop writer"; + LOGV2_DEBUG(21308, 1, "Stopping noop writer"); _noopWriter->stopWritingPeriodicNoops(); // We must wait for _taskExecutor outside of _threadMutex, since _taskExecutor is used to run @@ -877,7 +879,7 @@ void ReplicationCoordinatorExternalStateImpl::_dropAllTempCollections(OperationC // replica set members. if (*it == "local") continue; - LOG(2) << "Removing temporary collections from " << *it; + LOGV2_DEBUG(21309, 2, "Removing temporary collections from {it}", "it"_attr = *it); AutoGetDb autoDb(opCtx, *it, MODE_IX); invariant(autoDb.getDb(), str::stream() << "Unable to get reference to database " << *it); autoDb.getDb()->clearTmpCollections(opCtx); @@ -922,10 +924,11 @@ void ReplicationCoordinatorExternalStateImpl::notifyOplogMetadataWaiters( _taskExecutor.get(), [committedOpTime, reaper](const executor::TaskExecutor::CallbackArgs& args) { if (MONGO_unlikely(dropPendingCollectionReaperHang.shouldFail())) { - log() << "fail point dropPendingCollectionReaperHang enabled. " - "Blocking until fail point is disabled. " - "committedOpTime: " - << committedOpTime; + LOGV2(21310, + "fail point dropPendingCollectionReaperHang enabled. " + "Blocking until fail point is disabled. " + "committedOpTime: {committedOpTime}", + "committedOpTime"_attr = committedOpTime); dropPendingCollectionReaperHang.pauseWhileSet(); } auto opCtx = cc().makeOperationContext(); diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index f1db12180a2..43a9eab03a2 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -88,6 +88,7 @@ #include "mongo/db/write_concern_options.h" #include "mongo/executor/connection_pool_stats.h" #include "mongo/executor/network_interface.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/rpc/metadata/repl_set_metadata.h" @@ -443,12 +444,14 @@ bool ReplicationCoordinatorImpl::_startLoadLocalConfig(OperationContext* opCtx) StatusWith<LastVote> lastVote = _externalState->loadLocalLastVoteDocument(opCtx); if (!lastVote.isOK()) { - severe() << "Error loading local voted for document at startup; " << lastVote.getStatus(); + LOGV2_FATAL(21429, + "Error loading local voted for document at startup; {lastVote_getStatus}", + "lastVote_getStatus"_attr = lastVote.getStatus()); fassertFailedNoTrace(40367); } if (lastVote.getValue().getTerm() == OpTime::kInitialTerm) { // This log line is checked in unit tests. - log() << "Did not find local initialized voted for document at startup."; + LOGV2(21311, "Did not find local initialized voted for document at startup."); } { stdx::lock_guard<Latch> lk(_mutex); @@ -459,38 +462,45 @@ bool ReplicationCoordinatorImpl::_startLoadLocalConfig(OperationContext* opCtx) auto status = _replicationProcess->refreshRollbackID(opCtx); if (!status.isOK()) { if (status == ErrorCodes::NamespaceNotFound) { - log() << "Did not find local Rollback ID document at startup. Creating one."; + LOGV2(21312, "Did not find local Rollback ID document at startup. Creating one."); auto initializingStatus = _replicationProcess->initializeRollbackID(opCtx); fassert(40424, initializingStatus); } else { - severe() << "Error loading local Rollback ID document at startup; " << status; + LOGV2_FATAL(21430, + "Error loading local Rollback ID document at startup; {status}", + "status"_attr = status); fassertFailedNoTrace(40428); } } StatusWith<BSONObj> cfg = _externalState->loadLocalConfigDocument(opCtx); if (!cfg.isOK()) { - log() << "Did not find local replica set configuration document at startup; " - << cfg.getStatus(); + LOGV2(21313, + "Did not find local replica set configuration document at startup; {cfg_getStatus}", + "cfg_getStatus"_attr = cfg.getStatus()); return true; } ReplSetConfig localConfig; status = localConfig.initialize(cfg.getValue()); if (!status.isOK()) { if (status.code() == ErrorCodes::RepairedReplicaSetNode) { - severe() - << "This instance has been repaired and may contain modified replicated data that " - "would not match other replica set members. To see your repaired data, start " - "mongod without the --replSet option. When you are finished recovering your " - "data and would like to perform a complete re-sync, please refer to the " - "documentation here: " - "https://docs.mongodb.com/manual/tutorial/resync-replica-set-member/"; + LOGV2_FATAL( + 21431, + "This instance has been repaired and may contain modified replicated data that " + "would not match other replica set members. To see your repaired data, start " + "mongod without the --replSet option. When you are finished recovering your " + "data and would like to perform a complete re-sync, please refer to the " + "documentation here: " + "https://docs.mongodb.com/manual/tutorial/resync-replica-set-member/"); fassertFailedNoTrace(50923); } - error() << "Locally stored replica set configuration does not parse; See " - "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config " - "for information on how to recover from this. Got \"" - << status << "\" while parsing " << cfg.getValue(); + LOGV2_ERROR(21414, + "Locally stored replica set configuration does not parse; See " + "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config " + "for information on how to recover from this. Got \"{status}\" while parsing " + "{cfg_getValue}", + "status"_attr = status, + "cfg_getValue"_attr = cfg.getValue()); fassertFailedNoTrace(28545); } @@ -535,7 +545,10 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig( const StatusWith<OpTimeAndWallTime>& lastOpTimeAndWallTimeStatus, const StatusWith<LastVote>& lastVoteStatus) { if (!cbData.status.isOK()) { - LOG(1) << "Loading local replica set configuration failed due to " << cbData.status; + LOGV2_DEBUG(21314, + 1, + "Loading local replica set configuration failed due to {cbData_status}", + "cbData_status"_attr = cbData.status); return; } @@ -544,37 +557,51 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig( if (!myIndex.isOK()) { if (myIndex.getStatus() == ErrorCodes::NodeNotFound || myIndex.getStatus() == ErrorCodes::InvalidReplicaSetConfig) { - warning() << "Locally stored replica set configuration does not have a valid entry " - "for the current node; waiting for reconfig or remote heartbeat; Got \"" - << myIndex.getStatus() << "\" while validating " << localConfig.toBSON(); + LOGV2_WARNING(21405, + "Locally stored replica set configuration does not have a valid entry " + "for the current node; waiting for reconfig or remote heartbeat; Got " + "\"{myIndex_getStatus}\" while validating {localConfig}", + "myIndex_getStatus"_attr = myIndex.getStatus(), + "localConfig"_attr = localConfig.toBSON()); myIndex = StatusWith<int>(-1); } else { - error() << "Locally stored replica set configuration is invalid; See " - "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config" - " for information on how to recover from this. Got \"" - << myIndex.getStatus() << "\" while validating " << localConfig.toBSON(); + LOGV2_ERROR(21415, + "Locally stored replica set configuration is invalid; See " + "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config" + " for information on how to recover from this. Got \"{myIndex_getStatus}\" " + "while validating {localConfig}", + "myIndex_getStatus"_attr = myIndex.getStatus(), + "localConfig"_attr = localConfig.toBSON()); fassertFailedNoTrace(28544); } } if (localConfig.getReplSetName() != _settings.ourSetName()) { - warning() << "Local replica set configuration document reports set name of " - << localConfig.getReplSetName() << ", but command line reports " - << _settings.ourSetName() << "; waiting for reconfig or remote heartbeat"; + LOGV2_WARNING(21406, + "Local replica set configuration document reports set name of " + "{localConfig_getReplSetName}, but command line reports " + "{settings_ourSetName}; waiting for reconfig or remote heartbeat", + "localConfig_getReplSetName"_attr = localConfig.getReplSetName(), + "settings_ourSetName"_attr = _settings.ourSetName()); myIndex = StatusWith<int>(-1); } if (serverGlobalParams.enableMajorityReadConcern && localConfig.getNumMembers() == 3 && localConfig.getNumDataBearingMembers() == 2) { - log() << startupWarningsLog; - log() << "** WARNING: This replica set has a Primary-Secondary-Arbiter architecture, but " - "readConcern:majority is enabled " - << startupWarningsLog; - log() << "** for this node. This is not a recommended configuration. Please see " - << startupWarningsLog; - log() << "** https://dochub.mongodb.org/core/psa-disable-rc-majority" - << startupWarningsLog; - log() << startupWarningsLog; + LOGV2_OPTIONS(21315, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 21316, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This replica set has a Primary-Secondary-Arbiter architecture, but " + "readConcern:majority is enabled "); + LOGV2_OPTIONS( + 21317, + {logv2::LogTag::kStartupWarnings}, + "** for this node. This is not a recommended configuration. Please see "); + LOGV2_OPTIONS(21318, + {logv2::LogTag::kStartupWarnings}, + "** https://dochub.mongodb.org/core/psa-disable-rc-majority"); + LOGV2_OPTIONS(21319, {logv2::LogTag::kStartupWarnings}, ""); } // Do not check optime, if this node is an arbiter. @@ -583,9 +610,12 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig( OpTimeAndWallTime lastOpTimeAndWallTime = OpTimeAndWallTime(); if (!isArbiter) { if (!lastOpTimeAndWallTimeStatus.isOK()) { - warning() << "Failed to load timestamp and/or wall clock time of most recently applied " - "operation: " - << lastOpTimeAndWallTimeStatus.getStatus(); + LOGV2_WARNING( + 21407, + "Failed to load timestamp and/or wall clock time of most recently applied " + "operation: {lastOpTimeAndWallTimeStatus_getStatus}", + "lastOpTimeAndWallTimeStatus_getStatus"_attr = + lastOpTimeAndWallTimeStatus.getStatus()); } else { lastOpTimeAndWallTime = lastOpTimeAndWallTimeStatus.getValue(); } @@ -646,7 +676,7 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig( // Step down is impossible, so we don't need to wait for the returned event. _updateTerm_inlock(term); } - LOG(1) << "Current term is now " << term; + LOGV2_DEBUG(21320, 1, "Current term is now {term}", "term"_attr = term); _performPostMemberStateUpdateAction(action); if (!isArbiter) { @@ -662,17 +692,21 @@ void ReplicationCoordinatorImpl::_stopDataReplication(OperationContext* opCtx) { _initialSyncer.swap(initialSyncerCopy); } if (initialSyncerCopy) { - LOG(1) - << "ReplicationCoordinatorImpl::_stopDataReplication calling InitialSyncer::shutdown."; + LOGV2_DEBUG( + 21321, + 1, + "ReplicationCoordinatorImpl::_stopDataReplication calling InitialSyncer::shutdown."); const auto status = initialSyncerCopy->shutdown(); if (!status.isOK()) { - warning() << "InitialSyncer shutdown failed: " << status; + LOGV2_WARNING(21408, "InitialSyncer shutdown failed: {status}", "status"_attr = status); } initialSyncerCopy.reset(); // Do not return here, fall through. } - LOG(1) << "ReplicationCoordinatorImpl::_stopDataReplication calling " - "ReplCoordExtState::stopDataReplication."; + LOGV2_DEBUG(21322, + 1, + "ReplicationCoordinatorImpl::_stopDataReplication calling " + "ReplCoordExtState::stopDataReplication."); _externalState->stopDataReplication(opCtx); } @@ -694,7 +728,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, // Do initial sync. if (!_externalState->getTaskExecutor()) { - log() << "not running initial sync during test."; + LOGV2(21323, "not running initial sync during test."); return; } @@ -702,16 +736,20 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, { stdx::lock_guard<Latch> lock(_mutex); if (opTimeStatus == ErrorCodes::CallbackCanceled) { - log() << "Initial Sync has been cancelled: " << opTimeStatus.getStatus(); + LOGV2(21324, + "Initial Sync has been cancelled: {opTimeStatus_getStatus}", + "opTimeStatus_getStatus"_attr = opTimeStatus.getStatus()); return; } else if (!opTimeStatus.isOK()) { if (_inShutdown) { - log() << "Initial Sync failed during shutdown due to " - << opTimeStatus.getStatus(); + LOGV2(21325, + "Initial Sync failed during shutdown due to {opTimeStatus_getStatus}", + "opTimeStatus_getStatus"_attr = opTimeStatus.getStatus()); return; } else { - error() << "Initial sync failed, shutting down now. Restart the server " - "to attempt a new initial sync."; + LOGV2_ERROR(21416, + "Initial sync failed, shutting down now. Restart the server " + "to attempt a new initial sync."); fassertFailedWithStatusNoTrace(40088, opTimeStatus.getStatus()); } } @@ -743,7 +781,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, // Must take the lock to set _initialSyncer, but not call it. stdx::lock_guard<Latch> lock(_mutex); if (_inShutdown) { - log() << "Initial Sync not starting because replication is shutting down."; + LOGV2(21326, "Initial Sync not starting because replication is shutting down."); return; } initialSyncerCopy = std::make_shared<InitialSyncer>( @@ -761,7 +799,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, uassertStatusOK(initialSyncerCopy->startup(opCtx, numInitialSyncAttempts.load())); } catch (const DBException& e) { auto status = e.toStatus(); - log() << "Initial Sync failed to start: " << status; + LOGV2(21327, "Initial Sync failed to start: {status}", "status"_attr = status); if (ErrorCodes::CallbackCanceled == status || ErrorCodes::isShutdownError(status.code())) { return; } @@ -853,7 +891,7 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) { return; } - log() << "shutting down replication subsystems"; + LOGV2(21328, "shutting down replication subsystems"); // Used to shut down outside of the lock. std::shared_ptr<InitialSyncer> initialSyncerCopy; @@ -862,9 +900,10 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) { fassert(28533, !_inShutdown); _inShutdown = true; if (_rsConfigState == kConfigPreStart) { - warning() << "ReplicationCoordinatorImpl::shutdown() called before " - "startup() finished. Shutting down without cleaning up the " - "replication system"; + LOGV2_WARNING(21409, + "ReplicationCoordinatorImpl::shutdown() called before " + "startup() finished. Shutting down without cleaning up the " + "replication system"); return; } if (_rsConfigState == kConfigStartingUp) { @@ -885,10 +924,11 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) { // joining the replication executor is blocking so it must be run outside of the mutex if (initialSyncerCopy) { - LOG(1) << "ReplicationCoordinatorImpl::shutdown calling InitialSyncer::shutdown."; + LOGV2_DEBUG( + 21329, 1, "ReplicationCoordinatorImpl::shutdown calling InitialSyncer::shutdown."); const auto status = initialSyncerCopy->shutdown(); if (!status.isOK()) { - warning() << "InitialSyncer shutdown failed: " << status; + LOGV2_WARNING(21410, "InitialSyncer shutdown failed: {status}", "status"_attr = status); } initialSyncerCopy->join(); initialSyncerCopy.reset(); @@ -1068,7 +1108,9 @@ void ReplicationCoordinatorImpl::signalDrainComplete(OperationContext* opCtx, auto status = _topCoord->completeTransitionToPrimary(firstOpTime); if (status.code() == ErrorCodes::PrimarySteppedDown) { - log() << "Transition to primary failed" << causedBy(status); + LOGV2(21330, + "Transition to primary failed{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); return; } invariant(status); @@ -1082,7 +1124,9 @@ void ReplicationCoordinatorImpl::signalDrainComplete(OperationContext* opCtx, // Update _canAcceptNonLocalWrites _updateMemberStateFromTopologyCoordinator(lk, opCtx); - log() << "transition to primary complete; database writes are now permitted" << rsLog; + LOGV2_OPTIONS(21331, + {logv2::LogTag::kRS}, + "transition to primary complete; database writes are now permitted"); _drainFinishedCond.notify_all(); _externalState->startNoopWriter(_getMyLastAppliedOpTime_inlock()); } @@ -1178,7 +1222,7 @@ void ReplicationCoordinatorImpl::resetMyLastOpTimes() { } void ReplicationCoordinatorImpl::_resetMyLastOpTimes(WithLock lk) { - LOG(1) << "resetting durable/applied optimes."; + LOGV2_DEBUG(21332, 1, "resetting durable/applied optimes."); // Reset to uninitialized OpTime bool isRollbackAllowed = true; _setMyLastAppliedOpTimeAndWallTime( @@ -1411,8 +1455,14 @@ Status ReplicationCoordinatorImpl::_waitUntilOpTime(OperationContext* opCtx, // We just need to wait for the opTime to catch up to what we need (not majority RC). auto future = _opTimeWaiterList.add_inlock(targetOpTime); - LOG(3) << "waitUntilOpTime: OpID " << opCtx->getOpID() << " is waiting for OpTime " - << targetOpTime << " until " << deadline.value_or(opCtx->getDeadline()); + LOGV2_DEBUG(21333, + 3, + "waitUntilOpTime: OpID {opCtx_getOpID} is waiting for OpTime " + "{targetOpTime} until {deadline_value_or_opCtx_getDeadline}", + "opCtx_getOpID"_attr = opCtx->getOpID(), + "targetOpTime"_attr = targetOpTime, + "deadline_value_or_opCtx_getDeadline"_attr = + deadline.value_or(opCtx->getDeadline())); lock.unlock(); auto waitStatus = futureGetNoThrowWithDeadline( @@ -1455,12 +1505,19 @@ Status ReplicationCoordinatorImpl::_waitUntilMajorityOpTime(mongo::OperationCont stdx::unique_lock lock(_mutex); - LOG(1) << "waitUntilOpTime: waiting for optime:" << targetOpTime - << " to be in a snapshot -- current snapshot: " - << _getCurrentCommittedSnapshotOpTime_inlock(); + LOGV2_DEBUG(21334, + 1, + "waitUntilOpTime: waiting for optime:{targetOpTime} to be in a snapshot -- current " + "snapshot: {getCurrentCommittedSnapshotOpTime_inlock}", + "targetOpTime"_attr = targetOpTime, + "getCurrentCommittedSnapshotOpTime_inlock"_attr = + _getCurrentCommittedSnapshotOpTime_inlock()); - LOG(3) << "waitUntilOpTime: waiting for a new snapshot until " - << deadline.value_or(opCtx->getDeadline()); + LOGV2_DEBUG( + 21335, + 3, + "waitUntilOpTime: waiting for a new snapshot until {deadline_value_or_opCtx_getDeadline}", + "deadline_value_or_opCtx_getDeadline"_attr = deadline.value_or(opCtx->getDeadline())); try { auto ok = opCtx->waitForConditionOrInterruptUntil( @@ -1484,7 +1541,10 @@ Status ReplicationCoordinatorImpl::_waitUntilMajorityOpTime(mongo::OperationCont // _currentCommittedSnapshot, _getCurrentCommittedSnapshotOpTime_inlock() also returns // default OpTime{}. Hence this branch only runs if _currentCommittedSnapshot actually // exists. - LOG(3) << "Got notified of new snapshot: " << _currentCommittedSnapshot->toString(); + LOGV2_DEBUG(21336, + 3, + "Got notified of new snapshot: {currentCommittedSnapshot}", + "currentCommittedSnapshot"_attr = _currentCommittedSnapshot->toString()); } return Status::OK(); } @@ -1638,8 +1698,13 @@ bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock( // Wait for the "current" snapshot to advance to/past the opTime. const auto haveSnapshot = _currentCommittedSnapshot->opTime >= opTime; if (!haveSnapshot) { - LOG(1) << "Required snapshot optime: " << opTime << " is not yet part of the " - << "current 'committed' snapshot: " << _currentCommittedSnapshot->opTime; + LOGV2_DEBUG(21337, + 1, + "Required snapshot optime: {opTime} is not yet part of the current " + "'committed' snapshot: {currentCommittedSnapshot_opTime}", + "opTime"_attr = opTime, + "currentCommittedSnapshot_opTime"_attr = + _currentCommittedSnapshot->opTime); return false; } @@ -1650,14 +1715,16 @@ bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock( // removed from storage. if (auto dropOpTime = _externalState->getEarliestDropPendingOpTime()) { if (*dropOpTime <= opTime) { - LOG(1) << "Unable to satisfy the requested majority write concern at " - "'committed' optime " - << opTime - << ". There are still drop pending collections (earliest drop optime: " - << *dropOpTime - << ") that have to be removed from storage before we can " - "satisfy the write concern " - << writeConcern.toBSON(); + LOGV2_DEBUG(21338, + 1, + "Unable to satisfy the requested majority write concern at " + "'committed' optime {opTime}. There are still drop pending collections " + "(earliest drop optime: {dropOpTime}) that have to be removed from " + "storage before we can " + "satisfy the write concern {writeConcern}", + "opTime"_attr = opTime, + "dropOpTime"_attr = *dropOpTime, + "writeConcern"_attr = writeConcern.toBSON()); return false; } } @@ -1717,9 +1784,13 @@ ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorImpl::awaitRepli if (getTestCommandsEnabled() && !status.isOK()) { stdx::lock_guard lock(_mutex); - log() << "Replication failed for write concern: " << writeConcern.toBSON() - << ", waiting for optime: " << opTime << ", opID: " << opCtx->getOpID() - << ", progress: " << _getReplicationProgress(lock); + LOGV2(21339, + "Replication failed for write concern: {writeConcern}, waiting for optime: {opTime}, " + "opID: {opCtx_getOpID}, progress: {getReplicationProgress_lock}", + "writeConcern"_attr = writeConcern.toBSON(), + "opTime"_attr = opTime, + "opCtx_getOpID"_attr = opCtx->getOpID(), + "getReplicationProgress_lock"_attr = _getReplicationProgress(lock)); } return {std::move(status), duration_cast<Milliseconds>(timer.elapsed())}; } @@ -1862,7 +1933,7 @@ void ReplicationCoordinatorImpl::updateAndLogStateTransitionMetrics( bob.appendNumber("userOpsKilled", userOpsKilled.get()); bob.appendNumber("userOpsRunning", userOpsRunning.get()); - log() << "State transition ops metrics: " << bob.obj(); + LOGV2(21340, "State transition ops metrics: {bob_obj}", "bob_obj"_attr = bob.obj()); } std::shared_ptr<IsMasterResponse> ReplicationCoordinatorImpl::_makeIsMasterResponse( @@ -1954,12 +2025,16 @@ std::shared_ptr<const IsMasterResponse> ReplicationCoordinatorImpl::awaitIsMaste if (MONGO_unlikely(waitForIsMasterResponse.shouldFail())) { // Used in tests that wait for this failpoint to be entered before triggering a topology // change. - log() << "waitForIsMasterResponse failpoint enabled."; + LOGV2(21341, "waitForIsMasterResponse failpoint enabled."); } // Wait for a topology change with timeout set to deadline. - LOG(1) << "Waiting for an isMaster response from a topology change or until deadline: " - << deadline.get() << ". Current TopologyVersion counter is " << topologyVersionCounter; + LOGV2_DEBUG(21342, + 1, + "Waiting for an isMaster response from a topology change or until deadline: " + "{deadline_get}. Current TopologyVersion counter is {topologyVersionCounter}", + "deadline_get"_attr = deadline.get(), + "topologyVersionCounter"_attr = topologyVersionCounter); auto statusWithIsMaster = futureGetNoThrowWithDeadline(opCtx, future, deadline.get(), opCtx->getTimeoutError()); auto status = statusWithIsMaster.getStatus(); @@ -2050,7 +2125,7 @@ void ReplicationCoordinatorImpl::AutoGetRstlForStepUpStepDown::_killOpThreadFn() invariant(!cc().isFromUserConnection()); - log() << "Starting to kill user operations"; + LOGV2(21343, "Starting to kill user operations"); auto uniqueOpCtx = cc().makeOperationContext(); OperationContext* opCtx = uniqueOpCtx.get(); @@ -2078,7 +2153,7 @@ void ReplicationCoordinatorImpl::AutoGetRstlForStepUpStepDown::_killOpThreadFn() stdx::unique_lock<Latch> lock(_mutex); if (_stopKillingOps.wait_for( lock, Milliseconds(10).toSystemDuration(), [this] { return _killSignaled; })) { - log() << "Stopped killing user operations"; + LOGV2(21344, "Stopped killing user operations"); _replCord->updateAndLogStateTransitionMetrics( _stateTransition, getUserOpsKilled(), getUserOpsRunning()); _killSignaled = false; @@ -2189,9 +2264,10 @@ void ReplicationCoordinatorImpl::stepDown(OperationContext* opCtx, lk.unlock(); if (MONGO_unlikely(stepdownHangBeforePerformingPostMemberStateUpdateActions.shouldFail())) { - log() << "stepping down from primary - " - "stepdownHangBeforePerformingPostMemberStateUpdateActions fail point enabled. " - "Blocking until fail point is disabled."; + LOGV2(21345, + "stepping down from primary - " + "stepdownHangBeforePerformingPostMemberStateUpdateActions fail point enabled. " + "Blocking until fail point is disabled."); while (MONGO_unlikely( stepdownHangBeforePerformingPostMemberStateUpdateActions.shouldFail())) { mongo::sleepsecs(1); @@ -2313,31 +2389,41 @@ void ReplicationCoordinatorImpl::_performElectionHandoff() { auto candidateIndex = _topCoord->chooseElectionHandoffCandidate(); if (candidateIndex < 0) { - log() << "Could not find node to hand off election to."; + LOGV2(21346, "Could not find node to hand off election to."); return; } auto target = _rsConfig.getMemberAt(candidateIndex).getHostAndPort(); executor::RemoteCommandRequest request( target, "admin", BSON("replSetStepUp" << 1 << "skipDryRun" << true), nullptr); - log() << "Handing off election to " << target; + LOGV2(21347, "Handing off election to {target}", "target"_attr = target); auto callbackHandleSW = _replExecutor->scheduleRemoteCommand( request, [target](const executor::TaskExecutor::RemoteCommandCallbackArgs& callbackData) { auto status = callbackData.response.status; if (status.isOK()) { - LOG(1) << "replSetStepUp request to " << target << " succeeded with response -- " - << callbackData.response.data; + LOGV2_DEBUG(21348, + 1, + "replSetStepUp request to {target} succeeded with response -- " + "{callbackData_response_data}", + "target"_attr = target, + "callbackData_response_data"_attr = callbackData.response.data); } else { - log() << "replSetStepUp request to " << target << " failed due to " << status; + LOGV2(21349, + "replSetStepUp request to {target} failed due to {status}", + "target"_attr = target, + "status"_attr = status); } }); auto callbackHandleStatus = callbackHandleSW.getStatus(); if (!callbackHandleStatus.isOK()) { - error() << "Failed to schedule ReplSetStepUp request to " << target - << " for election handoff: " << callbackHandleStatus; + LOGV2_ERROR(21417, + "Failed to schedule ReplSetStepUp request to {target} for election handoff: " + "{callbackHandleStatus}", + "target"_attr = target, + "callbackHandleStatus"_attr = callbackHandleStatus); } } @@ -2643,18 +2729,24 @@ Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) { int curMaintenanceCalls = _topCoord->getMaintenanceCount(); if (activate) { - log() << "going into maintenance mode with " << curMaintenanceCalls - << " other maintenance mode tasks in progress" << rsLog; + LOGV2_OPTIONS(21350, + {logv2::LogTag::kRS}, + "going into maintenance mode with {curMaintenanceCalls} other maintenance " + "mode tasks in progress", + "curMaintenanceCalls"_attr = curMaintenanceCalls); _topCoord->adjustMaintenanceCountBy(1); } else if (curMaintenanceCalls > 0) { invariant(_topCoord->getRole() == TopologyCoordinator::Role::kFollower); _topCoord->adjustMaintenanceCountBy(-1); - log() << "leaving maintenance mode (" << curMaintenanceCalls - 1 - << " other maintenance mode tasks ongoing)" << rsLog; + LOGV2_OPTIONS(21351, + {logv2::LogTag::kRS}, + "leaving maintenance mode ({curMaintenanceCalls_1} other maintenance mode " + "tasks ongoing)", + "curMaintenanceCalls_1"_attr = curMaintenanceCalls - 1); } else { - warning() << "Attempted to leave maintenance mode but it is not currently active"; + LOGV2_WARNING(21411, "Attempted to leave maintenance mode but it is not currently active"); return Status(ErrorCodes::OperationFailed, "already out of maintenance mode"); } @@ -2707,8 +2799,9 @@ Status ReplicationCoordinatorImpl::processReplSetFreeze(int secs, BSONObjBuilder Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCtx, const ReplSetReconfigArgs& args, BSONObjBuilder* resultObj) { - log() << "replSetReconfig admin command received from client; new config: " - << args.newConfigObj; + LOGV2(21352, + "replSetReconfig admin command received from client; new config: {args_newConfigObj}", + "args_newConfigObj"_attr = args.newConfigObj); stdx::unique_lock<Latch> lk(_mutex); @@ -2732,7 +2825,9 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt "Cannot run replSetReconfig because the node is currently updating " "its configuration"); default: - severe() << "Unexpected _rsConfigState " << int(_rsConfigState); + LOGV2_FATAL(21432, + "Unexpected _rsConfigState {int_rsConfigState}", + "int_rsConfigState"_attr = int(_rsConfigState)); fassertFailed(18914); } @@ -2767,41 +2862,49 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt // field passed in through its args. Instead, use this node's term. Status status = newConfig.initialize(newConfigObj, topCoordTerm, oldConfig.getReplicaSetId()); if (!status.isOK()) { - error() << "replSetReconfig got " << status << " while parsing " << newConfigObj; + LOGV2_ERROR(21418, + "replSetReconfig got {status} while parsing {newConfigObj}", + "status"_attr = status, + "newConfigObj"_attr = newConfigObj); return Status(ErrorCodes::InvalidReplicaSetConfig, status.reason()); } if (newConfig.getReplSetName() != _settings.ourSetName()) { str::stream errmsg; errmsg << "Attempting to reconfigure a replica set with name " << newConfig.getReplSetName() << ", but command line reports " << _settings.ourSetName() << "; rejecting"; - error() << std::string(errmsg); + LOGV2_ERROR(21419, "{std_string_errmsg}", "std_string_errmsg"_attr = std::string(errmsg)); return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg); } StatusWith<int> myIndex = validateConfigForReconfig( _externalState.get(), oldConfig, newConfig, opCtx->getServiceContext(), args.force); if (!myIndex.isOK()) { - error() << "replSetReconfig got " << myIndex.getStatus() << " while validating " - << newConfigObj; + LOGV2_ERROR(21420, + "replSetReconfig got {myIndex_getStatus} while validating {newConfigObj}", + "myIndex_getStatus"_attr = myIndex.getStatus(), + "newConfigObj"_attr = newConfigObj); return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, myIndex.getStatus().reason()); } - log() << "replSetReconfig config object with " << newConfig.getNumMembers() - << " members parses ok"; + LOGV2(21353, + "replSetReconfig config object with {newConfig_getNumMembers} members parses ok", + "newConfig_getNumMembers"_attr = newConfig.getNumMembers()); if (!args.force) { status = checkQuorumForReconfig( _replExecutor.get(), newConfig, myIndex.getValue(), _topCoord->getTerm()); if (!status.isOK()) { - error() << "replSetReconfig failed; " << status; + LOGV2_ERROR(21421, "replSetReconfig failed; {status}", "status"_attr = status); return status; } } status = _externalState->storeLocalConfigDocument(opCtx, newConfig.toBSON()); if (!status.isOK()) { - error() << "replSetReconfig failed to store config document; " << status; + LOGV2_ERROR(21422, + "replSetReconfig failed to store config document; {status}", + "status"_attr = status); return status; } @@ -2825,8 +2928,11 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx, // we have already set our ReplicationCoordinatorImpl::_rsConfigState state to // "kConfigReconfiguring" which prevents new elections from happening. if (electionFinishedEvent) { - LOG(2) << "Waiting for election to complete before finishing reconfig to config with " - << newConfig.getConfigVersionAndTerm(); + LOGV2_DEBUG(21354, + 2, + "Waiting for election to complete before finishing reconfig to config with " + "{newConfig_getConfigVersionAndTerm}", + "newConfig_getConfigVersionAndTerm"_attr = newConfig.getConfigVersionAndTerm()); // Wait for the election to complete and the node's Role to be set to follower. _replExecutor->waitForEvent(electionFinishedEvent); } @@ -2844,7 +2950,7 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx, lk.lock(); if (_topCoord->isSteppingDownUnconditionally()) { invariant(opCtx->lockState()->isRSTLExclusive()); - log() << "stepping down from primary, because we received a new config"; + LOGV2(21355, "stepping down from primary, because we received a new config"); // We need to release the mutex before yielding locks for prepared transactions, which // might check out sessions, to avoid deadlocks with checked-out sessions accessing // this mutex. @@ -2892,7 +2998,7 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx, Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCtx, const BSONObj& configObj, BSONObjBuilder* resultObj) { - log() << "replSetInitiate admin command received from client"; + LOGV2(21356, "replSetInitiate admin command received from client"); const auto replEnabled = _settings.usingReplSets(); stdx::unique_lock<Latch> lk(_mutex); @@ -2925,27 +3031,33 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt ReplSetConfig newConfig; Status status = newConfig.initializeForInitiate(configObj); if (!status.isOK()) { - error() << "replSet initiate got " << status << " while parsing " << configObj; + LOGV2_ERROR(21423, + "replSet initiate got {status} while parsing {configObj}", + "status"_attr = status, + "configObj"_attr = configObj); return Status(ErrorCodes::InvalidReplicaSetConfig, status.reason()); } if (newConfig.getReplSetName() != _settings.ourSetName()) { str::stream errmsg; errmsg << "Attempting to initiate a replica set with name " << newConfig.getReplSetName() << ", but command line reports " << _settings.ourSetName() << "; rejecting"; - error() << std::string(errmsg); + LOGV2_ERROR(21424, "{std_string_errmsg}", "std_string_errmsg"_attr = std::string(errmsg)); return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg); } StatusWith<int> myIndex = validateConfigForInitiate(_externalState.get(), newConfig, opCtx->getServiceContext()); if (!myIndex.isOK()) { - error() << "replSet initiate got " << myIndex.getStatus() << " while validating " - << configObj; + LOGV2_ERROR(21425, + "replSet initiate got {myIndex_getStatus} while validating {configObj}", + "myIndex_getStatus"_attr = myIndex.getStatus(), + "configObj"_attr = configObj); return Status(ErrorCodes::InvalidReplicaSetConfig, myIndex.getStatus().reason()); } - log() << "replSetInitiate config object with " << newConfig.getNumMembers() - << " members parses ok"; + LOGV2(21357, + "replSetInitiate config object with {newConfig_getNumMembers} members parses ok", + "newConfig_getNumMembers"_attr = newConfig.getNumMembers()); // In pv1, the TopologyCoordinator has not set the term yet. It will be set to kInitialTerm if // the initiate succeeds so we pass that here. @@ -2953,14 +3065,15 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt _replExecutor.get(), newConfig, myIndex.getValue(), OpTime::kInitialTerm); if (!status.isOK()) { - error() << "replSetInitiate failed; " << status; + LOGV2_ERROR(21426, "replSetInitiate failed; {status}", "status"_attr = status); return status; } status = _externalState->initializeReplSetStorage(opCtx, newConfig.toBSON()); if (!status.isOK()) { - error() << "replSetInitiate failed to store config document or create the oplog; " - << status; + LOGV2_ERROR(21427, + "replSetInitiate failed to store config document or create the oplog; {status}", + "status"_attr = status); return status; } @@ -3177,7 +3290,11 @@ ReplicationCoordinatorImpl::_updateMemberStateFromTopologyCoordinator(WithLock l _cancelPriorityTakeover_inlock(); } - log() << "transition to " << newState << " from " << _memberState << rsLog; + LOGV2_OPTIONS(21358, + {logv2::LogTag::kRS}, + "transition to {newState} from {memberState}", + "newState"_attr = newState, + "memberState"_attr = _memberState); // Initializes the featureCompatibilityVersion to the latest value, because arbiters do not // receive the replicated version. This is to avoid bugs like SERVER-32639. if (newState.arbiter()) { @@ -3219,7 +3336,9 @@ void ReplicationCoordinatorImpl::_performPostMemberStateUpdateAction( _startElectSelfV1(StartElectionReasonEnum::kElectionTimeout); break; default: - severe() << "Unknown post member state update action " << static_cast<int>(action); + LOGV2_FATAL(21433, + "Unknown post member state update action {static_cast_int_action}", + "static_cast_int_action"_attr = static_cast<int>(action)); fassertFailed(26010); } } @@ -3249,7 +3368,7 @@ void ReplicationCoordinatorImpl::_onFollowerModeStateChange() { } void ReplicationCoordinatorImpl::CatchupState::start_inlock() { - log() << "Entering primary catch-up mode."; + LOGV2(21359, "Entering primary catch-up mode."); // Reset the number of catchup operations performed before starting catchup. _numCatchUpOps = 0; @@ -3264,7 +3383,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() { // When catchUpTimeoutMillis is 0, we skip doing catchup entirely. if (catchupTimeout == ReplSetConfig::kCatchUpDisabled) { - log() << "Skipping primary catchup since the catchup timeout is 0."; + LOGV2(21360, "Skipping primary catchup since the catchup timeout is 0."); abort_inlock(PrimaryCatchUpConclusionReason::kSkipped); return; } @@ -3279,7 +3398,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() { if (cbData.myHandle.isCanceled()) { return; } - log() << "Catchup timed out after becoming primary."; + LOGV2(21361, "Catchup timed out after becoming primary."); abort_inlock(PrimaryCatchUpConclusionReason::kTimedOut); }; @@ -3292,7 +3411,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() { auto timeoutDate = _repl->_replExecutor->now() + catchupTimeout; auto status = _repl->_replExecutor->scheduleWorkAt(timeoutDate, std::move(timeoutCB)); if (!status.isOK()) { - log() << "Failed to schedule catchup timeout work."; + LOGV2(21362, "Failed to schedule catchup timeout work."); abort_inlock(PrimaryCatchUpConclusionReason::kFailedWithError); return; } @@ -3305,7 +3424,7 @@ void ReplicationCoordinatorImpl::CatchupState::abort_inlock(PrimaryCatchUpConclu ReplicationMetrics::get(getGlobalServiceContext()) .incrementNumCatchUpsConcludedForReason(reason); - log() << "Exited primary catch-up mode."; + LOGV2(21363, "Exited primary catch-up mode."); // Clean up its own members. if (_timeoutCbh) { _repl->_replExecutor->cancel(_timeoutCbh); @@ -3331,8 +3450,11 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() { // We've caught up. const auto myLastApplied = _repl->_getMyLastAppliedOpTime_inlock(); if (*targetOpTime <= myLastApplied) { - log() << "Caught up to the latest optime known via heartbeats after becoming primary. " - << "Target optime: " << *targetOpTime << ". My Last Applied: " << myLastApplied; + LOGV2(21364, + "Caught up to the latest optime known via heartbeats after becoming primary. Target " + "optime: {targetOpTime}. My Last Applied: {myLastApplied}", + "targetOpTime"_attr = *targetOpTime, + "myLastApplied"_attr = myLastApplied); // Report the number of ops applied during catchup in replSetGetStatus once the primary is // caught up. ReplicationMetrics::get(getGlobalServiceContext()).setNumCatchUpOps(_numCatchUpOps); @@ -3348,12 +3470,17 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() { ReplicationMetrics::get(getGlobalServiceContext()).setTargetCatchupOpTime(_targetOpTime); - log() << "Heartbeats updated catchup target optime to " << _targetOpTime; - log() << "Latest known optime per replica set member:"; + LOGV2(21365, + "Heartbeats updated catchup target optime to {targetOpTime}", + "targetOpTime"_attr = _targetOpTime); + LOGV2(21366, "Latest known optime per replica set member:"); auto opTimesPerMember = _repl->_topCoord->latestKnownOpTimeSinceHeartbeatRestartPerMember(); for (auto&& pair : opTimesPerMember) { - log() << "Member ID: " << pair.first - << ", latest known optime: " << (pair.second ? (*pair.second).toString() : "unknown"); + LOGV2(21367, + "Member ID: {pair_first}, latest known optime: {pair_second_pair_second_unknown}", + "pair_first"_attr = pair.first, + "pair_second_pair_second_unknown"_attr = + (pair.second ? (*pair.second).toString() : "unknown")); } if (_waiter) { @@ -3370,8 +3497,11 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() { // Double check the target time since stepdown may signal us too. const auto myLastApplied = _repl->_getMyLastAppliedOpTime_inlock(); if (_targetOpTime <= myLastApplied) { - log() << "Caught up to the latest known optime successfully after becoming primary. " - << "Target optime: " << _targetOpTime << ". My Last Applied: " << myLastApplied; + LOGV2(21368, + "Caught up to the latest known optime successfully after becoming primary. " + "Target optime: {targetOpTime}. My Last Applied: {myLastApplied}", + "targetOpTime"_attr = _targetOpTime, + "myLastApplied"_attr = myLastApplied); // Report the number of ops applied during catchup in replSetGetStatus once the primary // is caught up. ReplicationMetrics::get(getGlobalServiceContext()).setNumCatchUpOps(_numCatchUpOps); @@ -3442,21 +3572,32 @@ ReplicationCoordinatorImpl::_setCurrentRSConfig(WithLock lk, if (storageEngine && !storageEngine->isDurable() && (newConfig.getWriteConcernMajorityShouldJournal() && (!oldConfig.isInitialized() || !oldConfig.getWriteConcernMajorityShouldJournal()))) { - log() << startupWarningsLog; - log() << "** WARNING: This replica set node is running without journaling enabled but the " - << startupWarningsLog; - log() << "** writeConcernMajorityJournalDefault option to the replica set config " - << startupWarningsLog; - log() << "** is set to true. The writeConcernMajorityJournalDefault " - << startupWarningsLog; - log() << "** option to the replica set config must be set to false " - << startupWarningsLog; - log() << "** or w:majority write concerns will never complete." - << startupWarningsLog; - log() << "** In addition, this node's memory consumption may increase until all" - << startupWarningsLog; - log() << "** available free RAM is exhausted." << startupWarningsLog; - log() << startupWarningsLog; + LOGV2_OPTIONS(21369, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 21370, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This replica set node is running without journaling enabled but the "); + LOGV2_OPTIONS( + 21371, + {logv2::LogTag::kStartupWarnings}, + "** writeConcernMajorityJournalDefault option to the replica set config "); + LOGV2_OPTIONS(21372, + {logv2::LogTag::kStartupWarnings}, + "** is set to true. The writeConcernMajorityJournalDefault "); + LOGV2_OPTIONS(21373, + {logv2::LogTag::kStartupWarnings}, + "** option to the replica set config must be set to false "); + LOGV2_OPTIONS(21374, + {logv2::LogTag::kStartupWarnings}, + "** or w:majority write concerns will never complete."); + LOGV2_OPTIONS( + 21375, + {logv2::LogTag::kStartupWarnings}, + "** In addition, this node's memory consumption may increase until all"); + LOGV2_OPTIONS(21376, + {logv2::LogTag::kStartupWarnings}, + "** available free RAM is exhausted."); + LOGV2_OPTIONS(21377, {logv2::LogTag::kStartupWarnings}, ""); } // Warn if using the in-memory (ephemeral) storage engine with @@ -3464,44 +3605,66 @@ ReplicationCoordinatorImpl::_setCurrentRSConfig(WithLock lk, if (storageEngine && storageEngine->isEphemeral() && (newConfig.getWriteConcernMajorityShouldJournal() && (!oldConfig.isInitialized() || !oldConfig.getWriteConcernMajorityShouldJournal()))) { - log() << startupWarningsLog; - log() << "** WARNING: This replica set node is using in-memory (ephemeral) storage with the" - << startupWarningsLog; - log() << "** writeConcernMajorityJournalDefault option to the replica set config " - << startupWarningsLog; - log() << "** set to true. The writeConcernMajorityJournalDefault option to the " - << startupWarningsLog; - log() << "** replica set config must be set to false " << startupWarningsLog; - log() << "** or w:majority write concerns will never complete." - << startupWarningsLog; - log() << "** In addition, this node's memory consumption may increase until all" - << startupWarningsLog; - log() << "** available free RAM is exhausted." << startupWarningsLog; - log() << startupWarningsLog; + LOGV2_OPTIONS(21378, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 21379, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This replica set node is using in-memory (ephemeral) storage with the"); + LOGV2_OPTIONS( + 21380, + {logv2::LogTag::kStartupWarnings}, + "** writeConcernMajorityJournalDefault option to the replica set config "); + LOGV2_OPTIONS( + 21381, + {logv2::LogTag::kStartupWarnings}, + "** set to true. The writeConcernMajorityJournalDefault option to the "); + LOGV2_OPTIONS(21382, + {logv2::LogTag::kStartupWarnings}, + "** replica set config must be set to false "); + LOGV2_OPTIONS(21383, + {logv2::LogTag::kStartupWarnings}, + "** or w:majority write concerns will never complete."); + LOGV2_OPTIONS( + 21384, + {logv2::LogTag::kStartupWarnings}, + "** In addition, this node's memory consumption may increase until all"); + LOGV2_OPTIONS(21385, + {logv2::LogTag::kStartupWarnings}, + "** available free RAM is exhausted."); + LOGV2_OPTIONS(21386, {logv2::LogTag::kStartupWarnings}, ""); } // Since the ReplSetConfig always has a WriteConcernOptions, the only way to know if it has been // customized is if it's different to the implicit defaults of { w: 1, wtimeout: 0 }. if (const auto& wc = newConfig.getDefaultWriteConcern(); !(wc.wNumNodes == 1 && wc.wTimeout == 0)) { - log() << startupWarningsLog; - log() << "** WARNING: Replica set config contains customized getLastErrorDefaults," - << startupWarningsLog; - log() << "** which are deprecated. Use setDefaultRWConcern instead to set a" - << startupWarningsLog; - log() << "** cluster-wide default writeConcern." << startupWarningsLog; - log() << startupWarningsLog; + LOGV2_OPTIONS(21387, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(21388, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Replica set config contains customized getLastErrorDefaults,"); + LOGV2_OPTIONS(21389, + {logv2::LogTag::kStartupWarnings}, + "** which are deprecated. Use setDefaultRWConcern instead to set a"); + LOGV2_OPTIONS(21390, + {logv2::LogTag::kStartupWarnings}, + "** cluster-wide default writeConcern."); + LOGV2_OPTIONS(21391, {logv2::LogTag::kStartupWarnings}, ""); } const bool horizonsChanged = _haveHorizonsChanged(oldConfig, newConfig, _selfIndex, myIndex); - log() << "New replica set config in use: " << _rsConfig.toBSON() << rsLog; + LOGV2_OPTIONS(21392, + {logv2::LogTag::kRS}, + "New replica set config in use: {rsConfig}", + "rsConfig"_attr = _rsConfig.toBSON()); _selfIndex = myIndex; if (_selfIndex >= 0) { - log() << "This node is " << _rsConfig.getMemberAt(_selfIndex).getHostAndPort() - << " in the config"; + LOGV2(21393, + "This node is {rsConfig_getMemberAt_selfIndex_getHostAndPort} in the config", + "rsConfig_getMemberAt_selfIndex_getHostAndPort"_attr = + _rsConfig.getMemberAt(_selfIndex).getHostAndPort()); } else { - log() << "This node is not a member of the config"; + LOGV2(21394, "This node is not a member of the config"); } if (horizonsChanged) { @@ -3736,9 +3899,11 @@ void ReplicationCoordinatorImpl::resetLastOpTimesFromOplog(OperationContext* opC auto lastOpTimeAndWallTimeStatus = _externalState->loadLastOpTimeAndWallTime(opCtx); OpTimeAndWallTime lastOpTimeAndWallTime = {OpTime(), Date_t()}; if (!lastOpTimeAndWallTimeStatus.getStatus().isOK()) { - warning() << "Failed to load timestamp and/or wall clock time of most recently applied " - "operation; " - << lastOpTimeAndWallTimeStatus.getStatus(); + LOGV2_WARNING(21412, + "Failed to load timestamp and/or wall clock time of most recently applied " + "operation; {lastOpTimeAndWallTimeStatus_getStatus}", + "lastOpTimeAndWallTimeStatus_getStatus"_attr = + lastOpTimeAndWallTimeStatus.getStatus()); } else { lastOpTimeAndWallTime = lastOpTimeAndWallTimeStatus.getValue(); } @@ -3899,7 +4064,7 @@ MONGO_FAIL_POINT_DEFINE(disableSnapshotting); void ReplicationCoordinatorImpl::_setStableTimestampForStorage(WithLock lk) { if (!_shouldSetStableTimestamp) { - LOG(2) << "Not setting stable timestamp for storage."; + LOGV2_DEBUG(21395, 2, "Not setting stable timestamp for storage."); return; } // Get the current stable optime. @@ -3908,7 +4073,10 @@ void ReplicationCoordinatorImpl::_setStableTimestampForStorage(WithLock lk) { // If there is a valid stable optime, set it for the storage engine, and then remove any // old, unneeded stable optime candidates. if (stableOpTime) { - LOG(2) << "Setting replication's stable optime to " << stableOpTime.value(); + LOGV2_DEBUG(21396, + 2, + "Setting replication's stable optime to {stableOpTime_value}", + "stableOpTime_value"_attr = stableOpTime.value()); if (!gTestingSnapshotBehaviorInIsolation) { // Update committed snapshot and wake up any threads waiting on read concern or @@ -3962,15 +4130,17 @@ void ReplicationCoordinatorImpl::finishRecoveryIfEligible(OperationContext* opCt // We can only transition to SECONDARY from RECOVERING state. MemberState state(getMemberState()); if (!state.recovering()) { - LOG(2) << "We cannot transition to SECONDARY state since we are not currently in " - "RECOVERING state. Current state: " - << state.toString(); + LOGV2_DEBUG(21397, + 2, + "We cannot transition to SECONDARY state since we are not currently in " + "RECOVERING state. Current state: {state}", + "state"_attr = state.toString()); return; } // Maintenance mode will force us to remain in RECOVERING state, no matter what. if (getMaintenanceMode()) { - LOG(1) << "We cannot transition to SECONDARY state while in maintenance mode."; + LOGV2_DEBUG(21398, 1, "We cannot transition to SECONDARY state while in maintenance mode."); return; } @@ -3980,17 +4150,26 @@ void ReplicationCoordinatorImpl::finishRecoveryIfEligible(OperationContext* opCt auto lastApplied = getMyLastAppliedOpTime(); auto minValid = _replicationProcess->getConsistencyMarkers()->getMinValid(opCtx); if (lastApplied < minValid) { - LOG(2) << "We cannot transition to SECONDARY state because our 'lastApplied' optime" - " is less than the 'minValid' optime. minValid optime: " - << minValid << ", lastApplied optime: " << lastApplied; + LOGV2_DEBUG(21399, + 2, + "We cannot transition to SECONDARY state because our 'lastApplied' optime" + " is less than the 'minValid' optime. minValid optime: {minValid}, lastApplied " + "optime: {lastApplied}", + "minValid"_attr = minValid, + "lastApplied"_attr = lastApplied); return; } // Execute the transition to SECONDARY. auto status = setFollowerMode(MemberState::RS_SECONDARY); if (!status.isOK()) { - warning() << "Failed to transition into " << MemberState(MemberState::RS_SECONDARY) - << ". Current state: " << getMemberState() << causedBy(status); + LOGV2_WARNING(21413, + "Failed to transition into {MemberState_MemberState_RS_SECONDARY}. Current " + "state: {getMemberState}{causedBy_status}", + "MemberState_MemberState_RS_SECONDARY"_attr = + MemberState(MemberState::RS_SECONDARY), + "getMemberState"_attr = getMemberState(), + "causedBy_status"_attr = causedBy(status)); } } @@ -4057,7 +4236,9 @@ Status ReplicationCoordinatorImpl::processReplSetRequestVotes( if (votedForCandidate) { Status status = _externalState->storeLocalLastVoteDocument(opCtx, lastVote); if (!status.isOK()) { - error() << "replSetRequestVotes failed to store LastVote document; " << status; + LOGV2_ERROR(21428, + "replSetRequestVotes failed to store LastVote document; {status}", + "status"_attr = status); return status; } } @@ -4160,8 +4341,10 @@ Status ReplicationCoordinatorImpl::processHeartbeatV1(const ReplSetHeartbeatArgs // a configuration that contains us. Chances are excellent that it will, since that // is the only reason for a remote node to send this node a heartbeat request. if (!senderHost.empty() && _seedList.insert(senderHost).second) { - log() << "Scheduling heartbeat to fetch a new config from: " << senderHost - << " since we are not a member of our current config."; + LOGV2(21400, + "Scheduling heartbeat to fetch a new config from: {senderHost} since we are not " + "a member of our current config.", + "senderHost"_attr = senderHost); _scheduleHeartbeatToTarget_inlock(senderHost, -1, now); } } else if (result.isOK() && @@ -4171,9 +4354,12 @@ Status ReplicationCoordinatorImpl::processHeartbeatV1(const ReplSetHeartbeatArgs // We cannot cancel the enqueued heartbeat, but either this one or the enqueued heartbeat // will trigger reconfig, which cancels and reschedules all heartbeats. if (args.hasSender()) { - log() << "Scheduling heartbeat to fetch a newer config with term " - << args.getConfigTerm() << " and version " << args.getConfigVersion() - << " from member: " << senderHost; + LOGV2(21401, + "Scheduling heartbeat to fetch a newer config with term {args_getConfigTerm} and " + "version {args_getConfigVersion} from member: {senderHost}", + "args_getConfigTerm"_attr = args.getConfigTerm(), + "args_getConfigVersion"_attr = args.getConfigVersion(), + "senderHost"_attr = senderHost); int senderIndex = _rsConfig.findMemberIndexByHostAndPort(senderHost); _scheduleHeartbeatToTarget_inlock(senderHost, senderIndex, now); } @@ -4251,12 +4437,16 @@ EventHandle ReplicationCoordinatorImpl::_updateTerm_inlock( _pendingTermUpdateDuringStepDown = term; } if (_topCoord->prepareForUnconditionalStepDown()) { - log() << "stepping down from primary, because a new term has begun: " << term; + LOGV2(21402, + "stepping down from primary, because a new term has begun: {term}", + "term"_attr = term); ReplicationMetrics::get(getServiceContext()).incrementNumStepDownsCausedByHigherTerm(); return _stepDownStart(); } else { - LOG(2) << "Updated term but not triggering stepdown because we are already in the " - "process of stepping down"; + LOGV2_DEBUG(21403, + 2, + "Updated term but not triggering stepdown because we are already in the " + "process of stepping down"); } } return EventHandle(); @@ -4314,7 +4504,7 @@ bool ReplicationCoordinatorImpl::_updateCommittedSnapshot( // If we are in ROLLBACK state, do not set any new _currentCommittedSnapshot, as it will be // cleared at the end of rollback anyway. if (_memberState.rollback()) { - log() << "Not updating committed snapshot because we are in rollback"; + LOGV2(21404, "Not updating committed snapshot because we are in rollback"); return false; } invariant(!newCommittedSnapshot.opTime.isNull()); diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp index 6d44c96bc0e..61910c41c1e 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp @@ -37,6 +37,7 @@ #include "mongo/db/repl/replication_metrics.h" #include "mongo/db/repl/topology_coordinator.h" #include "mongo/db/repl/vote_requester.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -55,7 +56,9 @@ public: if (_dismissed) { return; } - log() << "Lost " << (_isDryRun ? "dry run " : "") << "election due to internal error"; + LOGV2(21434, + "Lost {isDryRun_dry_run}election due to internal error", + "isDryRun_dry_run"_attr = (_isDryRun ? "dry run " : "")); _replCoord->_topCoord->processLoseElection(); _replCoord->_voteRequester.reset(nullptr); if (_isDryRun && _replCoord->_electionDryRunFinishedEvent.isValid()) { @@ -105,13 +108,15 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu case kConfigInitiating: case kConfigReconfiguring: case kConfigHBReconfiguring: - LOG(2) << "Not standing for election; processing a configuration change"; + LOGV2_DEBUG(21435, 2, "Not standing for election; processing a configuration change"); // Transition out of candidate role. _topCoord->processLoseElection(); return; default: - severe() << "Entered replica set election code while in illegal config state " - << int(_rsConfigState); + LOGV2_FATAL(21452, + "Entered replica set election code while in illegal config state " + "{int_rsConfigState}", + "int_rsConfigState"_attr = int(_rsConfigState)); fassertFailed(28641); } @@ -134,8 +139,9 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu const auto lastOpTime = _getMyLastAppliedOpTime_inlock(); if (lastOpTime == OpTime()) { - log() << "not trying to elect self, " - "do not yet have a complete set of data from any point in time"; + LOGV2(21436, + "not trying to elect self, " + "do not yet have a complete set of data from any point in time"); return; } @@ -144,13 +150,17 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu if (reason == StartElectionReasonEnum::kStepUpRequestSkipDryRun) { long long newTerm = term + 1; - log() << "skipping dry run and running for election in term " << newTerm; + LOGV2(21437, + "skipping dry run and running for election in term {newTerm}", + "newTerm"_attr = newTerm); _startRealElection_inlock(newTerm, reason); lossGuard.dismiss(); return; } - log() << "conducting a dry run election to see if we could be elected. current term: " << term; + LOGV2(21438, + "conducting a dry run election to see if we could be elected. current term: {term}", + "term"_attr = term); _voteRequester.reset(new VoteRequester); // Only set primaryIndex if the primary's vote is required during the dry run. @@ -186,29 +196,34 @@ void ReplicationCoordinatorImpl::_processDryRunResult(long long originalTerm, invariant(_voteRequester); if (_topCoord->getTerm() != originalTerm) { - log() << "not running for primary, we have been superseded already during dry run. " - << "original term: " << originalTerm << ", current term: " << _topCoord->getTerm(); + LOGV2(21439, + "not running for primary, we have been superseded already during dry run. original " + "term: {originalTerm}, current term: {topCoord_getTerm}", + "originalTerm"_attr = originalTerm, + "topCoord_getTerm"_attr = _topCoord->getTerm()); return; } const VoteRequester::Result endResult = _voteRequester->getResult(); if (endResult == VoteRequester::Result::kInsufficientVotes) { - log() << "not running for primary, we received insufficient votes"; + LOGV2(21440, "not running for primary, we received insufficient votes"); return; } else if (endResult == VoteRequester::Result::kStaleTerm) { - log() << "not running for primary, we have been superseded already"; + LOGV2(21441, "not running for primary, we have been superseded already"); return; } else if (endResult == VoteRequester::Result::kPrimaryRespondedNo) { - log() << "not running for primary, the current primary responded no in the dry run"; + LOGV2(21442, "not running for primary, the current primary responded no in the dry run"); return; } else if (endResult != VoteRequester::Result::kSuccessfullyElected) { - log() << "not running for primary, we received an unexpected problem"; + LOGV2(21443, "not running for primary, we received an unexpected problem"); return; } long long newTerm = originalTerm + 1; - log() << "dry election run succeeded, running for election in term " << newTerm; + LOGV2(21444, + "dry election run succeeded, running for election in term {newTerm}", + "newTerm"_attr = newTerm); _startRealElection_inlock(newTerm, reason); lossGuard.dismiss(); @@ -291,14 +306,18 @@ void ReplicationCoordinatorImpl::_writeLastVoteForMyElection( } if (!status.isOK()) { - log() << "failed to store LastVote document when voting for myself: " << status; + LOGV2(21445, + "failed to store LastVote document when voting for myself: {status}", + "status"_attr = status); return; } if (_topCoord->getTerm() != lastVote.getTerm()) { - log() << "not running for primary, we have been superseded already while writing our last " - "vote. election term: " - << lastVote.getTerm() << ", current term: " << _topCoord->getTerm(); + LOGV2(21446, + "not running for primary, we have been superseded already while writing our last " + "vote. election term: {lastVote_getTerm}, current term: {topCoord_getTerm}", + "lastVote_getTerm"_attr = lastVote.getTerm(), + "topCoord_getTerm"_attr = _topCoord->getTerm()); return; } _startVoteRequester_inlock(lastVote.getTerm(), reason); @@ -336,8 +355,11 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm, invariant(_voteRequester); if (_topCoord->getTerm() != newTerm) { - log() << "not becoming primary, we have been superseded already during election. " - << "election term: " << newTerm << ", current term: " << _topCoord->getTerm(); + LOGV2(21447, + "not becoming primary, we have been superseded already during election. election " + "term: {newTerm}, current term: {topCoord_getTerm}", + "newTerm"_attr = newTerm, + "topCoord_getTerm"_attr = _topCoord->getTerm()); return; } @@ -346,13 +368,15 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm, switch (endResult) { case VoteRequester::Result::kInsufficientVotes: - log() << "not becoming primary, we received insufficient votes"; + LOGV2(21448, "not becoming primary, we received insufficient votes"); return; case VoteRequester::Result::kStaleTerm: - log() << "not becoming primary, we have been superseded already"; + LOGV2(21449, "not becoming primary, we have been superseded already"); return; case VoteRequester::Result::kSuccessfullyElected: - log() << "election succeeded, assuming primary role in term " << _topCoord->getTerm(); + LOGV2(21450, + "election succeeded, assuming primary role in term {topCoord_getTerm}", + "topCoord_getTerm"_attr = _topCoord->getTerm()); ReplicationMetrics::get(getServiceContext()) .incrementNumElectionsSuccessfulForReason(reason); break; @@ -372,9 +396,10 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm, electionHangsBeforeUpdateMemberState.execute([&](const BSONObj& customWait) { auto waitForMillis = Milliseconds(customWait["waitForMillis"].numberInt()); - log() << "election succeeded - electionHangsBeforeUpdateMemberState fail point " - "enabled, sleeping " - << waitForMillis; + LOGV2(21451, + "election succeeded - electionHangsBeforeUpdateMemberState fail point " + "enabled, sleeping {waitForMillis}", + "waitForMillis"_attr = waitForMillis); sleepFor(waitForMillis); }); diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp index bb44ed0bcd4..59db90faba0 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp @@ -44,6 +44,7 @@ #include "mongo/db/repl/replication_metrics.h" #include "mongo/db/repl/topology_coordinator.h" #include "mongo/executor/network_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -129,7 +130,9 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) { auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21453, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); NetworkInterfaceMock* net = getNet(); net->enterNetwork(); @@ -140,8 +143,10 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) { } auto noi = net->getNextReadyRequest(); const auto& request = noi->getRequest(); - error() << "Black holing irrelevant request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21473, + "Black holing irrelevant request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->exitNetwork(); @@ -354,7 +359,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun) auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21454, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); int voteRequests = 0; NetworkInterfaceMock* net = getNet(); @@ -366,7 +373,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun) ASSERT_TRUE(net->hasReadyRequests()); const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21455, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (consumeHeartbeatV1(noi)) { // The heartbeat has been consumed. } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { @@ -423,7 +433,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) { auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21456, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); int voteRequests = 0; NetworkInterfaceMock* net = getNet(); @@ -435,7 +447,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) { ASSERT_TRUE(net->hasReadyRequests()); const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21457, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (consumeHeartbeatV1(noi)) { // The heartbeat has been consumed. } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { @@ -529,7 +544,10 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { for (int i = 0; i < 2; ++i) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21458, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); ReplSetHeartbeatArgsV1 hbArgs; if (hbArgs.initialize(request.cmdObj).isOK()) { ReplSetHeartbeatResponse hbResp; @@ -543,8 +561,10 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { BSONObjBuilder respObj; net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON())); } else { - error() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21474, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); @@ -554,7 +574,9 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { // Advance the simulator clock sufficiently to trigger an election. auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21459, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); net->enterNetwork(); while (net->now() < electionTimeoutWhen) { @@ -607,7 +629,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringRequest while (net->hasReadyRequests()) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21460, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") { net->blackHole(noi); } else { @@ -700,7 +725,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenVoteRequestResponseContainsANewerTerm) { while (net->hasReadyRequests()) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21461, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") { net->blackHole(noi); } else { @@ -796,7 +824,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenTermChangesDuringActualElection) { while (net->hasReadyRequests()) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21462, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") { net->blackHole(noi); } else { @@ -941,7 +972,11 @@ private: noi = net->getNextReadyRequest(); auto&& request = noi->getRequest(); - log() << request.target << " processing " << request.cmdObj << " at " << net->now(); + LOGV2(21463, + "{request_target} processing {request_cmdObj} at {net_now}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj, + "net_now"_attr = net->now()); // Make sure the heartbeat request is valid. ReplSetHeartbeatArgsV1 hbArgs; @@ -1549,10 +1584,16 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) { NetworkInterfaceMock::NetworkOperationIterator noi_primary; Date_t until = net->now() + Seconds(1); while (voteRequests < votesExpected) { - unittest::log() << "request: " << voteRequests << " expected: " << votesExpected; + LOGV2(21464, + "request: {voteRequests} expected: {votesExpected}", + "voteRequests"_attr = voteRequests, + "votesExpected"_attr = votesExpected); const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21465, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") { net->blackHole(noi); } else { @@ -2125,13 +2166,17 @@ protected: auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21466, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); ASSERT(replCoord->getMemberState().secondary()) << replCoord->getMemberState().toString(); // Process requests until we're primary but leave the heartbeats for the notification // of election win. Exit immediately on unexpected requests. while (!replCoord->getMemberState().primary()) { - log() << "Waiting on network in state " << replCoord->getMemberState(); + LOGV2(21467, + "Waiting on network in state {replCoord_getMemberState}", + "replCoord_getMemberState"_attr = replCoord->getMemberState()); net->enterNetwork(); if (net->now() < electionTimeoutWhen) { net->runUntil(electionTimeoutWhen); @@ -2139,7 +2184,10 @@ protected: // Peek the next request, don't consume it yet. const NetworkOpIter noi = net->getFrontOfUnscheduledQueue(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21468, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) { OpTime opTime(Timestamp(), getReplCoord()->getTerm()); net->scheduleResponse( @@ -2204,13 +2252,18 @@ protected: while (net->hasReadyRequests()) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing heartbeat " << request.cmdObj - << " at " << net->now(); + LOGV2(21469, + "{request_target} processing heartbeat {request_cmdObj} at {net_now}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj, + "net_now"_attr = net->now()); if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) { onHeartbeatRequest(noi); } else { - log() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2(21470, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); @@ -2227,7 +2280,11 @@ protected: // Peek the next request auto noi = net->getFrontOfUnscheduledQueue(); auto& request = noi->getRequest(); - log() << request.target << " at " << net->now() << " processing " << request.cmdObj; + LOGV2(21471, + "{request_target} at {net_now} processing {request_cmdObj}", + "request_target"_attr = request.target, + "net_now"_attr = net->now(), + "request_cmdObj"_attr = request.cmdObj); if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) { // Consume the next request onHeartbeatRequest(net->getNextReadyRequest()); @@ -2434,7 +2491,9 @@ TEST_F(PrimaryCatchUpTest, HeartbeatTimeout) { replyHeartbeatsAndRunUntil(catchupTimeoutTime, [this, time1](const NetworkOpIter noi) { const RemoteCommandRequest& request = noi->getRequest(); if (request.target.host() == "node2") { - log() << "Black holing heartbeat from " << request.target.host(); + LOGV2(21472, + "Black holing heartbeat from {request_target_host}", + "request_target_host"_attr = request.target.host()); getNet()->blackHole(noi); } else { getNet()->scheduleResponse(noi, getNet()->now(), makeHeartbeatResponse(time1)); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index db9d264aa16..3b928f80df0 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -54,6 +54,7 @@ #include "mongo/db/repl/topology_coordinator.h" #include "mongo/db/repl/vote_requester.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/metadata/repl_set_metadata.h" @@ -274,11 +275,13 @@ stdx::unique_lock<Latch> ReplicationCoordinatorImpl::_handleHeartbeatResponseAct case HeartbeatResponseAction::StepDownSelf: invariant(action.getPrimaryConfigIndex() == _selfIndex); if (_topCoord->prepareForUnconditionalStepDown()) { - log() << "Stepping down from primary in response to heartbeat"; + LOGV2(21475, "Stepping down from primary in response to heartbeat"); _stepDownStart(); } else { - LOG(2) << "Heartbeat would have triggered a stepdown, but we're already in the " - "process of stepping down"; + LOGV2_DEBUG(21476, + 2, + "Heartbeat would have triggered a stepdown, but we're already in the " + "process of stepping down"); } break; case HeartbeatResponseAction::PriorityTakeover: { @@ -325,11 +328,18 @@ void remoteStepdownCallback(const executor::TaskExecutor::RemoteCommandCallbackA } if (status.isOK()) { - LOG(1) << "stepdown of primary(" << cbData.request.target << ") succeeded with response -- " - << cbData.response.data; + LOGV2_DEBUG(21477, + 1, + "stepdown of primary({cbData_request_target}) succeeded with response -- " + "{cbData_response_data}", + "cbData_request_target"_attr = cbData.request.target, + "cbData_response_data"_attr = cbData.response.data); } else { - warning() << "stepdown of primary(" << cbData.request.target << ") failed due to " - << cbData.response.status; + LOGV2_WARNING( + 21486, + "stepdown of primary({cbData_request_target}) failed due to {cbData_response_status}", + "cbData_request_target"_attr = cbData.request.target, + "cbData_response_status"_attr = cbData.response.status); } } } // namespace @@ -344,7 +354,7 @@ void ReplicationCoordinatorImpl::_requestRemotePrimaryStepdown(const HostAndPort 20LL)), nullptr); - log() << "Requesting " << target << " step down from primary"; + LOGV2(21478, "Requesting {target} step down from primary", "target"_attr = target); auto cbh = _replExecutor->scheduleRemoteCommand(request, remoteStepdownCallback); if (cbh.getStatus() != ErrorCodes::ShutdownInProgress) { fassert(18808, cbh.getStatus()); @@ -375,8 +385,9 @@ void ReplicationCoordinatorImpl::_stepDownFinish( if (MONGO_unlikely(blockHeartbeatStepdown.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "stepDown - blockHeartbeatStepdown fail point enabled. " - "Blocking until fail point is disabled."; + LOGV2(21479, + "stepDown - blockHeartbeatStepdown fail point enabled. " + "Blocking until fail point is disabled."); auto inShutdown = [&] { stdx::lock_guard<Latch> lk(_mutex); @@ -458,8 +469,10 @@ void ReplicationCoordinatorImpl::_scheduleHeartbeatReconfig_inlock(const ReplSet case kConfigPreStart: case kConfigStartingUp: case kConfigReplicationDisabled: - severe() << "Reconfiguration request occurred while _rsConfigState == " - << int(_rsConfigState) << "; aborting."; + LOGV2_FATAL(21491, + "Reconfiguration request occurred while _rsConfigState == " + "{int_rsConfigState}; aborting.", + "int_rsConfigState"_attr = int(_rsConfigState)); fassertFailed(18807); } _setConfigState_inlock(kConfigHBReconfiguring); @@ -489,8 +502,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore( const executor::TaskExecutor::CallbackArgs& cbd, const ReplSetConfig& newConfig) { if (cbd.status.code() == ErrorCodes::CallbackCanceled) { - log() << "The callback to persist the replica set configuration was canceled - " - << "the configuration was not persisted but was used: " << newConfig.toBSON(); + LOGV2(21480, + "The callback to persist the replica set configuration was canceled - the " + "configuration was not persisted but was used: {newConfig}", + "newConfig"_attr = newConfig.toBSON()); return; } @@ -513,9 +528,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore( bool shouldStartDataReplication = false; if (!myIndex.getStatus().isOK() && myIndex.getStatus() != ErrorCodes::NodeNotFound) { - warning() << "Not persisting new configuration in heartbeat response to disk because " - "it is invalid: " - << myIndex.getStatus(); + LOGV2_WARNING(21487, + "Not persisting new configuration in heartbeat response to disk because " + "it is invalid: {myIndex_getStatus}", + "myIndex_getStatus"_attr = myIndex.getStatus()); } else { LOG_FOR_HEARTBEATS(2) << "Config with " << newConfig.getConfigVersionAndTerm() << " validated for reconfig; persisting to disk."; @@ -527,9 +543,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore( stdx::lock_guard<Latch> lk(_mutex); isFirstConfig = !_rsConfig.isInitialized(); if (!status.isOK()) { - error() << "Ignoring new configuration in heartbeat response because we failed to" - " write it to stable storage; " - << status; + LOGV2_ERROR(21488, + "Ignoring new configuration in heartbeat response because we failed to" + " write it to stable storage; {status}", + "status"_attr = status); invariant(_rsConfigState == kConfigHBReconfiguring); if (isFirstConfig) { _setConfigState_inlock(kConfigUninitialized); @@ -626,7 +643,8 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish( lk.lock(); if (_topCoord->isSteppingDownUnconditionally()) { invariant(opCtx->lockState()->isRSTLExclusive()); - log() << "stepping down from primary, because we received a new config via heartbeat"; + LOGV2(21481, + "stepping down from primary, because we received a new config via heartbeat"); // We need to release the mutex before yielding locks for prepared transactions, which // might check out sessions, to avoid deadlocks with checked-out sessions accessing // this mutex. @@ -655,18 +673,24 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish( if (!myIndex.isOK()) { switch (myIndex.getStatus().code()) { case ErrorCodes::NodeNotFound: - log() << "Cannot find self in new replica set configuration; I must be removed; " - << myIndex.getStatus(); + LOGV2(21482, + "Cannot find self in new replica set configuration; I must be removed; " + "{myIndex_getStatus}", + "myIndex_getStatus"_attr = myIndex.getStatus()); break; case ErrorCodes::InvalidReplicaSetConfig: - error() << "Several entries in new config represent this node; " - "Removing self until an acceptable configuration arrives; " - << myIndex.getStatus(); + LOGV2_ERROR( + 21489, + "Several entries in new config represent this node; " + "Removing self until an acceptable configuration arrives; {myIndex_getStatus}", + "myIndex_getStatus"_attr = myIndex.getStatus()); break; default: - error() << "Could not validate configuration received from remote node; " - "Removing self until an acceptable configuration arrives; " - << myIndex.getStatus(); + LOGV2_ERROR( + 21490, + "Could not validate configuration received from remote node; " + "Removing self until an acceptable configuration arrives; {myIndex_getStatus}", + "myIndex_getStatus"_attr = myIndex.getStatus()); break; } myIndex = StatusWith<int>(-1); @@ -778,7 +802,8 @@ void ReplicationCoordinatorImpl::_scheduleNextLivenessUpdate_inlock() { } auto nextTimeout = earliestDate + _rsConfig.getElectionTimeoutPeriod(); - LOG(3) << "scheduling next check at " << nextTimeout; + LOGV2_DEBUG( + 21483, 3, "scheduling next check at {nextTimeout}", "nextTimeout"_attr = nextTimeout); // It is possible we will schedule the next timeout in the past. // ThreadPoolTaskExecutor::_scheduleWorkAt() schedules its work immediately if it's given a @@ -810,7 +835,7 @@ void ReplicationCoordinatorImpl::_cancelAndRescheduleLivenessUpdate_inlock(int u void ReplicationCoordinatorImpl::_cancelPriorityTakeover_inlock() { if (_priorityTakeoverCbh.isValid()) { - log() << "Canceling priority takeover callback"; + LOGV2(21484, "Canceling priority takeover callback"); _replExecutor->cancel(_priorityTakeoverCbh); _priorityTakeoverCbh = CallbackHandle(); _priorityTakeoverWhen = Date_t(); @@ -819,7 +844,7 @@ void ReplicationCoordinatorImpl::_cancelPriorityTakeover_inlock() { void ReplicationCoordinatorImpl::_cancelCatchupTakeover_inlock() { if (_catchupTakeoverCbh.isValid()) { - log() << "Canceling catchup takeover callback"; + LOGV2(21485, "Canceling catchup takeover callback"); _replExecutor->cancel(_catchupTakeoverCbh); _catchupTakeoverCbh = CallbackHandle(); _catchupTakeoverWhen = Date_t(); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp index 5532d72f701..27271617d88 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp @@ -41,6 +41,7 @@ #include "mongo/db/repl/replication_coordinator_test_fixture.h" #include "mongo/db/repl/topology_coordinator.h" #include "mongo/executor/network_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/unittest/unittest.h" #include "mongo/util/log.h" @@ -718,7 +719,10 @@ TEST_F(ReplCoordHBV1Test, enterNetwork(); const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21492, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); getNet()->scheduleResponse( noi, getNet()->now(), @@ -728,8 +732,10 @@ TEST_F(ReplCoordHBV1Test, if (request.target != HostAndPort("node2", 12345) && request.cmdObj.firstElement().fieldNameStringData() != "replSetHeartbeat") { - error() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21496, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); getNet()->blackHole(noi); } getNet()->runReadyNetworkOperations(); @@ -792,11 +798,16 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM const RemoteCommandRequest& request = noi->getRequest(); if (request.target == host2 && request.cmdObj.firstElement().fieldNameStringData() == "replSetHeartbeat") { - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21493, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); net->scheduleResponse(noi, net->now(), heartbeatResponse); } else { - log() << "blackholing request to " << request.target.toString() << ": " - << request.cmdObj; + LOGV2(21494, + "blackholing request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); @@ -810,7 +821,7 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM ASSERT_OK(getReplCoord()->processReplSetGetStatus( &statusBuilder, ReplicationCoordinator::ReplSetGetStatusResponseStyle::kBasic)); auto statusObj = statusBuilder.obj(); - unittest::log() << "replica set status = " << statusObj; + LOGV2(21495, "replica set status = {statusObj}", "statusObj"_attr = statusObj); ASSERT_EQ(mongo::Array, statusObj["members"].type()); auto members = statusObj["members"].Array(); diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index aefefa5177e..1f1e6c32160 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -63,6 +63,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/write_concern_options.h" #include "mongo/executor/network_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/stdx/future.h" @@ -1320,7 +1321,10 @@ protected: getNet()->runUntil(getNet()->now() + heartbeatInterval); NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest(); RemoteCommandRequest request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21497, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); ReplSetHeartbeatArgsV1 hbArgs; if (hbArgs.initialize(request.cmdObj).isOK()) { ReplSetHeartbeatResponse hbResp; @@ -1336,7 +1340,9 @@ protected: } while (getNet()->hasReadyRequests()) { auto noi = getNet()->getNextReadyRequest(); - log() << "Blackholing network request " << noi->getRequest().cmdObj; + LOGV2(21498, + "Blackholing network request {noi_getRequest_cmdObj}", + "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj); getNet()->blackHole(noi); } @@ -1969,7 +1975,10 @@ protected: ReplSetHeartbeatArgsV1 hbArgs; ASSERT_OK(hbArgs.initialize(request.cmdObj)); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21499, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); // Catch up 'numNodesCaughtUp' nodes out of 5. OpTime optimeResponse = (hbNum <= numNodesCaughtUp) ? optimePrimary : optimeLagged; @@ -2365,7 +2374,10 @@ TEST_F(StepDownTest, getNet()->runUntil(getNet()->now() + Milliseconds(2000)); NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest(); RemoteCommandRequest request = noi->getRequest(); - log() << "HB1: " << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21500, + "HB1: {request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); ReplSetHeartbeatArgsV1 hbArgs; if (hbArgs.initialize(request.cmdObj).isOK()) { ReplSetHeartbeatResponse hbResp; @@ -2651,7 +2663,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) { long long memberId = entry[UpdatePositionArgs::kMemberIdFieldName].Number(); memberIds.insert(memberId); if (memberId == 0) { - log() << 0; + LOGV2(21501, "{_0}", "_0"_attr = 0); ASSERT_OK(bsonExtractOpTimeField( entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime)); ASSERT_OK(bsonExtractOpTimeField( @@ -2659,7 +2671,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) { ASSERT_EQUALS(optime1, appliedOpTime); ASSERT_EQUALS(optime1, durableOpTime); } else if (memberId == 1) { - log() << 1; + LOGV2(21502, "{_1}", "_1"_attr = 1); ASSERT_OK(bsonExtractOpTimeField( entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime)); ASSERT_OK(bsonExtractOpTimeField( @@ -2667,7 +2679,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) { ASSERT_EQUALS(optime2, appliedOpTime); ASSERT_EQUALS(OpTime(), durableOpTime); } else if (memberId == 2) { - log() << 2; + LOGV2(21503, "{_2}", "_2"_attr = 2); ASSERT_OK(bsonExtractOpTimeField( entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime)); ASSERT_OK(bsonExtractOpTimeField( @@ -2675,7 +2687,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) { ASSERT_EQUALS(optime3, appliedOpTime); ASSERT_EQUALS(optime3, durableOpTime); } else { - log() << 3; + LOGV2(21504, "{_3}", "_3"_attr = 3); ASSERT_EQUALS(3, memberId); ASSERT_OK(bsonExtractOpTimeField( entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime)); @@ -3778,8 +3790,9 @@ TEST_F(ReplCoordTest, AwaitIsMasterResponseReturnsOnElectionWin) { waitForIsMasterFailPoint->waitForTimesEntered(timesEnteredFailPoint + 1); auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - unittest::log() << "Election timeout scheduled at " << electionTimeoutWhen - << " (simulator time)"; + LOGV2(21505, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); simulateSuccessfulV1ElectionWithoutExitingDrainMode(electionTimeoutWhen, opCtx.get()); waitForIsMasterFailPoint->waitForTimesEntered(timesEnteredFailPoint + 2); @@ -5682,7 +5695,7 @@ TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) { &metadataBob); BSONObj metadata = metadataBob.done(); - log() << metadata; + LOGV2(21506, "{metadata}", "metadata"_attr = metadata); auto oqMetadata = rpc::OplogQueryMetadata::readFromMetadata(metadata); ASSERT_OK(oqMetadata.getStatus()); @@ -5788,12 +5801,16 @@ TEST_F(ReplCoordTest, const auto& request = noi->getRequest(); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); - log() << "black holing " << noi->getRequest().cmdObj; + LOGV2(21507, + "black holing {noi_getRequest_cmdObj}", + "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj); net->blackHole(noi); // Advance simulator clock to some time before the first scheduled election. auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest(); - log() << "Election initially scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21508, + "Election initially scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); ASSERT_GREATER_THAN(electionTimeoutWhen, net->now()); auto until = net->now() + (electionTimeoutWhen - net->now()) / 2; net->runUntil(until); @@ -5877,7 +5894,7 @@ TEST_F(ReplCoordTest, ASSERT_TRUE(net->hasReadyRequests()); auto noi = net->getNextReadyRequest(); auto&& request = noi->getRequest(); - log() << "processing " << request.cmdObj; + LOGV2(21509, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); @@ -5934,7 +5951,7 @@ TEST_F(ReplCoordTest, ASSERT_TRUE(net->hasReadyRequests()); auto noi = net->getNextReadyRequest(); auto&& request = noi->getRequest(); - log() << "processing " << request.cmdObj; + LOGV2(21510, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); @@ -5987,7 +6004,7 @@ TEST_F(ReplCoordTest, ASSERT_TRUE(net->hasReadyRequests()); auto noi = net->getNextReadyRequest(); auto&& request = noi->getRequest(); - log() << "processing " << request.cmdObj; + LOGV2(21511, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); @@ -6035,7 +6052,7 @@ TEST_F(ReplCoordTest, ASSERT_TRUE(net->hasReadyRequests()); auto noi = net->getNextReadyRequest(); auto&& request = noi->getRequest(); - log() << "processing " << request.cmdObj; + LOGV2(21512, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); @@ -6097,12 +6114,16 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) { const auto& request = noi->getRequest(); ASSERT_EQUALS(HostAndPort("node2", 12345), request.target); ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData()); - log() << "black holing " << noi->getRequest().cmdObj; + LOGV2(21513, + "black holing {noi_getRequest_cmdObj}", + "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj); net->blackHole(noi); // Advance simulator clock to some time after the first scheduled election. auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest(); - log() << "Election initially scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21514, + "Election initially scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); ASSERT_GREATER_THAN(electionTimeoutWhen, net->now()); auto until = electionTimeoutWhen + Milliseconds(1); net->runUntil(until); diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp index f773b0d03ff..4d2c4c82dd4 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp @@ -52,6 +52,7 @@ #include "mongo/executor/network_interface_mock.h" #include "mongo/executor/thread_pool_mock.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -217,7 +218,10 @@ void ReplCoordTest::assertStartSuccess(const BSONObj& configDoc, const HostAndPo executor::RemoteCommandResponse ReplCoordTest::makeResponseStatus(const BSONObj& doc, Milliseconds millis) { - log() << "Responding with " << doc << " (elapsed: " << millis << ")"; + LOGV2(21515, + "Responding with {doc} (elapsed: {millis})", + "doc"_attr = doc, + "millis"_attr = millis); return RemoteCommandResponse(doc, millis); } @@ -229,7 +233,10 @@ void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() { for (int i = 0; i < rsConfig.getNumMembers() - 1; ++i) { const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21516, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); ReplSetHeartbeatArgsV1 hbArgs; if (hbArgs.initialize(request.cmdObj).isOK()) { ReplSetHeartbeatResponse hbResp; @@ -243,8 +250,10 @@ void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() { BSONObjBuilder respObj; net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON())); } else { - error() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21526, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); @@ -260,12 +269,15 @@ void ReplCoordTest::simulateSuccessfulDryRun( auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21517, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); int voteRequests = 0; int votesExpected = rsConfig.getNumMembers() / 2; - log() << "Simulating dry run responses - expecting " << votesExpected - << " replSetRequestVotes requests"; + LOGV2(21518, + "Simulating dry run responses - expecting {votesExpected} replSetRequestVotes requests", + "votesExpected"_attr = votesExpected); net->enterNetwork(); while (voteRequests < votesExpected) { if (net->now() < electionTimeoutWhen) { @@ -273,7 +285,10 @@ void ReplCoordTest::simulateSuccessfulDryRun( } const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21519, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { ASSERT_TRUE(request.cmdObj.getBoolField("dryRun")); onDryRunRequest(request); @@ -288,17 +303,20 @@ void ReplCoordTest::simulateSuccessfulDryRun( } else if (consumeHeartbeatV1(noi)) { // The heartbeat has been consumed. } else { - error() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21527, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); } net->exitNetwork(); - log() << "Simulating dry run responses - scheduled " << voteRequests - << " replSetRequestVotes responses"; + LOGV2(21520, + "Simulating dry run responses - scheduled {voteRequests} replSetRequestVotes responses", + "voteRequests"_attr = voteRequests); getReplCoord()->waitForElectionDryRunFinish_forTest(); - log() << "Simulating dry run responses - dry run completed"; + LOGV2(21521, "Simulating dry run responses - dry run completed"); } void ReplCoordTest::simulateSuccessfulDryRun() { @@ -309,7 +327,9 @@ void ReplCoordTest::simulateSuccessfulDryRun() { void ReplCoordTest::simulateSuccessfulV1Election() { auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest(); ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen); - log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)"; + LOGV2(21522, + "Election timeout scheduled at {electionTimeoutWhen} (simulator time)", + "electionTimeoutWhen"_attr = electionTimeoutWhen); simulateSuccessfulV1ElectionAt(electionTimeoutWhen); } @@ -325,14 +345,19 @@ void ReplCoordTest::simulateSuccessfulV1ElectionWithoutExitingDrainMode(Date_t e // Process requests until we're primary and consume the heartbeats for the notification // of election win. while (!replCoord->getMemberState().primary() || hasReadyRequests) { - log() << "Waiting on network in state " << replCoord->getMemberState(); + LOGV2(21523, + "Waiting on network in state {replCoord_getMemberState}", + "replCoord_getMemberState"_attr = replCoord->getMemberState()); getNet()->enterNetwork(); if (net->now() < electionTime) { net->runUntil(electionTime); } const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); - log() << request.target.toString() << " processing " << request.cmdObj; + LOGV2(21524, + "{request_target} processing {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); ReplSetHeartbeatArgsV1 hbArgs; Status status = hbArgs.initialize(request.cmdObj); if (status.isOK()) { @@ -354,8 +379,10 @@ void ReplCoordTest::simulateSuccessfulV1ElectionWithoutExitingDrainMode(Date_t e << "term" << request.cmdObj["term"].Long() << "voteGranted" << true))); } else { - error() << "Black holing unexpected request to " << request.target << ": " - << request.cmdObj; + LOGV2_ERROR(21528, + "Black holing unexpected request to {request_target}: {request_cmdObj}", + "request_target"_attr = request.target, + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); } net->runReadyNetworkOperations(); @@ -464,7 +491,10 @@ void ReplCoordTest::simulateCatchUpAbort() { auto noi = net->getNextReadyRequest(); auto request = noi->getRequest(); // Black hole heartbeat requests caused by time advance. - log() << "Black holing request to " << request.target.toString() << " : " << request.cmdObj; + LOGV2(21525, + "Black holing request to {request_target} : {request_cmdObj}", + "request_target"_attr = request.target.toString(), + "request_cmdObj"_attr = request.cmdObj); net->blackHole(noi); if (net->now() < heartbeatTimeoutWhen) { net->runUntil(heartbeatTimeoutWhen); diff --git a/src/mongo/db/repl/replication_process.cpp b/src/mongo/db/repl/replication_process.cpp index 117972289af..194c0194d12 100644 --- a/src/mongo/db/repl/replication_process.cpp +++ b/src/mongo/db/repl/replication_process.cpp @@ -41,6 +41,7 @@ #include "mongo/db/repl/rollback_gen.h" #include "mongo/db/repl/storage_interface.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -92,9 +93,14 @@ Status ReplicationProcess::refreshRollbackID(OperationContext* opCtx) { } if (kUninitializedRollbackId == _rbid) { - log() << "Rollback ID is " << rbidResult.getValue(); + LOGV2(21529, + "Rollback ID is {rbidResult_getValue}", + "rbidResult_getValue"_attr = rbidResult.getValue()); } else { - log() << "Rollback ID is " << rbidResult.getValue() << " (previously " << _rbid << ")"; + LOGV2(21530, + "Rollback ID is {rbidResult_getValue} (previously {rbid})", + "rbidResult_getValue"_attr = rbidResult.getValue(), + "rbid"_attr = _rbid); } _rbid = rbidResult.getValue(); @@ -106,7 +112,7 @@ int ReplicationProcess::getRollbackID() const { if (kUninitializedRollbackId == _rbid) { // This may happen when serverStatus is called by an internal client before we have a chance // to read the rollback ID from storage. - warning() << "Rollback ID is not initialized yet."; + LOGV2_WARNING(21533, "Rollback ID is not initialized yet."); } return _rbid; } @@ -122,11 +128,15 @@ Status ReplicationProcess::initializeRollbackID(OperationContext* opCtx) { auto initRbidSW = _storageInterface->initializeRollbackID(opCtx); if (initRbidSW.isOK()) { - log() << "Initialized the rollback ID to " << initRbidSW.getValue(); + LOGV2(21531, + "Initialized the rollback ID to {initRbidSW_getValue}", + "initRbidSW_getValue"_attr = initRbidSW.getValue()); _rbid = initRbidSW.getValue(); invariant(kUninitializedRollbackId != _rbid); } else { - warning() << "Failed to initialize the rollback ID: " << initRbidSW.getStatus().reason(); + LOGV2_WARNING(21534, + "Failed to initialize the rollback ID: {initRbidSW_getStatus_reason}", + "initRbidSW_getStatus_reason"_attr = initRbidSW.getStatus().reason()); } return initRbidSW.getStatus(); } @@ -139,11 +149,15 @@ Status ReplicationProcess::incrementRollbackID(OperationContext* opCtx) { // If the rollback ID was incremented successfully, cache the new value in _rbid to be returned // the next time getRollbackID() is called. if (status.isOK()) { - log() << "Incremented the rollback ID to " << status.getValue(); + LOGV2(21532, + "Incremented the rollback ID to {status_getValue}", + "status_getValue"_attr = status.getValue()); _rbid = status.getValue(); invariant(kUninitializedRollbackId != _rbid); } else { - warning() << "Failed to increment the rollback ID: " << status.getStatus().reason(); + LOGV2_WARNING(21535, + "Failed to increment the rollback ID: {status_getStatus_reason}", + "status_getStatus_reason"_attr = status.getStatus().reason()); } return status.getStatus(); diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index 3c7b47d3285..f28c9aaa2d1 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -50,6 +50,7 @@ #include "mongo/db/storage/storage_parameters_gen.h" #include "mongo/db/transaction_history_iterator.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/timer.h" @@ -90,8 +91,12 @@ public: void onBatchEnd(const StatusWith<OpTime>&, const std::vector<OplogEntry>&) final {} void complete(const OpTime& applyThroughOpTime) const { - log() << "Applied " << _numOpsApplied << " operations in " << _numBatches - << " batches. Last operation applied with optime: " << applyThroughOpTime; + LOGV2(21536, + "Applied {numOpsApplied} operations in {numBatches} batches. Last operation applied " + "with optime: {applyThroughOpTime}", + "numOpsApplied"_attr = _numOpsApplied, + "numBatches"_attr = _numBatches, + "applyThroughOpTime"_attr = applyThroughOpTime); } private: @@ -134,16 +139,21 @@ public: ss << " and <= " << _oplogApplicationEndPoint->toBSON(); } - severe() << "Couldn't find any entries in the oplog" << ss.str() - << ", which should be impossible."; + LOGV2_FATAL( + 21559, + "Couldn't find any entries in the oplog{ss_str}, which should be impossible.", + "ss_str"_attr = ss.str()); fassertFailedNoTrace(40293); } auto firstTimestampFound = fassert(40291, OpTime::parseFromOplogEntry(_cursor->nextSafe())).getTimestamp(); if (firstTimestampFound != _oplogApplicationStartPoint) { - severe() << "Oplog entry at " << _oplogApplicationStartPoint.toBSON() - << " is missing; actual entry found is " << firstTimestampFound.toBSON(); + LOGV2_FATAL(21560, + "Oplog entry at {oplogApplicationStartPoint} is missing; actual entry " + "found is {firstTimestampFound}", + "oplogApplicationStartPoint"_attr = _oplogApplicationStartPoint.toBSON(), + "firstTimestampFound"_attr = firstTimestampFound.toBSON()); fassertFailedNoTrace(40292); } } @@ -210,8 +220,9 @@ private: boost::optional<Timestamp> recoverFromOplogPrecursor(OperationContext* opCtx, StorageInterface* storageInterface) { if (!storageInterface->supportsRecoveryTimestamp(opCtx->getServiceContext())) { - severe() << "Cannot recover from the oplog with a storage engine that does not support " - << "recover to stable timestamp."; + LOGV2_FATAL(21561, + "Cannot recover from the oplog with a storage engine that does not support " + "recover to stable timestamp."); fassertFailedNoTrace(50805); } @@ -220,7 +231,8 @@ boost::optional<Timestamp> recoverFromOplogPrecursor(OperationContext* opCtx, // happen. auto recoveryTS = storageInterface->getRecoveryTimestamp(opCtx->getServiceContext()); if (recoveryTS && recoveryTS->isNull()) { - severe() << "Cannot recover from the oplog with stable checkpoint at null timestamp."; + LOGV2_FATAL(21562, + "Cannot recover from the oplog with stable checkpoint at null timestamp."); fassertFailedNoTrace(50806); } @@ -238,36 +250,44 @@ void ReplicationRecoveryImpl::_assertNoRecoveryNeededOnUnstableCheckpoint(Operat invariant(!_storageInterface->getRecoveryTimestamp(opCtx->getServiceContext())); if (_consistencyMarkers->getInitialSyncFlag(opCtx)) { - severe() << "Unexpected recovery needed, initial sync flag set."; + LOGV2_FATAL(21563, "Unexpected recovery needed, initial sync flag set."); fassertFailedNoTrace(31362); } const auto truncateAfterPoint = _consistencyMarkers->getOplogTruncateAfterPoint(opCtx); if (!truncateAfterPoint.isNull()) { - severe() << "Unexpected recovery needed, oplog requires truncation. Truncate after point: " - << truncateAfterPoint.toString(); + LOGV2_FATAL(21564, + "Unexpected recovery needed, oplog requires truncation. Truncate after point: " + "{truncateAfterPoint}", + "truncateAfterPoint"_attr = truncateAfterPoint.toString()); fassertFailedNoTrace(31363); } auto topOfOplogSW = _getTopOfOplog(opCtx); if (!topOfOplogSW.isOK()) { - severe() << "Recovery not possible, no oplog found: " << topOfOplogSW.getStatus(); + LOGV2_FATAL(21565, + "Recovery not possible, no oplog found: {topOfOplogSW_getStatus}", + "topOfOplogSW_getStatus"_attr = topOfOplogSW.getStatus()); fassertFailedNoTrace(31364); } const auto topOfOplog = topOfOplogSW.getValue(); const auto appliedThrough = _consistencyMarkers->getAppliedThrough(opCtx); if (!appliedThrough.isNull() && appliedThrough != topOfOplog) { - severe() << "Unexpected recovery needed, appliedThrough is not at top of oplog, indicating " - "oplog has not been fully applied. appliedThrough: " - << appliedThrough.toString(); + LOGV2_FATAL(21566, + "Unexpected recovery needed, appliedThrough is not at top of oplog, indicating " + "oplog has not been fully applied. appliedThrough: {appliedThrough}", + "appliedThrough"_attr = appliedThrough.toString()); fassertFailedNoTrace(31365); } const auto minValid = _consistencyMarkers->getMinValid(opCtx); if (minValid > topOfOplog) { - severe() << "Unexpected recovery needed, top of oplog is not consistent. topOfOplog: " - << topOfOplog << ", minValid: " << minValid; + LOGV2_FATAL(21567, + "Unexpected recovery needed, top of oplog is not consistent. topOfOplog: " + "{topOfOplog}, minValid: {minValid}", + "topOfOplog"_attr = topOfOplog, + "minValid"_attr = minValid); fassertFailedNoTrace(31366); } } @@ -287,21 +307,25 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC if (gTakeUnstableCheckpointOnShutdown) { // Ensure 'recoverFromOplogAsStandalone' with 'takeUnstableCheckpointOnShutdown' // is safely idempotent when it succeeds. - log() << "Recovering from unstable checkpoint with 'takeUnstableCheckpointOnShutdown'." - << " Confirming that no oplog recovery is needed."; + LOGV2(21537, + "Recovering from unstable checkpoint with 'takeUnstableCheckpointOnShutdown'. " + "Confirming that no oplog recovery is needed."); _assertNoRecoveryNeededOnUnstableCheckpoint(opCtx); - log() << "Not doing any oplog recovery since there is an unstable checkpoint that is " - << "up to date."; + LOGV2(21538, + "Not doing any oplog recovery since there is an unstable checkpoint that is up " + "to date."); } else { - severe() << "Cannot use 'recoverFromOplogAsStandalone' without a stable checkpoint."; + LOGV2_FATAL(21568, + "Cannot use 'recoverFromOplogAsStandalone' without a stable checkpoint."); fassertFailedNoTrace(31229); } } reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering); - warning() << "Setting mongod to readOnly mode as a result of specifying " - "'recoverFromOplogAsStandalone'."; + LOGV2_WARNING(21558, + "Setting mongod to readOnly mode as a result of specifying " + "'recoverFromOplogAsStandalone'."); storageGlobalParams.readOnly = true; } @@ -313,7 +337,7 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time auto recoveryTS = recoverFromOplogPrecursor(opCtx, _storageInterface); if (!recoveryTS) { - severe() << "Cannot use 'recoverToOplogTimestamp' without a stable checkpoint."; + LOGV2_FATAL(21569, "Cannot use 'recoverToOplogTimestamp' without a stable checkpoint."); fassertFailedNoTrace(31399); } @@ -322,15 +346,18 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time Timestamp startPoint = _consistencyMarkers->getAppliedThrough(opCtx).getTimestamp(); if (startPoint.isNull()) { - log() << "No stored oplog entries to apply for recovery."; + LOGV2(21539, "No stored oplog entries to apply for recovery."); return; } invariant(!endPoint.isNull()); if (startPoint == endPoint) { - log() << "No oplog entries to apply for recovery. Start point '" << startPoint - << "' is at the end point '" << endPoint << "' in the oplog."; + LOGV2(21540, + "No oplog entries to apply for recovery. Start point '{startPoint}' is at the end " + "point '{endPoint}' in the oplog.", + "startPoint"_attr = startPoint, + "endPoint"_attr = endPoint); return; } else if (startPoint > endPoint) { uasserted(ErrorCodes::BadValue, @@ -341,8 +368,11 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time Timestamp appliedUpTo = _applyOplogOperations(opCtx, startPoint, endPoint); if (appliedUpTo.isNull()) { - log() << "No stored oplog entries to apply for recovery between " << startPoint.toString() - << " (inclusive) and " << endPoint.toString() << " (inclusive)."; + LOGV2(21541, + "No stored oplog entries to apply for recovery between {startPoint} (inclusive) and " + "{endPoint} (inclusive).", + "startPoint"_attr = startPoint.toString(), + "endPoint"_attr = endPoint.toString()); } else { invariant(appliedUpTo <= endPoint); } @@ -353,7 +383,7 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx, boost::optional<Timestamp> stableTimestamp) try { if (_consistencyMarkers->getInitialSyncFlag(opCtx)) { - log() << "No recovery needed. Initial sync flag set."; + LOGV2(21542, "No recovery needed. Initial sync flag set."); return; // Initial Sync will take over so no cleanup is needed. } @@ -393,7 +423,7 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx, topOfOplogSW.getStatus() == ErrorCodes::NamespaceNotFound) { // Oplog is empty. There are no oplog entries to apply, so we exit recovery and go into // initial sync. - log() << "No oplog entries to apply for recovery. Oplog is empty."; + LOGV2(21543, "No oplog entries to apply for recovery. Oplog is empty."); return; } fassert(40290, topOfOplogSW); @@ -406,7 +436,9 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx, _recoverFromUnstableCheckpoint(opCtx, appliedThrough, topOfOplog); } } catch (...) { - severe() << "Caught exception during replication recovery: " << exceptionToStatus(); + LOGV2_FATAL(21570, + "Caught exception during replication recovery: {exceptionToStatus}", + "exceptionToStatus"_attr = exceptionToStatus()); std::terminate(); } @@ -419,11 +451,17 @@ void ReplicationRecoveryImpl::_recoverFromStableTimestamp(OperationContext* opCt const auto truncateAfterPoint = _consistencyMarkers->getOplogTruncateAfterPoint(opCtx); - log() << "Recovering from stable timestamp: " << stableTimestamp - << " (top of oplog: " << topOfOplog << ", appliedThrough: " << appliedThrough - << ", TruncateAfter: " << truncateAfterPoint << ")"; - - log() << "Starting recovery oplog application at the stable timestamp: " << stableTimestamp; + LOGV2(21544, + "Recovering from stable timestamp: {stableTimestamp} (top of oplog: {topOfOplog}, " + "appliedThrough: {appliedThrough}, TruncateAfter: {truncateAfterPoint})", + "stableTimestamp"_attr = stableTimestamp, + "topOfOplog"_attr = topOfOplog, + "appliedThrough"_attr = appliedThrough, + "truncateAfterPoint"_attr = truncateAfterPoint); + + LOGV2(21545, + "Starting recovery oplog application at the stable timestamp: {stableTimestamp}", + "stableTimestamp"_attr = stableTimestamp); _applyToEndOfOplog(opCtx, stableTimestamp, topOfOplog.getTimestamp()); } @@ -431,18 +469,24 @@ void ReplicationRecoveryImpl::_recoverFromUnstableCheckpoint(OperationContext* o OpTime appliedThrough, OpTime topOfOplog) { invariant(!topOfOplog.isNull()); - log() << "Recovering from an unstable checkpoint (top of oplog: " << topOfOplog - << ", appliedThrough: " << appliedThrough << ")"; + LOGV2(21546, + "Recovering from an unstable checkpoint (top of oplog: {topOfOplog}, appliedThrough: " + "{appliedThrough})", + "topOfOplog"_attr = topOfOplog, + "appliedThrough"_attr = appliedThrough); if (appliedThrough.isNull()) { // The appliedThrough would be null if we shut down cleanly or crashed as a primary. Either // way we are consistent at the top of the oplog. - log() << "No oplog entries to apply for recovery. appliedThrough is null."; + LOGV2(21547, "No oplog entries to apply for recovery. appliedThrough is null."); } else { // If the appliedThrough is not null, then we shut down uncleanly during secondary oplog // application and must apply from the appliedThrough to the top of the oplog. - log() << "Starting recovery oplog application at the appliedThrough: " << appliedThrough - << ", through the top of the oplog: " << topOfOplog; + LOGV2(21548, + "Starting recovery oplog application at the appliedThrough: {appliedThrough}, " + "through the top of the oplog: {topOfOplog}", + "appliedThrough"_attr = appliedThrough, + "topOfOplog"_attr = topOfOplog); // When `recoverFromOplog` truncates the oplog, that also happens to set the "oldest // timestamp" to the truncation point[1]. `_applyToEndOfOplog` will then perform writes @@ -492,11 +536,15 @@ void ReplicationRecoveryImpl::_applyToEndOfOplog(OperationContext* opCtx, // Check if we have any unapplied ops in our oplog. It is important that this is done after // deleting the ragged end of the oplog. if (oplogApplicationStartPoint == topOfOplog) { - log() << "No oplog entries to apply for recovery. Start point is at the top of the oplog."; + LOGV2(21549, + "No oplog entries to apply for recovery. Start point is at the top of the oplog."); return; // We've applied all the valid oplog we have. } else if (oplogApplicationStartPoint > topOfOplog) { - severe() << "Applied op " << oplogApplicationStartPoint.toBSON() - << " not found. Top of oplog is " << topOfOplog.toBSON() << '.'; + LOGV2_FATAL( + 21571, + "Applied op {oplogApplicationStartPoint} not found. Top of oplog is {topOfOplog}.", + "oplogApplicationStartPoint"_attr = oplogApplicationStartPoint.toBSON(), + "topOfOplog"_attr = topOfOplog.toBSON()); fassertFailedNoTrace(40313); } @@ -511,8 +559,10 @@ void ReplicationRecoveryImpl::_applyToEndOfOplog(OperationContext* opCtx, Timestamp ReplicationRecoveryImpl::_applyOplogOperations(OperationContext* opCtx, const Timestamp& startPoint, const Timestamp& endPoint) { - log() << "Replaying stored operations from " << startPoint << " (inclusive) to " << endPoint - << " (inclusive)."; + LOGV2(21550, + "Replaying stored operations from {startPoint} (inclusive) to {endPoint} (inclusive).", + "startPoint"_attr = startPoint, + "endPoint"_attr = endPoint); OplogBufferLocalOplog oplogBuffer(startPoint, endPoint); oplogBuffer.startup(opCtx); @@ -616,9 +666,10 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx, const auto tsElem = entry["ts"]; if (count == 1) { if (tsElem.eoo()) { - LOG(2) << "Oplog tail entry: " << redact(entry); + LOGV2_DEBUG(21551, 2, "Oplog tail entry: {entry}", "entry"_attr = redact(entry)); } else { - LOG(2) << "Oplog tail entry ts field: " << tsElem; + LOGV2_DEBUG( + 21552, 2, "Oplog tail entry ts field: {tsElem}", "tsElem"_attr = tsElem); topOfOplog = tsElem.timestamp(); } } @@ -627,24 +678,35 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx, // If count == 1, that means that we have nothing to delete because everything in the // oplog is <= truncateTimestamp. if (count != 1) { - log() << "Truncating oplog from [" << Timestamp(previousRecordId.repr()) << " to " - << topOfOplog << "]. Truncate after point is " << truncateTimestamp; + LOGV2(21553, + "Truncating oplog from [{Timestamp_previousRecordId_repr} to {topOfOplog}]. " + "Truncate after point is {truncateTimestamp}", + "Timestamp_previousRecordId_repr"_attr = Timestamp(previousRecordId.repr()), + "topOfOplog"_attr = topOfOplog, + "truncateTimestamp"_attr = truncateTimestamp); invariant(!previousRecordId.isNull()); oplogCollection->cappedTruncateAfter(opCtx, previousRecordId, /*inclusive*/ true); } else { - log() << "There is no oplog after " << truncateTimestamp - << " to truncate. The top of the oplog is " << topOfOplog; + LOGV2(21554, + "There is no oplog after {truncateTimestamp} to truncate. The top of the " + "oplog is {topOfOplog}", + "truncateTimestamp"_attr = truncateTimestamp, + "topOfOplog"_attr = topOfOplog); } - log() << "Replication recovery oplog truncation finished in: " << timer.millis() - << "ms"; + LOGV2(21555, + "Replication recovery oplog truncation finished in: {timer_millis}ms", + "timer_millis"_attr = timer.millis()); return; } previousRecordId = id; } - severe() << "Reached end of oplog looking for oplog entry before " << truncateTimestamp.toBSON() - << " but couldn't find any after looking through " << count << " entries."; + LOGV2_FATAL(21572, + "Reached end of oplog looking for oplog entry before {truncateTimestamp} but " + "couldn't find any after looking through {count} entries.", + "truncateTimestamp"_attr = truncateTimestamp.toBSON(), + "count"_attr = count); fassertFailedNoTrace(40296); } @@ -661,14 +723,18 @@ void ReplicationRecoveryImpl::_truncateOplogIfNeededAndThenClearOplogTruncateAft AutoGetCollectionForRead oplog(opCtx, NamespaceString::kRsOplogNamespace); invariant(oplog.getCollection()); - log() << "The oplog truncation point (" << truncatePoint - << ") is equal to or earlier than the stable timestamp (" << stableTimestamp.get() - << "), so truncating after the stable timestamp instead"; + LOGV2(21556, + "The oplog truncation point ({truncatePoint}) is equal to or earlier than the stable " + "timestamp ({stableTimestamp_get}), so truncating after the stable timestamp instead", + "truncatePoint"_attr = truncatePoint, + "stableTimestamp_get"_attr = stableTimestamp.get()); truncatePoint = stableTimestamp.get(); } - log() << "Removing unapplied oplog entries starting after: " << truncatePoint.toBSON(); + LOGV2(21557, + "Removing unapplied oplog entries starting after: {truncatePoint}", + "truncatePoint"_attr = truncatePoint.toBSON()); _truncateOplogTo(opCtx, truncatePoint); // Clear the oplogTruncateAfterPoint now that we have removed any holes that might exist in the diff --git a/src/mongo/db/repl/reporter.cpp b/src/mongo/db/repl/reporter.cpp index f66eb930893..2d23ef4e256 100644 --- a/src/mongo/db/repl/reporter.cpp +++ b/src/mongo/db/repl/reporter.cpp @@ -37,6 +37,7 @@ #include "mongo/bson/util/bson_extract.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/repl/update_position_args.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/assert_util.h" #include "mongo/util/destructor_guard.h" @@ -190,8 +191,11 @@ Status Reporter::trigger() { _status = scheduleResult.getStatus(); if (!_status.isOK()) { - LOG(2) << "Reporter failed to schedule callback to prepare and send update command: " - << _status; + LOGV2_DEBUG( + 21585, + 2, + "Reporter failed to schedule callback to prepare and send update command: {status}", + "status"_attr = _status); return _status; } @@ -212,8 +216,11 @@ StatusWith<BSONObj> Reporter::_prepareCommand() { // If there was an error in preparing the command, abort and return that error. if (!prepareResult.isOK()) { - LOG(2) << "Reporter failed to prepare update command with status: " - << prepareResult.getStatus(); + LOGV2_DEBUG( + 21586, + 2, + "Reporter failed to prepare update command with status: {prepareResult_getStatus}", + "prepareResult_getStatus"_attr = prepareResult.getStatus()); _status = prepareResult.getStatus(); return _status; } @@ -222,8 +229,12 @@ StatusWith<BSONObj> Reporter::_prepareCommand() { } void Reporter::_sendCommand_inlock(BSONObj commandRequest, Milliseconds netTimeout) { - LOG(2) << "Reporter sending slave oplog progress to upstream updater " << _target << ": " - << commandRequest; + LOGV2_DEBUG( + 21587, + 2, + "Reporter sending slave oplog progress to upstream updater {target}: {commandRequest}", + "target"_attr = _target, + "commandRequest"_attr = commandRequest); auto scheduleResult = _executor->scheduleRemoteCommand( executor::RemoteCommandRequest(_target, "admin", commandRequest, nullptr, netTimeout), @@ -233,7 +244,8 @@ void Reporter::_sendCommand_inlock(BSONObj commandRequest, Milliseconds netTimeo _status = scheduleResult.getStatus(); if (!_status.isOK()) { - LOG(2) << "Reporter failed to schedule with status: " << _status; + LOGV2_DEBUG( + 21588, 2, "Reporter failed to schedule with status: {status}", "status"_attr = _status); if (_status != ErrorCodes::ShutdownInProgress) { fassert(34434, _status); } @@ -272,8 +284,10 @@ void Reporter::_processResponseCallback( // sync target. if (_status == ErrorCodes::InvalidReplicaSetConfig && _isTargetConfigNewerThanRequest(commandResult, rcbd.request.cmdObj)) { - LOG(1) << "Reporter found newer configuration on sync source: " << _target - << ". Retrying."; + LOGV2_DEBUG(21589, + 1, + "Reporter found newer configuration on sync source: {target}. Retrying.", + "target"_attr = _target); _status = Status::OK(); // Do not resend update command immediately. _isWaitingToSendReporter = false; diff --git a/src/mongo/db/repl/roll_back_local_operations.cpp b/src/mongo/db/repl/roll_back_local_operations.cpp index 1e5b102a595..04ea36b725d 100644 --- a/src/mongo/db/repl/roll_back_local_operations.cpp +++ b/src/mongo/db/repl/roll_back_local_operations.cpp @@ -33,6 +33,7 @@ #include "mongo/db/repl/roll_back_local_operations.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -114,7 +115,10 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollBackLocalOperations while (getTimestamp(_localOplogValue) > getTimestamp(operation)) { _scanned++; - LOG(2) << "Local oplog entry to roll back: " << redact(_localOplogValue.first); + LOGV2_DEBUG(21656, + 2, + "Local oplog entry to roll back: {localOplogValue_first}", + "localOplogValue_first"_attr = redact(_localOplogValue.first)); auto status = _rollbackOperation(_localOplogValue.first); if (!status.isOK()) { invariant(ErrorCodes::NoSuchKey != status.code()); diff --git a/src/mongo/db/repl/roll_back_local_operations_test.cpp b/src/mongo/db/repl/roll_back_local_operations_test.cpp index 6d4261938ea..659ac806d09 100644 --- a/src/mongo/db/repl/roll_back_local_operations_test.cpp +++ b/src/mongo/db/repl/roll_back_local_operations_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <iterator> @@ -39,7 +41,9 @@ #include "mongo/db/repl/oplog_interface_mock.h" #include "mongo/db/repl/oplog_interface_remote.h" #include "mongo/db/repl/roll_back_local_operations.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace { @@ -326,14 +330,15 @@ public: int batchSize) override { if (_initFailuresLeft > 0) { _initFailuresLeft--; - unittest::log() - << "Throwing DBException on DBClientCursorForTest::query(). Failures left: " - << _initFailuresLeft; + LOGV2(21657, + "Throwing DBException on DBClientCursorForTest::query(). Failures left: " + "{initFailuresLeft}", + "initFailuresLeft"_attr = _initFailuresLeft); uasserted(50852, "Simulated network error"); MONGO_UNREACHABLE; } - unittest::log() << "Returning success on DBClientCursorForTest::query()"; + LOGV2(21658, "Returning success on DBClientCursorForTest::query()"); BSONArrayBuilder builder; builder.append(makeOp(1)); diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index b61005e8878..aa5d60beb85 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -62,6 +62,7 @@ #include "mongo/db/session_txn_record_gen.h" #include "mongo/db/storage/remove_saver.h" #include "mongo/db/transaction_history_iterator.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_config_version.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -99,10 +100,11 @@ boost::optional<long long> _parseDroppedCollectionCount(const OplogEntry& oplogE auto obj2 = oplogEntry.getObject2(); if (!obj2) { - warning() << "Unable to get collection count from " << desc - << " without the o2 " - "field. oplog op: " - << redact(oplogEntry.toBSON()); + LOGV2_WARNING(21634, + "Unable to get collection count from {desc} without the o2 " + "field. oplog op: {oplogEntry}", + "desc"_attr = desc, + "oplogEntry"_attr = redact(oplogEntry.toBSON())); return boost::none; } @@ -110,19 +112,30 @@ boost::optional<long long> _parseDroppedCollectionCount(const OplogEntry& oplogE // TODO: Use IDL to parse o2 object. See txn_cmds.idl for example. auto status = bsonExtractIntegerField(*obj2, kNumRecordsFieldName, &count); if (!status.isOK()) { - warning() << "Failed to parse " << desc << " for collection count: " << status - << ". oplog op: " << redact(oplogEntry.toBSON()); + LOGV2_WARNING( + 21635, + "Failed to parse {desc} for collection count: {status}. oplog op: {oplogEntry}", + "desc"_attr = desc, + "status"_attr = status, + "oplogEntry"_attr = redact(oplogEntry.toBSON())); return boost::none; } if (count < 0) { - warning() << "Invalid collection count found in " << desc << ": " << count - << ". oplog op: " << redact(oplogEntry.toBSON()); + LOGV2_WARNING(21636, + "Invalid collection count found in {desc}: {count}. oplog op: {oplogEntry}", + "desc"_attr = desc, + "count"_attr = count, + "oplogEntry"_attr = redact(oplogEntry.toBSON())); return boost::none; } - LOG(2) << "Parsed collection count of " << count << " from " << desc - << ". oplog op: " << redact(oplogEntry.toBSON()); + LOGV2_DEBUG(21590, + 2, + "Parsed collection count of {count} from {desc}. oplog op: {oplogEntry}", + "count"_attr = count, + "desc"_attr = desc, + "oplogEntry"_attr = redact(oplogEntry.toBSON())); return count; } @@ -182,8 +195,9 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) { _listener->onTransitionToRollback(); if (MONGO_unlikely(rollbackHangAfterTransitionToRollback.shouldFail())) { - log() << "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail " - "point is disabled (rollback_impl)."; + LOGV2(21591, + "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail " + "point is disabled (rollback_impl)."); rollbackHangAfterTransitionToRollback.pauseWhileSet(opCtx); } @@ -251,7 +265,7 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) { } _listener->onRollbackOpObserver(_observerInfo); - log() << "Rollback complete"; + LOGV2(21592, "Rollback complete"); return Status::OK(); } @@ -308,7 +322,7 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) { return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down"); } - log() << "transition to ROLLBACK"; + LOGV2(21593, "transition to ROLLBACK"); { ReplicationStateTransitionLockGuard rstlLock( opCtx, MODE_X, ReplicationStateTransitionLockGuard::EnqueueOnly()); @@ -327,7 +341,7 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) { << "Cannot transition from " << _replicationCoordinator->getMemberState().toString() << " to " << MemberState(MemberState::RS_ROLLBACK).toString()); - log() << status; + LOGV2(21594, "{status}", "status"_attr = status); return status; } } @@ -350,14 +364,19 @@ Status RollbackImpl::_awaitBgIndexCompletion(OperationContext* opCtx) { // Wait for all background operations to complete by waiting on each database. std::vector<StringData> dbNames(dbs.begin(), dbs.end()); - log() << "Waiting for all background operations to complete before starting rollback"; + LOGV2(21595, "Waiting for all background operations to complete before starting rollback"); for (auto db : dbNames) { auto numInProg = BackgroundOperation::numInProgForDb(db); auto numInProgInCoordinator = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(db); if (numInProg > 0 || numInProgInCoordinator > 0) { - LOG(1) << "Waiting for " - << (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator) - << " background operations to complete on database '" << db << "'"; + LOGV2_DEBUG( + 21596, + 1, + "Waiting for {numInProg_numInProgInCoordinator_numInProg_numInProgInCoordinator} " + "background operations to complete on database '{db}'", + "numInProg_numInProgInCoordinator_numInProg_numInProgInCoordinator"_attr = + (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator), + "db"_attr = db); BackgroundOperation::awaitNoBgOpInProgForDb(db); IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(db); } @@ -368,7 +387,7 @@ Status RollbackImpl::_awaitBgIndexCompletion(OperationContext* opCtx) { } } - log() << "Finished waiting for background operations to complete before rollback"; + LOGV2(21597, "Finished waiting for background operations to complete before rollback"); return Status::OK(); } @@ -478,7 +497,7 @@ void RollbackImpl::_runPhaseFromAbortToReconstructPreparedTxns( status = _writeRollbackFiles(opCtx); fassert(31228, status); } else { - log() << "Not writing rollback files. 'createRollbackDataFiles' set to false."; + LOGV2(21598, "Not writing rollback files. 'createRollbackDataFiles' set to false."); } // If there were rolled back operations on any session, invalidate all sessions. @@ -497,16 +516,24 @@ void RollbackImpl::_runPhaseFromAbortToReconstructPreparedTxns( // Log the total number of insert and update operations that have been rolled back as a // result of recovering to the stable timestamp. - log() << "Rollback reverted " << _observerInfo.rollbackCommandCounts[kInsertCmdName] - << " insert operations, " << _observerInfo.rollbackCommandCounts[kUpdateCmdName] - << " update operations and " << _observerInfo.rollbackCommandCounts[kDeleteCmdName] - << " delete operations."; + LOGV2(21599, + "Rollback reverted {observerInfo_rollbackCommandCounts_kInsertCmdName} insert " + "operations, {observerInfo_rollbackCommandCounts_kUpdateCmdName} update operations and " + "{observerInfo_rollbackCommandCounts_kDeleteCmdName} delete operations.", + "observerInfo_rollbackCommandCounts_kInsertCmdName"_attr = + _observerInfo.rollbackCommandCounts[kInsertCmdName], + "observerInfo_rollbackCommandCounts_kUpdateCmdName"_attr = + _observerInfo.rollbackCommandCounts[kUpdateCmdName], + "observerInfo_rollbackCommandCounts_kDeleteCmdName"_attr = + _observerInfo.rollbackCommandCounts[kDeleteCmdName]); // During replication recovery, we truncate all oplog entries with timestamps greater than the // oplog truncate after point. If we entered rollback, we are guaranteed to have at least one // oplog entry after the common point. - log() << "Marking to truncate all oplog entries with timestamps greater than " - << commonPoint.getOpTime().getTimestamp(); + LOGV2(21600, + "Marking to truncate all oplog entries with timestamps greater than " + "{commonPoint_getOpTime_getTimestamp}", + "commonPoint_getOpTime_getTimestamp"_attr = commonPoint.getOpTime().getTimestamp()); Timestamp truncatePoint = commonPoint.getOpTime().getTimestamp(); // Persist the truncate point to the 'oplogTruncateAfterPoint' document. We save this value so @@ -568,9 +595,14 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) { // if we just set the collection count here. if (sizeRecoveryState(opCtx->getServiceContext()) .collectionAlwaysNeedsSizeAdjustment(ident)) { - LOG(2) << "Not setting collection count to " << newCount << " for " << nss.ns() << " (" - << uuid.toString() << ") [" << ident - << "] because it is marked for size adjustment."; + LOGV2_DEBUG(21601, + 2, + "Not setting collection count to {newCount} for {nss_ns} ({uuid}) " + "[{ident}] because it is marked for size adjustment.", + "newCount"_attr = newCount, + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "ident"_attr = ident); continue; } @@ -578,8 +610,10 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) { // (most likely due to a 4.0 drop oplog entry without the count information), we will // determine the correct count here post-recovery using a collection scan. if (kCollectionScanRequired == newCount) { - log() << "Scanning collection " << nss.ns() << " (" << uuid.toString() - << ") to fix collection count."; + LOGV2(21602, + "Scanning collection {nss_ns} ({uuid}) to fix collection count.", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString()); AutoGetCollectionForRead autoCollToScan(opCtx, nss); auto collToScan = autoCollToScan.getCollection(); invariant(coll == collToScan, @@ -596,9 +630,13 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) { if (PlanExecutor::IS_EOF != state) { // We ignore errors here because crashing or leaving rollback would only leave // collection counts more inaccurate. - warning() << "Failed to set count of " << nss.ns() << " (" << uuid.toString() - << ") [" << ident - << "] due to failed collection scan: " << exec->statestr(state); + LOGV2_WARNING(21637, + "Failed to set count of {nss_ns} ({uuid}) [{ident}] due to failed " + "collection scan: {exec_statestr_state}", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "ident"_attr = ident, + "exec_statestr_state"_attr = exec->statestr(state)); continue; } newCount = countFromScan; @@ -609,11 +647,22 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) { if (!status.isOK()) { // We ignore errors here because crashing or leaving rollback would only leave // collection counts more inaccurate. - warning() << "Failed to set count of " << nss.ns() << " (" << uuid.toString() << ") [" - << ident << "] to " << newCount << ". Received: " << status; + LOGV2_WARNING(21638, + "Failed to set count of {nss_ns} ({uuid}) [{ident}] to {newCount}. " + "Received: {status}", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "ident"_attr = ident, + "newCount"_attr = newCount, + "status"_attr = status); } else { - LOG(2) << "Set collection count of " << nss.ns() << " (" << uuid.toString() << ") [" - << ident << "] to " << newCount << "."; + LOGV2_DEBUG(21603, + 2, + "Set collection count of {nss_ns} ({uuid}) [{ident}] to {newCount}.", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "ident"_attr = ident, + "newCount"_attr = newCount); } } } @@ -622,7 +671,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) { const auto& catalog = CollectionCatalog::get(opCtx); auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); - log() << "finding record store counts"; + LOGV2(21604, "finding record store counts"); for (const auto& uiCount : _countDiffs) { auto uuid = uiCount.first; auto countDiff = uiCount.second; @@ -662,10 +711,13 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) { } if (oldCount > static_cast<uint64_t>(std::numeric_limits<long long>::max())) { - warning() << "Count for " << nss->ns() << " (" << uuid.toString() << ") was " - << oldCount - << " which is larger than the maximum int64_t value. Not attempting to fix " - "count during rollback."; + LOGV2_WARNING(21639, + "Count for {nss_ns} ({uuid}) was {oldCount} which is larger than the " + "maximum int64_t value. Not attempting to fix " + "count during rollback.", + "nss_ns"_attr = nss->ns(), + "uuid"_attr = uuid.toString(), + "oldCount"_attr = oldCount); continue; } @@ -673,17 +725,28 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) { auto newCount = oldCountSigned + countDiff; if (newCount < 0) { - warning() << "Attempted to set count for " << nss->ns() << " (" << uuid.toString() - << ") to " << newCount - << " but set it to 0 instead. This is likely due to the count previously " - "becoming inconsistent from an unclean shutdown or a rollback that could " - "not fix the count correctly. Old count: " - << oldCount << ". Count change: " << countDiff; + LOGV2_WARNING( + 21640, + "Attempted to set count for {nss_ns} ({uuid}) to {newCount} but set it to 0 " + "instead. This is likely due to the count previously " + "becoming inconsistent from an unclean shutdown or a rollback that could " + "not fix the count correctly. Old count: {oldCount}. Count change: {countDiff}", + "nss_ns"_attr = nss->ns(), + "uuid"_attr = uuid.toString(), + "newCount"_attr = newCount, + "oldCount"_attr = oldCount, + "countDiff"_attr = countDiff); newCount = 0; } - LOG(2) << "Record count of " << nss->ns() << " (" << uuid.toString() - << ") before rollback is " << oldCount << ". Setting it to " << newCount - << ", due to change of " << countDiff; + LOGV2_DEBUG(21605, + 2, + "Record count of {nss_ns} ({uuid}) before rollback is {oldCount}. Setting it " + "to {newCount}, due to change of {countDiff}", + "nss_ns"_attr = nss->ns(), + "uuid"_attr = uuid.toString(), + "oldCount"_attr = oldCount, + "newCount"_attr = newCount, + "countDiff"_attr = countDiff); _newCounts[uuid] = newCount; } @@ -774,15 +837,17 @@ Status RollbackImpl::_processRollbackOp(OperationContext* opCtx, const OplogEntr idVal == ShardIdentityType::IdName) { // Check if the creation of the shard identity document is being rolled back. _observerInfo.shardIdentityRolledBack = true; - warning() << "Shard identity document rollback detected. oplog op: " - << redact(oplogEntry.toBSON()); + LOGV2_WARNING(21641, + "Shard identity document rollback detected. oplog op: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry.toBSON())); } else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer && opNss == VersionType::ConfigNS) { // Check if the creation of the config server config version document is being rolled // back. _observerInfo.configServerConfigVersionRolledBack = true; - warning() << "Config version document rollback detected. oplog op: " - << redact(oplogEntry.toBSON()); + LOGV2_WARNING(21642, + "Config version document rollback detected. oplog op: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry.toBSON())); } // Rolling back an insert must decrement the count by 1. @@ -902,7 +967,7 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down"); } - log() << "finding common point"; + LOGV2(21606, "finding common point"); // We save some aggregate information about all operations that are rolled back, so that we can // pass this information to the rollback op observer. In most cases, other subsystems do not @@ -934,7 +999,9 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm auto stableTimestamp = _storageInterface->getLastStableRecoveryTimestamp(opCtx->getServiceContext()); - log() << "Rollback common point is " << commonPointOpTime; + LOGV2(21607, + "Rollback common point is {commonPointOpTime}", + "commonPointOpTime"_attr = commonPointOpTime); // Rollback common point should be >= the replication commit point. invariant(commonPointOpTime.getTimestamp() >= lastCommittedOpTime.getTimestamp()); @@ -949,8 +1016,11 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm if (commonPointOpTime.getTimestamp() < *stableTimestamp) { // This is an fassert rather than an invariant, since it can happen if the server was // recently upgraded to enableMajorityReadConcern=true. - severe() << "Common point must be at least stable timestamp, common point: " - << commonPointOpTime.getTimestamp() << ", stable timestamp: " << *stableTimestamp; + LOGV2_FATAL(21644, + "Common point must be at least stable timestamp, common point: " + "{commonPointOpTime_getTimestamp}, stable timestamp: {stableTimestamp}", + "commonPointOpTime_getTimestamp"_attr = commonPointOpTime.getTimestamp(), + "stableTimestamp"_attr = *stableTimestamp); fassertFailedNoTrace(51121); } @@ -996,11 +1066,13 @@ Status RollbackImpl::_checkAgainstTimeLimit( } } else { - warning() - << "Wall clock times on oplog entries not monotonically increasing. This " - "might indicate a backward clock skew. Time at first oplog after common point: " - << firstOpWallClockTimeAfterCommonPoint - << ". Time at top of oplog: " << topOfOplogWallTime; + LOGV2_WARNING( + 21643, + "Wall clock times on oplog entries not monotonically increasing. This " + "might indicate a backward clock skew. Time at first oplog after common point: " + "{firstOpWallClockTimeAfterCommonPoint}. Time at top of oplog: {topOfOplogWallTime}", + "firstOpWallClockTimeAfterCommonPoint"_attr = firstOpWallClockTimeAfterCommonPoint, + "topOfOplogWallTime"_attr = topOfOplogWallTime); } return Status::OK(); @@ -1016,8 +1088,13 @@ boost::optional<BSONObj> RollbackImpl::_findDocumentById(OperationContext* opCtx } else if (document.getStatus().code() == ErrorCodes::NoSuchKey) { return boost::none; } else { - severe() << "Rollback failed to read document with " << redact(id) << " in namespace " - << nss.ns() << " with uuid " << uuid.toString() << causedBy(document.getStatus()); + LOGV2_FATAL(21645, + "Rollback failed to read document with {id} in namespace {nss_ns} with uuid " + "{uuid}{causedBy_document_getStatus}", + "id"_attr = redact(id), + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "causedBy_document_getStatus"_attr = causedBy(document.getStatus())); fassert(50751, document.getStatus()); } @@ -1034,10 +1111,12 @@ Status RollbackImpl::_writeRollbackFiles(OperationContext* opCtx) { // Drop-pending collections are not visible to rollback via the catalog when they are // managed by the storage engine. See StorageEngine::supportsPendingDrops(). if (!nss && storageEngine->supportsPendingDrops()) { - log() << "The collection with UUID " << uuid - << " is missing in the CollectionCatalog. This could be due to a dropped " - " collection. Not writing rollback file for uuid " - << uuid; + LOGV2(21608, + "The collection with UUID {uuid} is missing in the CollectionCatalog. This could " + "be due to a dropped " + " collection. Not writing rollback file for uuid {uuid2}", + "uuid"_attr = uuid, + "uuid2"_attr = uuid); continue; } @@ -1056,8 +1135,12 @@ void RollbackImpl::_writeRollbackFileForNamespace(OperationContext* opCtx, NamespaceString nss, const SimpleBSONObjUnorderedSet& idSet) { RemoveSaver removeSaver(kRollbackRemoveSaverType, uuid.toString(), kRollbackRemoveSaverWhy); - log() << "Preparing to write deleted documents to a rollback file for collection " << nss.ns() - << " with uuid " << uuid.toString() << " to " << removeSaver.file().generic_string(); + LOGV2(21609, + "Preparing to write deleted documents to a rollback file for collection {nss_ns} with " + "uuid {uuid} to {removeSaver_file_generic_string}", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid.toString(), + "removeSaver_file_generic_string"_attr = removeSaver.file().generic_string()); // The RemoveSaver will save the data files in a directory structure similar to the following: // @@ -1106,7 +1189,7 @@ Status RollbackImpl::_triggerOpObserver(OperationContext* opCtx) { if (_isInShutdown()) { return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down"); } - log() << "Triggering the rollback op observer"; + LOGV2(21610, "Triggering the rollback op observer"); opCtx->getServiceContext()->getOpObserver()->onReplicationRollback(opCtx, _observerInfo); return Status::OK(); } @@ -1115,16 +1198,22 @@ void RollbackImpl::_transitionFromRollbackToSecondary(OperationContext* opCtx) { invariant(opCtx); invariant(_replicationCoordinator->getMemberState() == MemberState(MemberState::RS_ROLLBACK)); - log() << "transition to SECONDARY"; + LOGV2(21611, "transition to SECONDARY"); ReplicationStateTransitionLockGuard transitionGuard(opCtx, MODE_X); auto status = _replicationCoordinator->setFollowerMode(MemberState::RS_SECONDARY); if (!status.isOK()) { - severe() << "Failed to transition into " << MemberState(MemberState::RS_SECONDARY) - << "; expected to be in state " << MemberState(MemberState::RS_ROLLBACK) - << "; found self in " << _replicationCoordinator->getMemberState() - << causedBy(status); + LOGV2_FATAL( + 21646, + "Failed to transition into {MemberState_MemberState_RS_SECONDARY}; expected to be in " + "state {MemberState_MemberState_RS_ROLLBACK}; found self in " + "{replicationCoordinator_getMemberState}{causedBy_status}", + "MemberState_MemberState_RS_SECONDARY"_attr = MemberState(MemberState::RS_SECONDARY), + "MemberState_MemberState_RS_ROLLBACK"_attr = MemberState(MemberState::RS_ROLLBACK), + "replicationCoordinator_getMemberState"_attr = + _replicationCoordinator->getMemberState(), + "causedBy_status"_attr = causedBy(status)); fassertFailedNoTrace(40408); } } @@ -1150,21 +1239,36 @@ void RollbackImpl::_resetDropPendingState(OperationContext* opCtx) { } void RollbackImpl::_summarizeRollback(OperationContext* opCtx) const { - log() << "Rollback summary:"; - log() << "\tstart time: " << _rollbackStats.startTime; - log() << "\tend time: " << opCtx->getServiceContext()->getFastClockSource()->now(); - log() << "\tsync source: " << _remoteOplog->hostAndPort().toString(); - log() << "\trollback data file directory: " - << _rollbackStats.rollbackDataFileDirectory.value_or("none; no files written"); + LOGV2(21612, "Rollback summary:"); + LOGV2(21613, + "\tstart time: {rollbackStats_startTime}", + "rollbackStats_startTime"_attr = _rollbackStats.startTime); + LOGV2(21614, + "\tend time: {opCtx_getServiceContext_getFastClockSource_now}", + "opCtx_getServiceContext_getFastClockSource_now"_attr = + opCtx->getServiceContext()->getFastClockSource()->now()); + LOGV2(21615, + "\tsync source: {remoteOplog_hostAndPort}", + "remoteOplog_hostAndPort"_attr = _remoteOplog->hostAndPort().toString()); + LOGV2(21616, + "\trollback data file directory: " + "{rollbackStats_rollbackDataFileDirectory_value_or_none_no_files_written}", + "rollbackStats_rollbackDataFileDirectory_value_or_none_no_files_written"_attr = + _rollbackStats.rollbackDataFileDirectory.value_or("none; no files written")); if (_rollbackStats.rollbackId) { - log() << "\trollback id: " << *_rollbackStats.rollbackId; + LOGV2(21617, + "\trollback id: {rollbackStats_rollbackId}", + "rollbackStats_rollbackId"_attr = *_rollbackStats.rollbackId); } if (_rollbackStats.lastLocalOptime) { - log() << "\tlast optime on branch of history rolled back: " - << *_rollbackStats.lastLocalOptime; + LOGV2(21618, + "\tlast optime on branch of history rolled back: {rollbackStats_lastLocalOptime}", + "rollbackStats_lastLocalOptime"_attr = *_rollbackStats.lastLocalOptime); } if (_rollbackStats.commonPoint) { - log() << "\tcommon point optime: " << *_rollbackStats.commonPoint; + LOGV2(21619, + "\tcommon point optime: {rollbackStats_commonPoint}", + "rollbackStats_commonPoint"_attr = *_rollbackStats.commonPoint); } if (_rollbackStats.lastLocalWallClockTime && _rollbackStats.firstOpWallClockTimeAfterCommonPoint) { @@ -1175,36 +1279,62 @@ void RollbackImpl::_summarizeRollback(OperationContext* opCtx) const { unsigned long long diff = durationCount<Seconds>(Milliseconds(lastWall - firstOpWallClockTimeAfterCommonPoint)); - log() << "\tlast wall clock time on the branch of history rolled back: " << lastWall; - log() << "\twall clock time of the first operation after the common point: " - << firstOpWallClockTimeAfterCommonPoint; - log() << "\tdifference in wall clock times: " << diff << " second(s)"; + LOGV2(21620, + "\tlast wall clock time on the branch of history rolled back: {lastWall}", + "lastWall"_attr = lastWall); + LOGV2(21621, + "\twall clock time of the first operation after the common point: " + "{firstOpWallClockTimeAfterCommonPoint}", + "firstOpWallClockTimeAfterCommonPoint"_attr = firstOpWallClockTimeAfterCommonPoint); + LOGV2(21622, "\tdifference in wall clock times: {diff} second(s)", "diff"_attr = diff); } if (_rollbackStats.truncateTimestamp) { - log() << "\ttruncate timestamp: " << *_rollbackStats.truncateTimestamp; + LOGV2(21623, + "\ttruncate timestamp: {rollbackStats_truncateTimestamp}", + "rollbackStats_truncateTimestamp"_attr = *_rollbackStats.truncateTimestamp); } if (_rollbackStats.stableTimestamp) { - log() << "\tstable timestamp: " << *_rollbackStats.stableTimestamp; + LOGV2(21624, + "\tstable timestamp: {rollbackStats_stableTimestamp}", + "rollbackStats_stableTimestamp"_attr = *_rollbackStats.stableTimestamp); } - log() << "\tshard identity document rolled back: " << std::boolalpha - << _observerInfo.shardIdentityRolledBack; - log() << "\tconfig server config version document rolled back: " << std::boolalpha - << _observerInfo.configServerConfigVersionRolledBack; - log() << "\taffected sessions: " << (_observerInfo.rollbackSessionIds.empty() ? "none" : ""); + LOGV2(21625, + "\tshard identity document rolled back: {observerInfo_shardIdentityRolledBack}", + "observerInfo_shardIdentityRolledBack"_attr = _observerInfo.shardIdentityRolledBack); + LOGV2(21626, + "\tconfig server config version document rolled back: " + "{observerInfo_configServerConfigVersionRolledBack}", + "observerInfo_configServerConfigVersionRolledBack"_attr = + _observerInfo.configServerConfigVersionRolledBack); + LOGV2(21627, + "\taffected sessions: {observerInfo_rollbackSessionIds_empty_none}", + "observerInfo_rollbackSessionIds_empty_none"_attr = + (_observerInfo.rollbackSessionIds.empty() ? "none" : "")); for (const auto& sessionId : _observerInfo.rollbackSessionIds) { - log() << "\t\t" << sessionId; + LOGV2(21628, "\t\t{sessionId}", "sessionId"_attr = sessionId); } - log() << "\taffected namespaces: " << (_observerInfo.rollbackNamespaces.empty() ? "none" : ""); + LOGV2(21629, + "\taffected namespaces: {observerInfo_rollbackNamespaces_empty_none}", + "observerInfo_rollbackNamespaces_empty_none"_attr = + (_observerInfo.rollbackNamespaces.empty() ? "none" : "")); for (const auto& nss : _observerInfo.rollbackNamespaces) { - log() << "\t\t" << nss.ns(); + LOGV2(21630, "\t\t{nss_ns}", "nss_ns"_attr = nss.ns()); } - log() << "\tcounts of interesting commands rolled back: " - << (_observerInfo.rollbackCommandCounts.empty() ? "none" : ""); + LOGV2(21631, + "\tcounts of interesting commands rolled back: " + "{observerInfo_rollbackCommandCounts_empty_none}", + "observerInfo_rollbackCommandCounts_empty_none"_attr = + (_observerInfo.rollbackCommandCounts.empty() ? "none" : "")); for (const auto& entry : _observerInfo.rollbackCommandCounts) { - log() << "\t\t" << entry.first << ": " << entry.second; + LOGV2(21632, + "\t\t{entry_first}: {entry_second}", + "entry_first"_attr = entry.first, + "entry_second"_attr = entry.second); } - log() << "\ttotal number of entries rolled back (including no-ops): " - << _observerInfo.numberOfEntriesObserved; + LOGV2(21633, + "\ttotal number of entries rolled back (including no-ops): " + "{observerInfo_numberOfEntriesObserved}", + "observerInfo_numberOfEntriesObserved"_attr = _observerInfo.numberOfEntriesObserved); } } // namespace repl diff --git a/src/mongo/db/repl/rollback_impl_test.cpp b/src/mongo/db/repl/rollback_impl_test.cpp index e33b10f60cc..fa5b5af0a96 100644 --- a/src/mongo/db/repl/rollback_impl_test.cpp +++ b/src/mongo/db/repl/rollback_impl_test.cpp @@ -48,6 +48,7 @@ #include "mongo/db/s/shard_identity_rollback_notifier.h" #include "mongo/db/s/type_shard_identity.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_config_version.h" #include "mongo/stdx/thread.h" #include "mongo/transport/session.h" @@ -113,10 +114,15 @@ protected: UUID uuid, NamespaceString nss, const SimpleBSONObjUnorderedSet& idSet) final { - log() << "Simulating writing a rollback file for namespace " << nss.ns() << " with uuid " - << uuid; + LOGV2(21647, + "Simulating writing a rollback file for namespace {nss_ns} with uuid {uuid}", + "nss_ns"_attr = nss.ns(), + "uuid"_attr = uuid); for (auto&& id : idSet) { - log() << "Looking up " << id.jsonString(JsonStringFormat::LegacyStrict); + LOGV2(21648, + "Looking up {id_jsonString_JsonStringFormat_LegacyStrict}", + "id_jsonString_JsonStringFormat_LegacyStrict"_attr = + id.jsonString(JsonStringFormat::LegacyStrict)); auto document = _findDocumentById(opCtx, uuid, nss, id.firstElement()); if (document) { _uuidToObjsMap[uuid].push_back(*document); @@ -531,12 +537,12 @@ TEST_F(RollbackImplTest, RollbackKillsNecessaryOperations) { } // We assume that an interrupted opCtx would release its locks. - unittest::log() << "Both opCtx's marked for kill"; + LOGV2(21649, "Both opCtx's marked for kill"); ASSERT_EQ(ErrorCodes::InterruptedDueToReplStateChange, writeOpCtx->checkForInterruptNoAssert()); globalWrite = boost::none; ASSERT_EQ(ErrorCodes::InterruptedDueToReplStateChange, readOpCtx->checkForInterruptNoAssert()); globalRead = boost::none; - unittest::log() << "Both opCtx's were interrupted"; + LOGV2(21650, "Both opCtx's were interrupted"); rollbackThread.join(); ASSERT_OK(status); @@ -879,7 +885,7 @@ DEATH_TEST_F(RollbackImplTest, _storageInterface->setStableTimestamp(nullptr, Timestamp(1, 1)); auto status = _rollback->runRollback(_opCtx.get()); - unittest::log() << "Mongod did not crash. Status: " << status; + LOGV2(21651, "Mongod did not crash. Status: {status}", "status"_attr = status); MONGO_UNREACHABLE; } @@ -1234,7 +1240,7 @@ DEATH_TEST_F(RollbackImplTest, } auto status = _rollback->runRollback(_opCtx.get()); - unittest::log() << "mongod did not crash when expected; status: " << status; + LOGV2(21652, "mongod did not crash when expected; status: {status}", "status"_attr = status); } DEATH_TEST_F(RollbackImplTest, @@ -1248,7 +1254,7 @@ DEATH_TEST_F(RollbackImplTest, _storageInterface->setStableTimestamp(nullptr, Timestamp(1, 1)); auto status = _rollback->runRollback(_opCtx.get()); - unittest::log() << "mongod did not crash when expected; status: " << status; + LOGV2(21653, "mongod did not crash when expected; status: {status}", "status"_attr = status); } TEST_F(RollbackImplTest, RollbackSetsMultipleCollectionCounts) { @@ -1753,7 +1759,9 @@ DEATH_TEST_F(RollbackImplObserverInfoTest, Timestamp(2, 2), boost::none, "admin.$cmd", BSON("applyOps" << subops.arr()), 2); auto status = _rollback->_namespacesForOp_forTest(OplogEntry(applyOpsCmdOp.first)); - unittest::log() << "Mongod did not crash. Status: " << status.getStatus(); + LOGV2(21654, + "Mongod did not crash. Status: {status_getStatus}", + "status_getStatus"_attr = status.getStatus()); MONGO_UNREACHABLE; } @@ -1855,7 +1863,7 @@ DEATH_TEST_F(RollbackImplObserverInfoTest, ASSERT_OK(_insertOplogEntry(unknownCmdOp.first)); auto status = _rollback->runRollback(_opCtx.get()); - unittest::log() << "Mongod did not crash. Status: " << status; + LOGV2(21655, "Mongod did not crash. Status: {status}", "status"_attr = status); MONGO_UNREACHABLE; } diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 647247a228c..aad64b6db3c 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -77,6 +77,7 @@ #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/remove_saver.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/util/exit.h" @@ -134,9 +135,12 @@ void FixUpInfo::removeRedundantOperations() { } bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) { - LOG(2) << "Attempting to remove redundant index operations from the set of indexes to create " - "for collection " - << uuid << ", for index '" << indexName << "'"; + LOGV2_DEBUG(21659, + 2, + "Attempting to remove redundant index operations from the set of indexes to create " + "for collection {uuid}, for index '{indexName}'", + "uuid"_attr = uuid, + "indexName"_attr = indexName); // See if there are any indexes to create for this collection. auto indexes = indexesToCreate.find(uuid); @@ -144,10 +148,12 @@ bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) { // There are no indexes to create for this collection UUID, so there are no index creation // operations to remove. if (indexes == indexesToCreate.end()) { - LOG(2) - << "Collection " << uuid - << " has no indexes to create. Not removing any index creation operations for index '" - << indexName << "'."; + LOGV2_DEBUG(21660, + 2, + "Collection {uuid} has no indexes to create. Not removing any index creation " + "operations for index '{indexName}'.", + "uuid"_attr = uuid, + "indexName"_attr = indexName); return false; } @@ -158,15 +164,23 @@ bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) { // If this index was not previously added to the set of indexes that need to be created for this // collection, then we do nothing. if (indexesToCreateForColl->find(indexName) == indexesToCreateForColl->end()) { - LOG(2) << "Index '" << indexName << "' was not previously set to be created for collection " - << uuid << ". Not removing any index creation operations."; + LOGV2_DEBUG(21661, + 2, + "Index '{indexName}' was not previously set to be created for collection " + "{uuid}. Not removing any index creation operations.", + "indexName"_attr = indexName, + "uuid"_attr = uuid); return false; } // This index was previously added to the set of indexes to create for this collection, so we // remove it from that set. - LOG(2) << "Index '" << indexName << "' was previously set to be created for collection " << uuid - << ". Removing this redundant index creation operation."; + LOGV2_DEBUG(21662, + 2, + "Index '{indexName}' was previously set to be created for collection {uuid}. " + "Removing this redundant index creation operation.", + "indexName"_attr = indexName, + "uuid"_attr = uuid); indexesToCreateForColl->erase(indexName); // If there are now no remaining indexes to create for this collection, remove it from // the set of collections that we need to create indexes for. @@ -206,7 +220,7 @@ Status FixUpInfo::recordDropTargetInfo(const BSONElement& dropTarget, << "Unable to roll back renameCollection. Cannot parse " "dropTarget UUID. Returned status: " << redact(dropTargetUUIDStatus.getStatus()) << ", oplog entry: " << redact(obj); - error() << message; + LOGV2_ERROR(21729, "{message}", "message"_attr = message); return dropTargetUUIDStatus.getStatus(); } UUID dropTargetUUID = dropTargetUUIDStatus.getValue(); @@ -253,8 +267,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o const OplogEntry oplogEntry(fixedObj); if (isNestedApplyOpsCommand) { - LOG(2) << "Updating rollback FixUpInfo for nested applyOps oplog entry: " - << redact(oplogEntry.toBSON()); + LOGV2_DEBUG(21663, + 2, + "Updating rollback FixUpInfo for nested applyOps oplog entry: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry.toBSON())); } // Extract the op's collection namespace and UUID. @@ -371,9 +387,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o string indexName; auto status = bsonExtractStringField(obj, "index", &indexName); if (!status.isOK()) { - severe() - << "Missing index name in dropIndexes operation on rollback, document: " - << redact(oplogEntry.toBSON()); + LOGV2_FATAL(21731, + "Missing index name in dropIndexes operation on rollback, " + "document: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry.toBSON())); throw RSFatalException( "Missing index name in dropIndexes operation on rollback."); } @@ -409,9 +426,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o string indexName; auto status = bsonExtractStringField(obj, "name", &indexName); if (!status.isOK()) { - severe() - << "Missing index name in createIndexes operation on rollback, document: " - << redact(oplogEntry.toBSON()); + LOGV2_FATAL(21732, + "Missing index name in createIndexes operation on rollback, " + "document: {oplogEntry}", + "oplogEntry"_attr = redact(oplogEntry.toBSON())); throw RSFatalException( "Missing index name in createIndexes operation on rollback."); } @@ -457,9 +475,12 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o auto buildUUID = indexBuildOplogEntry.buildUUID; auto existingIt = buildsToRestart.find(buildUUID); if (existingIt != buildsToRestart.end()) { - LOG(2) << "Index build that was previously marked to be restarted will now be " - "dropped due to a rolled-back 'startIndexBuild' oplog entry: " - << buildUUID; + LOGV2_DEBUG( + 21664, + 2, + "Index build that was previously marked to be restarted will now be " + "dropped due to a rolled-back 'startIndexBuild' oplog entry: {buildUUID}", + "buildUUID"_attr = buildUUID); buildsToRestart.erase(existingIt); // If the index build was committed or aborted, we must mark the index as @@ -500,8 +521,11 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o "UUID is already marked to be restarted: " << buildUUID); - LOG(2) << "Index build will be restarted after a rolled-back 'abortIndexBuild': " - << buildUUID; + LOGV2_DEBUG(21665, + 2, + "Index build will be restarted after a rolled-back 'abortIndexBuild': " + "{buildUUID}", + "buildUUID"_attr = buildUUID); IndexBuildDetails details{*uuid}; for (auto& spec : indexBuildOplogEntry.indexSpecs) { invariant(spec.isOwned()); @@ -542,8 +566,11 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o "UUID is already marked to be restarted: " << buildUUID); - LOG(2) << "Index build will be restarted after a rolled-back 'commitIndexBuild': " - << buildUUID; + LOGV2_DEBUG(21666, + 2, + "Index build will be restarted after a rolled-back 'commitIndexBuild': " + "{buildUUID}", + "buildUUID"_attr = buildUUID); IndexBuildDetails details{*uuid}; for (auto& spec : indexBuildOplogEntry.indexSpecs) { @@ -571,7 +598,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o if (ns.empty()) { std::string message = str::stream() << "Collection name missing from oplog entry: " << redact(obj); - log() << message; + LOGV2(21667, "{message}", "message"_attr = message); return Status(ErrorCodes::UnrecoverableRollbackError, message); } @@ -650,7 +677,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o } // Some collMod fields cannot be rolled back, such as the index field. string message = "Cannot roll back a collMod command: "; - severe() << message << redact(obj); + LOGV2_FATAL(21733, + "{message}{obj}", + "message"_attr = message, + "obj"_attr = redact(obj)); throw RSFatalException(message); } return Status::OK(); @@ -687,7 +717,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o std::string message = str::stream() << "Expected applyOps argument to be an array; found " << redact(operations); - severe() << message; + LOGV2_FATAL(21734, "{message}", "message"_attr = message); return Status(ErrorCodes::UnrecoverableRollbackError, message); } for (const auto& subopElement : operations.Array()) { @@ -695,7 +725,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o std::string message = str::stream() << "Expected applyOps operations to be of Object type, but found " << redact(subopElement); - severe() << message; + LOGV2_FATAL(21735, "{message}", "message"_attr = message); return Status(ErrorCodes::UnrecoverableRollbackError, message); } // In applyOps, the object contains an array of different oplog entries, we @@ -729,7 +759,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o default: { std::string message = str::stream() << "Can't roll back this command yet: " << " cmdname = " << first.fieldName(); - severe() << message << " document: " << redact(obj); + LOGV2_FATAL(21736, + "{message} document: {obj}", + "message"_attr = message, + "obj"_attr = redact(obj)); throw RSFatalException(message); } } @@ -742,7 +775,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o doc._id = oplogEntry.getIdElement(); if (doc._id.eoo()) { std::string message = str::stream() << "Cannot roll back op with no _id. ns: " << nss.ns(); - severe() << message << ", document: " << redact(oplogEntry.toBSON()); + LOGV2_FATAL(21737, + "{message}, document: {oplogEntry}", + "message"_attr = message, + "oplogEntry"_attr = redact(oplogEntry.toBSON())); throw RSFatalException(message); } fixUpInfo.docsToRefetch.insert(doc); @@ -779,7 +815,7 @@ void checkRbidAndUpdateMinValid(OperationContext* opCtx, // RECOVERING state to SECONDARY state until we have reached the minValid oplog entry. OpTime minValid = fassert(40492, OpTime::parseFromOplogEntry(newMinValidDoc)); - log() << "Setting minvalid to " << minValid; + LOGV2(21668, "Setting minvalid to {minValid}", "minValid"_attr = minValid); // This method is only used with storage engines that do not support recover to stable // timestamp. As a result, the timestamp on the 'appliedThrough' update does not matter. @@ -790,8 +826,9 @@ void checkRbidAndUpdateMinValid(OperationContext* opCtx, if (MONGO_unlikely(rollbackHangThenFailAfterWritingMinValid.shouldFail())) { // This log output is used in jstests so please leave it. - log() << "rollback - rollbackHangThenFailAfterWritingMinValid fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21669, + "rollback - rollbackHangThenFailAfterWritingMinValid fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(rollbackHangThenFailAfterWritingMinValid.shouldFail())) { invariant(!globalInShutdownDeprecated()); // It is an error to shutdown while enabled. mongo::sleepsecs(1); @@ -813,8 +850,10 @@ void dropIndex(OperationContext* opCtx, auto indexDescriptor = indexCatalog->findIndexByName(opCtx, indexName, includeUnfinishedIndexes); if (!indexDescriptor) { - warning() << "Rollback failed to drop index " << indexName << " in " << nss.toString() - << ": index not found."; + LOGV2_WARNING(21725, + "Rollback failed to drop index {indexName} in {nss}: index not found.", + "indexName"_attr = indexName, + "nss"_attr = nss.toString()); return; } WriteUnitOfWork wunit(opCtx); @@ -822,14 +861,20 @@ void dropIndex(OperationContext* opCtx, if (entry->isReady(opCtx)) { auto status = indexCatalog->dropIndex(opCtx, indexDescriptor); if (!status.isOK()) { - severe() << "Rollback failed to drop index " << indexName << " in " << nss.toString() - << ": " << redact(status); + LOGV2_FATAL(21738, + "Rollback failed to drop index {indexName} in {nss}: {status}", + "indexName"_attr = indexName, + "nss"_attr = nss.toString(), + "status"_attr = redact(status)); } } else { auto status = indexCatalog->dropUnfinishedIndex(opCtx, indexDescriptor); if (!status.isOK()) { - severe() << "Rollback failed to drop unfinished index " << indexName << " in " - << nss.toString() << ": " << redact(status); + LOGV2_FATAL(21739, + "Rollback failed to drop unfinished index {indexName} in {nss}: {status}", + "indexName"_attr = indexName, + "nss"_attr = nss.toString(), + "status"_attr = redact(status)); } } wunit.commit(); @@ -849,29 +894,43 @@ void rollbackCreateIndexes(OperationContext* opCtx, UUID uuid, std::set<std::str // If we cannot find the collection, we skip over dropping the index. if (!collection) { - LOG(2) << "Cannot find the collection with uuid: " << uuid.toString() - << " in CollectionCatalog during roll back of a createIndexes command."; + LOGV2_DEBUG(21670, + 2, + "Cannot find the collection with uuid: {uuid} in CollectionCatalog during roll " + "back of a createIndexes command.", + "uuid"_attr = uuid.toString()); return; } // If we cannot find the index catalog, we skip over dropping the index. auto indexCatalog = collection->getIndexCatalog(); if (!indexCatalog) { - LOG(2) << "Cannot find the index catalog in collection with uuid: " << uuid.toString() - << " during roll back of a createIndexes command."; + LOGV2_DEBUG(21671, + 2, + "Cannot find the index catalog in collection with uuid: {uuid} during roll " + "back of a createIndexes command.", + "uuid"_attr = uuid.toString()); return; } for (auto itIndex = indexNames.begin(); itIndex != indexNames.end(); itIndex++) { const string& indexName = *itIndex; - log() << "Dropping index in rollback for collection: " << *nss << ", UUID: " << uuid - << ", index: " << indexName; + LOGV2(21672, + "Dropping index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "indexName"_attr = indexName); dropIndex(opCtx, indexCatalog, indexName, *nss); - LOG(1) << "Dropped index in rollback for collection: " << *nss << ", UUID: " << uuid - << ", index: " << indexName; + LOGV2_DEBUG( + 21673, + 1, + "Dropped index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "indexName"_attr = indexName); } } @@ -891,8 +950,11 @@ void rollbackDropIndexes(OperationContext* opCtx, // If we cannot find the collection, we skip over dropping the index. if (!collection) { - LOG(2) << "Cannot find the collection with uuid: " << uuid.toString() - << "in CollectionCatalog during roll back of a dropIndexes command."; + LOGV2_DEBUG(21674, + 2, + "Cannot find the collection with uuid: {uuid}in CollectionCatalog during roll " + "back of a dropIndexes command.", + "uuid"_attr = uuid.toString()); return; } @@ -900,13 +962,21 @@ void rollbackDropIndexes(OperationContext* opCtx, const string indexName = itIndex->first; BSONObj indexSpec = itIndex->second; - log() << "Creating index in rollback for collection: " << *nss << ", UUID: " << uuid - << ", index: " << indexName; + LOGV2(21675, + "Creating index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "indexName"_attr = indexName); createIndexForApplyOps(opCtx, indexSpec, *nss, OplogApplication::Mode::kRecovering); - LOG(1) << "Created index in rollback for collection: " << *nss << ", UUID: " << uuid - << ", index: " << indexName; + LOGV2_DEBUG( + 21676, + 1, + "Created index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "indexName"_attr = indexName); } } @@ -919,10 +989,14 @@ void dropCollection(OperationContext* opCtx, Database* db) { if (RollbackImpl::shouldCreateDataFiles()) { RemoveSaver removeSaver("rollback", "", collection->uuid().toString()); - log() << "Rolling back createCollection on " << nss - << ": Preparing to write documents to a rollback file for a collection " << nss - << " with uuid " << collection->uuid() << " to " - << removeSaver.file().generic_string(); + LOGV2(21677, + "Rolling back createCollection on {nss}: Preparing to write documents to a rollback " + "file for a collection {nss2} with uuid {collection_uuid} to " + "{removeSaver_file_generic_string}", + "nss"_attr = nss, + "nss2"_attr = nss, + "collection_uuid"_attr = collection->uuid(), + "removeSaver_file_generic_string"_attr = removeSaver.file().generic_string()); // Performs a collection scan and writes all documents in the collection to disk // in order to keep an archive of items that were rolled back. @@ -933,8 +1007,11 @@ void dropCollection(OperationContext* opCtx, while (PlanExecutor::ADVANCED == (execState = exec->getNext(&curObj, nullptr))) { auto status = removeSaver.goingToDelete(curObj); if (!status.isOK()) { - severe() << "Rolling back createCollection on " << nss - << " failed to write document to remove saver file: " << redact(status); + LOGV2_FATAL(21740, + "Rolling back createCollection on {nss} failed to write document to " + "remove saver file: {status}", + "nss"_attr = nss, + "status"_attr = redact(status)); throw RSFatalException( "Rolling back createCollection. Failed to write document to remove saver " "file."); @@ -951,13 +1028,18 @@ void dropCollection(OperationContext* opCtx, if (execState == PlanExecutor::FAILURE && WorkingSetCommon::isValidStatusMemberObject(curObj)) { Status errorStatus = WorkingSetCommon::getMemberObjectStatus(curObj); - severe() << "Rolling back createCollection on " << nss << " failed with " - << redact(errorStatus) << ". A full resync is necessary."; + LOGV2_FATAL(21741, + "Rolling back createCollection on {nss} failed with {errorStatus}. A " + "full resync is necessary.", + "nss"_attr = nss, + "errorStatus"_attr = redact(errorStatus)); throw RSFatalException( "Rolling back createCollection failed. A full resync is necessary."); } else { - severe() << "Rolling back createCollection on " << nss - << " failed. A full resync is necessary."; + LOGV2_FATAL( + 21742, + "Rolling back createCollection on {nss} failed. A full resync is necessary.", + "nss"_attr = nss); throw RSFatalException( "Rolling back createCollection failed. A full resync is necessary."); } @@ -992,17 +1074,27 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab // namespace. auto tmpNameResult = db->makeUniqueCollectionNamespace(opCtx, "rollback.tmp%%%%%"); if (!tmpNameResult.isOK()) { - severe() << "Unable to generate temporary namespace to rename collection " << info.renameTo - << " out of the way. " << tmpNameResult.getStatus().reason(); + LOGV2_FATAL(21743, + "Unable to generate temporary namespace to rename collection {info_renameTo} " + "out of the way. {tmpNameResult_getStatus_reason}", + "info_renameTo"_attr = info.renameTo, + "tmpNameResult_getStatus_reason"_attr = tmpNameResult.getStatus().reason()); throw RSFatalException( "Unable to generate temporary namespace to rename collection out of the way."); } const auto& tempNss = tmpNameResult.getValue(); - LOG(2) << "Attempted to rename collection from " << info.renameFrom << " to " << info.renameTo - << " but " << info.renameTo << " exists already. Temporarily renaming collection " - << info.renameTo << " with UUID " << collection->uuid() << " out of the way to " - << tempNss; + LOGV2_DEBUG(21678, + 2, + "Attempted to rename collection from {info_renameFrom} to {info_renameTo} but " + "{info_renameTo2} exists already. Temporarily renaming collection {info_renameTo3} " + "with UUID {collection_uuid} out of the way to {tempNss}", + "info_renameFrom"_attr = info.renameFrom, + "info_renameTo"_attr = info.renameTo, + "info_renameTo2"_attr = info.renameTo, + "info_renameTo3"_attr = info.renameTo, + "collection_uuid"_attr = collection->uuid(), + "tempNss"_attr = tempNss); // Renaming the collection that was clashing with the attempted rename // operation to a different collection name. @@ -1010,8 +1102,10 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab auto renameStatus = renameCollectionForRollback(opCtx, tempNss, uuid); if (!renameStatus.isOK()) { - severe() << "Unable to rename collection " << info.renameTo << " out of the way to " - << tempNss; + LOGV2_FATAL(21744, + "Unable to rename collection {info_renameTo} out of the way to {tempNss}", + "info_renameTo"_attr = info.renameTo, + "tempNss"_attr = tempNss); throw RSFatalException("Unable to rename collection out of the way"); } } @@ -1023,8 +1117,12 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti auto dbName = info.renameFrom.db(); - log() << "Attempting to rename collection with UUID: " << uuid << ", from: " << info.renameFrom - << ", to: " << info.renameTo; + LOGV2(21679, + "Attempting to rename collection with UUID: {uuid}, from: {info_renameFrom}, to: " + "{info_renameTo}", + "uuid"_attr = uuid, + "info_renameFrom"_attr = info.renameFrom, + "info_renameTo"_attr = info.renameTo); Lock::DBLock dbLock(opCtx, dbName, MODE_X); auto databaseHolder = DatabaseHolder::get(opCtx); auto db = databaseHolder->openDb(opCtx, dbName); @@ -1044,20 +1142,30 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti status = renameCollectionForRollback(opCtx, info.renameTo, uuid); if (!status.isOK()) { - severe() << "Rename collection failed to roll back twice. We were unable to rename " - << "collection " << info.renameFrom << " to " << info.renameTo << ". " - << status.toString(); + LOGV2_FATAL(21745, + "Rename collection failed to roll back twice. We were unable to rename " + "collection {info_renameFrom} to {info_renameTo}. {status}", + "info_renameFrom"_attr = info.renameFrom, + "info_renameTo"_attr = info.renameTo, + "status"_attr = status.toString()); throw RSFatalException( "Rename collection failed to roll back twice. We were unable to rename " "the collection."); } } else if (!status.isOK()) { - severe() << "Unable to roll back renameCollection command: " << status.toString(); + LOGV2_FATAL(21746, + "Unable to roll back renameCollection command: {status}", + "status"_attr = status.toString()); throw RSFatalException("Unable to rollback renameCollection command"); } - LOG(1) << "Renamed collection with UUID: " << uuid << ", from: " << info.renameFrom - << ", to: " << info.renameTo; + LOGV2_DEBUG( + 21680, + 1, + "Renamed collection with UUID: {uuid}, from: {info_renameFrom}, to: {info_renameTo}", + "uuid"_attr = uuid, + "info_renameFrom"_attr = info.renameFrom, + "info_renameTo"_attr = info.renameTo); } Status _syncRollback(OperationContext* opCtx, @@ -1071,7 +1179,10 @@ Status _syncRollback(OperationContext* opCtx, FixUpInfo how; how.localTopOfOplog = replCoord->getMyLastAppliedOpTime(); - log() << "Starting rollback. Sync source: " << rollbackSource.getSource() << rsLog; + LOGV2_OPTIONS(21681, + {logv2::LogTag::kRS}, + "Starting rollback. Sync source: {rollbackSource_getSource}", + "rollbackSource_getSource"_attr = rollbackSource.getSource()); how.rbid = rollbackSource.getRollbackId(); uassert( 40506, "Upstream node rolled back. Need to retry our rollback.", how.rbid == requiredRBID); @@ -1085,7 +1196,7 @@ Status _syncRollback(OperationContext* opCtx, // they may be made redundant by a rolled-back startIndexBuild oplog entry. how.indexBuildsToRestart.insert(abortedIndexBuilds.begin(), abortedIndexBuilds.end()); - log() << "Finding the Common Point"; + LOGV2(21682, "Finding the Common Point"); try { auto processOperationForFixUp = [&how, &opCtx, &localOplog](const BSONObj& operation) { @@ -1122,7 +1233,7 @@ Status _syncRollback(OperationContext* opCtx, OpTime lastCommittedOpTime = replCoord->getLastCommittedOpTime(); OpTime committedSnapshot = replCoord->getCurrentCommittedSnapshotOpTime(); - log() << "Rollback common point is " << commonPoint; + LOGV2(21683, "Rollback common point is {commonPoint}", "commonPoint"_attr = commonPoint); // Rollback common point should be >= the replication commit point. invariant(commonPoint.getTimestamp() >= lastCommittedOpTime.getTimestamp()); @@ -1140,8 +1251,9 @@ Status _syncRollback(OperationContext* opCtx, syncFixUp(opCtx, how, rollbackSource, replCoord, replicationProcess); if (MONGO_unlikely(rollbackExitEarlyAfterCollectionDrop.shouldFail())) { - log() << "rollbackExitEarlyAfterCollectionDrop fail point enabled. Returning early " - "until fail point is disabled."; + LOGV2(21684, + "rollbackExitEarlyAfterCollectionDrop fail point enabled. Returning early " + "until fail point is disabled."); return Status(ErrorCodes::NamespaceNotFound, str::stream() << "Failing rollback because " "rollbackExitEarlyAfterCollectionDrop fail point " @@ -1164,8 +1276,9 @@ Status _syncRollback(OperationContext* opCtx, if (MONGO_unlikely(rollbackHangBeforeFinish.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "rollback - rollbackHangBeforeFinish fail point " - "enabled. Blocking until fail point is disabled."; + LOGV2(21685, + "rollback - rollbackHangBeforeFinish fail point " + "enabled. Blocking until fail point is disabled."); while (MONGO_unlikely(rollbackHangBeforeFinish.shouldFail())) { invariant(!globalInShutdownDeprecated()); // It is an error to shutdown while enabled. mongo::sleepsecs(1); @@ -1191,7 +1304,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // Fetches all the goodVersions of each document from the current sync source. unsigned long long numFetched = 0; - log() << "Starting refetching documents"; + LOGV2(21686, "Starting refetching documents"); for (auto&& doc : fixUpInfo.docsToRefetch) { invariant(!doc._id.eoo()); // This is checked when we insert to the set. @@ -1201,10 +1314,18 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, try { if (nss) { - LOG(2) << "Refetching document, collection: " << *nss << ", UUID: " << uuid << ", " - << redact(doc._id); + LOGV2_DEBUG(21687, + 2, + "Refetching document, collection: {nss}, UUID: {uuid}, {doc_id}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "doc_id"_attr = redact(doc._id)); } else { - LOG(2) << "Refetching document, UUID: " << uuid << ", " << redact(doc._id); + LOGV2_DEBUG(21688, + 2, + "Refetching document, UUID: {uuid}, {doc_id}", + "uuid"_attr = uuid, + "doc_id"_attr = redact(doc._id)); } // TODO : Slow. Lots of round trips. numFetched++; @@ -1253,27 +1374,34 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, ex.code() == ErrorCodes::NamespaceNotFound) continue; - log() << "Rollback couldn't re-fetch from uuid: " << uuid << " _id: " << redact(doc._id) - << ' ' << numFetched << '/' << fixUpInfo.docsToRefetch.size() << ": " - << redact(ex); + LOGV2(21689, + "Rollback couldn't re-fetch from uuid: {uuid} _id: {doc_id} " + "{numFetched}/{fixUpInfo_docsToRefetch_size}: {ex}", + "uuid"_attr = uuid, + "doc_id"_attr = redact(doc._id), + "numFetched"_attr = numFetched, + "fixUpInfo_docsToRefetch_size"_attr = fixUpInfo.docsToRefetch.size(), + "ex"_attr = redact(ex)); throw; } } - log() << "Finished refetching documents. Total size of documents refetched: " - << goodVersions.size(); + LOGV2(21690, + "Finished refetching documents. Total size of documents refetched: {goodVersions_size}", + "goodVersions_size"_attr = goodVersions.size()); // We must start taking unstable checkpoints before rolling back oplog entries. Otherwise, a // stable checkpoint could include the fixup write (since it is untimestamped) but not the write // being rolled back (if it is after the stable timestamp), leading to inconsistent state. An // unstable checkpoint will include both writes. if (!serverGlobalParams.enableMajorityReadConcern) { - log() << "Setting initialDataTimestamp to 0 so that we start taking unstable checkpoints."; + LOGV2(21691, + "Setting initialDataTimestamp to 0 so that we start taking unstable checkpoints."); opCtx->getServiceContext()->getStorageEngine()->setInitialDataTimestamp( Timestamp::kAllowUnstableCheckpointsSentinel); } - log() << "Checking the RollbackID and updating the MinValid if necessary"; + LOGV2(21692, "Checking the RollbackID and updating the MinValid if necessary"); checkRbidAndUpdateMinValid(opCtx, fixUpInfo.rbid, rollbackSource, replicationProcess); @@ -1288,7 +1416,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // indexes. // We drop indexes before renaming collections so that if a collection name gets longer, // any indexes with names that are now too long will already be dropped. - log() << "Rolling back createIndexes and startIndexBuild operations"; + LOGV2(21693, "Rolling back createIndexes and startIndexBuild operations"); for (auto it = fixUpInfo.indexesToDrop.begin(); it != fixUpInfo.indexesToDrop.end(); it++) { UUID uuid = it->first; @@ -1301,7 +1429,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // rolled-back, but the unfinished index still exists in the catalog. Drop these before any // collection drops, because one of the preconditions of dropping a collection is that there are // no unfinished indxes. - log() << "Rolling back unfinished startIndexBuild operations"; + LOGV2(21694, "Rolling back unfinished startIndexBuild operations"); for (auto index : fixUpInfo.unfinishedIndexesToDrop) { UUID uuid = index.first; std::set<std::string> indexNames = index.second; @@ -1309,7 +1437,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, rollbackCreateIndexes(opCtx, uuid, indexNames); } - log() << "Dropping collections to roll back create operations"; + LOGV2(21695, "Dropping collections to roll back create operations"); // Drops collections before updating individual documents. We drop these collections before // rolling back any other commands to prevent namespace collisions that may occur @@ -1332,9 +1460,12 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // Do not attempt to acquire the database lock with an empty namespace. We should survive // an attempt to drop a non-existent collection. if (!nss) { - log() << "This collection does not exist, UUID: " << uuid; + LOGV2(21696, "This collection does not exist, UUID: {uuid}", "uuid"_attr = uuid); } else { - log() << "Dropping collection: " << *nss << ", UUID: " << uuid; + LOGV2(21697, + "Dropping collection: {nss}, UUID: {uuid}", + "nss"_attr = *nss, + "uuid"_attr = uuid); AutoGetDb dbLock(opCtx, nss->db(), MODE_X); Database* db = dbLock.getDb(); @@ -1342,7 +1473,11 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByUUID(opCtx, uuid); dropCollection(opCtx, *nss, collection, db); - LOG(1) << "Dropped collection: " << *nss << ", UUID: " << uuid; + LOGV2_DEBUG(21698, + 1, + "Dropped collection: {nss}, UUID: {uuid}", + "nss"_attr = *nss, + "uuid"_attr = uuid); } } } @@ -1352,7 +1487,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, } // Rolling back renameCollection commands. - log() << "Rolling back renameCollection commands and collection drop commands."; + LOGV2(21699, "Rolling back renameCollection commands and collection drop commands."); for (auto it = fixUpInfo.collectionsToRename.begin(); it != fixUpInfo.collectionsToRename.end(); it++) { @@ -1363,16 +1498,21 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, rollbackRenameCollection(opCtx, uuid, info); } - log() << "Rolling back collections pending being dropped: Removing them from the list of " - "drop-pending collections in the DropPendingCollectionReaper."; + LOGV2(21700, + "Rolling back collections pending being dropped: Removing them from the list of " + "drop-pending collections in the DropPendingCollectionReaper."); // Roll back any drop-pending collections. This must be done first so that the collection // exists when we attempt to resync its metadata or insert documents into it. for (const auto& collPair : fixUpInfo.collectionsToRemoveFromDropPendingCollections) { const auto& optime = collPair.second.first; const auto& collectionNamespace = collPair.second.second; - LOG(1) << "Rolling back collection pending being dropped for OpTime: " << optime - << ", collection: " << collectionNamespace; + LOGV2_DEBUG(21701, + 1, + "Rolling back collection pending being dropped for OpTime: {optime}, " + "collection: {collectionNamespace}", + "optime"_attr = optime, + "collectionNamespace"_attr = collectionNamespace); DropPendingCollectionReaper::get(opCtx)->rollBackDropPendingCollection( opCtx, optime, collectionNamespace); } @@ -1391,7 +1531,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, CollectionCatalog::get(opCtx).lookupNSSByUUID(opCtx, uuid); invariant(nss); - log() << "Resyncing collection metadata for collection: " << *nss << ", UUID: " << uuid; + LOGV2(21702, + "Resyncing collection metadata for collection: {nss}, UUID: {uuid}", + "nss"_attr = *nss, + "uuid"_attr = uuid); Lock::DBLock dbLock(opCtx, nss->db(), MODE_X); @@ -1411,9 +1554,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // is rolled back upstream and we restart, we expect to still have the // collection. - log() << nss->ns() - << " not found on remote host, so we do not roll back collmod " - "operation. Instead, we will drop the collection soon."; + LOGV2(21703, + "{nss_ns} not found on remote host, so we do not roll back collmod " + "operation. Instead, we will drop the collection soon.", + "nss_ns"_attr = nss->ns()); continue; } @@ -1460,22 +1604,29 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, wuow.commit(); - LOG(1) << "Resynced collection metadata for collection: " << *nss << ", UUID: " << uuid - << ", with: " << redact(info) << ", to: " - << redact(DurableCatalog::get(opCtx) - ->getCollectionOptions(opCtx, collection->getCatalogId()) - .toBSON()); + LOGV2_DEBUG( + 21704, + 1, + "Resynced collection metadata for collection: {nss}, UUID: {uuid}, with: {info}, " + "to: {DurableCatalog_get_opCtx_getCollectionOptions_opCtx_collection_getCatalogId}", + "nss"_attr = *nss, + "uuid"_attr = uuid, + "info"_attr = redact(info), + "DurableCatalog_get_opCtx_getCollectionOptions_opCtx_collection_getCatalogId"_attr = + redact(DurableCatalog::get(opCtx) + ->getCollectionOptions(opCtx, collection->getCatalogId()) + .toBSON())); } // Since we read from the sync source to retrieve the metadata of the // collection, we must check if the sync source rolled back as well as update // minValid if necessary. - log() << "Rechecking the Rollback ID and minValid"; + LOGV2(21705, "Rechecking the Rollback ID and minValid"); checkRbidAndUpdateMinValid(opCtx, fixUpInfo.rbid, rollbackSource, replicationProcess); } // Rolls back dropIndexes commands by re-creating the indexes that were dropped. - log() << "Rolling back dropIndexes commands."; + LOGV2(21706, "Rolling back dropIndexes commands."); for (auto it = fixUpInfo.indexesToCreate.begin(); it != fixUpInfo.indexesToCreate.end(); it++) { UUID uuid = it->first; @@ -1484,12 +1635,13 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, rollbackDropIndexes(opCtx, uuid, indexNames); } - log() << "Restarting rolled-back committed or aborted index builds."; + LOGV2(21707, "Restarting rolled-back committed or aborted index builds."); IndexBuildsCoordinator::get(opCtx)->restartIndexBuildsForRecovery( opCtx, fixUpInfo.indexBuildsToRestart); - log() << "Deleting and updating documents to roll back insert, update and remove " - "operations"; + LOGV2(21708, + "Deleting and updating documents to roll back insert, update and remove " + "operations"); unsigned deletes = 0, updates = 0; time_t lastProgressUpdate = time(nullptr); time_t progressUpdateGap = 10; @@ -1510,18 +1662,24 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, if (RollbackImpl::shouldCreateDataFiles()) { removeSaver = std::make_unique<RemoveSaver>("rollback", "", uuid.toString()); - log() << "Preparing to write deleted documents to a rollback file for collection " - << *nss << " with uuid " << uuid.toString() << " to " - << removeSaver->file().generic_string(); + LOGV2(21709, + "Preparing to write deleted documents to a rollback file for collection {nss} " + "with uuid {uuid} to {removeSaver_file_generic_string}", + "nss"_attr = *nss, + "uuid"_attr = uuid.toString(), + "removeSaver_file_generic_string"_attr = removeSaver->file().generic_string()); } const auto& goodVersionsByDocID = nsAndGoodVersionsByDocID.second; for (const auto& idAndDoc : goodVersionsByDocID) { time_t now = time(nullptr); if (now - lastProgressUpdate > progressUpdateGap) { - log() << deletes << " delete and " << updates - << " update operations processed out of " << goodVersions.size() - << " total operations."; + LOGV2(21710, + "{deletes} delete and {updates} update operations processed out of " + "{goodVersions_size} total operations.", + "deletes"_attr = deletes, + "updates"_attr = updates, + "goodVersions_size"_attr = goodVersions.size()); lastProgressUpdate = now; } const DocID& doc = idAndDoc.first; @@ -1546,21 +1704,31 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, if (found) { auto status = removeSaver->goingToDelete(obj); if (!status.isOK()) { - severe() << "Rollback cannot write document in namespace " << nss->ns() - << " to archive file: " << redact(status); + LOGV2_FATAL(21747, + "Rollback cannot write document in namespace {nss_ns} to " + "archive file: {status}", + "nss_ns"_attr = nss->ns(), + "status"_attr = redact(status)); throw RSFatalException(str::stream() << "Rollback cannot write document in namespace " << nss->ns() << " to archive file."); } } else { - error() << "Rollback cannot find object: " << pattern << " in namespace " - << nss->ns(); + LOGV2_ERROR(21730, + "Rollback cannot find object: {pattern} in namespace {nss_ns}", + "pattern"_attr = pattern, + "nss_ns"_attr = nss->ns()); } } if (idAndDoc.second.isEmpty()) { - LOG(2) << "Deleting document with: " << redact(doc._id) - << ", from collection: " << doc.ns << ", with UUID: " << uuid; + LOGV2_DEBUG(21711, + 2, + "Deleting document with: {doc_id}, from collection: {doc_ns}, with " + "UUID: {uuid}", + "doc_id"_attr = redact(doc._id), + "doc_ns"_attr = doc.ns, + "uuid"_attr = uuid); // If the document could not be found on the primary, deletes the document. // TODO 1.6 : can't delete from a capped collection. Need to handle that // here. @@ -1580,8 +1748,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, const auto findOneStart = clock->now(); RecordId loc = Helpers::findOne(opCtx, collection, pattern, false); if (clock->now() - findOneStart > Milliseconds(200)) - warning() << "Roll back slow no _id index for " << nss->ns() - << " perhaps?"; + LOGV2_WARNING( + 21726, + "Roll back slow no _id index for {nss_ns} perhaps?", + "nss_ns"_attr = nss->ns()); // Would be faster but requires index: // RecordId loc = Helpers::findById(nsd, pattern); if (!loc.isNull()) { @@ -1614,11 +1784,15 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // inconsistent. We rely on age-out to make these problems go away // eventually. - warning() << "Ignoring failure to roll back change to capped " - << "collection " << nss->ns() << " with _id " - << redact(idAndDoc.first._id.toString( - /*includeFieldName*/ false)) - << ": " << redact(e); + LOGV2_WARNING(21727, + "Ignoring failure to roll back change to capped " + "collection {nss_ns} with _id " + "{idAndDoc_first_id_includeFieldName_false}: {e}", + "nss_ns"_attr = nss->ns(), + "idAndDoc_first_id_includeFieldName_false"_attr = + redact(idAndDoc.first._id.toString( + /*includeFieldName*/ false)), + "e"_attr = redact(e)); } } else { deleteObjects(opCtx, @@ -1630,9 +1804,14 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, } } } else { - LOG(2) << "Updating document with: " << redact(doc._id) - << ", from collection: " << doc.ns << ", UUID: " << uuid - << ", to: " << redact(idAndDoc.second); + LOGV2_DEBUG(21712, + 2, + "Updating document with: {doc_id}, from collection: {doc_ns}, " + "UUID: {uuid}, to: {idAndDoc_second}", + "doc_id"_attr = redact(doc._id), + "doc_ns"_attr = doc.ns, + "uuid"_attr = uuid, + "idAndDoc_second"_attr = redact(idAndDoc.second)); // TODO faster... updates++; @@ -1646,23 +1825,31 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, update(opCtx, ctx.db(), request); } } catch (const DBException& e) { - log() << "Exception in rollback ns:" << nss->ns() << ' ' << pattern.toString() - << ' ' << redact(e) << " ndeletes:" << deletes; + LOGV2(21713, + "Exception in rollback ns:{nss_ns} {pattern} {e} ndeletes:{deletes}", + "nss_ns"_attr = nss->ns(), + "pattern"_attr = pattern.toString(), + "e"_attr = redact(e), + "deletes"_attr = deletes); throw; } } } - log() << "Rollback deleted " << deletes << " documents and updated " << updates - << " documents."; + LOGV2(21714, + "Rollback deleted {deletes} documents and updated {updates} documents.", + "deletes"_attr = deletes, + "updates"_attr = updates); if (!serverGlobalParams.enableMajorityReadConcern) { // When majority read concern is disabled, the stable timestamp may be ahead of the common // point. Force the stable timestamp back to the common point, to allow writes after the // common point. const bool force = true; - log() << "Forcing the stable timestamp to the common point: " - << fixUpInfo.commonPoint.getTimestamp(); + LOGV2(21715, + "Forcing the stable timestamp to the common point: " + "{fixUpInfo_commonPoint_getTimestamp}", + "fixUpInfo_commonPoint_getTimestamp"_attr = fixUpInfo.commonPoint.getTimestamp()); opCtx->getServiceContext()->getStorageEngine()->setStableTimestamp( fixUpInfo.commonPoint.getTimestamp(), force); @@ -1676,22 +1863,28 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, auto syncSourceTopOfOplog = OpTime::parseFromOplogEntry(rollbackSource.getLastOperation()) .getValue() .getTimestamp(); - log() << "Setting initialDataTimestamp to the max of local top of oplog and sync source " - "top of oplog. Local top of oplog: " - << fixUpInfo.localTopOfOplog.getTimestamp() - << ", sync source top of oplog: " << syncSourceTopOfOplog; + LOGV2(21716, + "Setting initialDataTimestamp to the max of local top of oplog and sync source " + "top of oplog. Local top of oplog: {fixUpInfo_localTopOfOplog_getTimestamp}, sync " + "source top of oplog: {syncSourceTopOfOplog}", + "fixUpInfo_localTopOfOplog_getTimestamp"_attr = + fixUpInfo.localTopOfOplog.getTimestamp(), + "syncSourceTopOfOplog"_attr = syncSourceTopOfOplog); opCtx->getServiceContext()->getStorageEngine()->setInitialDataTimestamp( std::max(fixUpInfo.localTopOfOplog.getTimestamp(), syncSourceTopOfOplog)); // Take an unstable checkpoint to ensure that all of the writes performed during rollback // are persisted to disk before truncating oplog. - log() << "Waiting for an unstable checkpoint"; + LOGV2(21717, "Waiting for an unstable checkpoint"); const bool stableCheckpoint = false; opCtx->recoveryUnit()->waitUntilUnjournaledWritesDurable(opCtx, stableCheckpoint); } - log() << "Truncating the oplog at " << fixUpInfo.commonPoint.toString() << " (" - << fixUpInfo.commonPointOurDiskloc << "), non-inclusive"; + LOGV2(21718, + "Truncating the oplog at {fixUpInfo_commonPoint} ({fixUpInfo_commonPointOurDiskloc}), " + "non-inclusive", + "fixUpInfo_commonPoint"_attr = fixUpInfo.commonPoint.toString(), + "fixUpInfo_commonPointOurDiskloc"_attr = fixUpInfo.commonPointOurDiskloc); // Cleans up the oplog. { @@ -1718,24 +1911,28 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // This is done using an untimestamped write, since timestamping the write with the common // point TS would be incorrect (since this is equal to the stable timestamp), and this write // will be included in the unstable checkpoint regardless of its timestamp. - log() << "Setting appliedThrough to the common point: " << fixUpInfo.commonPoint; + LOGV2(21719, + "Setting appliedThrough to the common point: {fixUpInfo_commonPoint}", + "fixUpInfo_commonPoint"_attr = fixUpInfo.commonPoint); const bool setTimestamp = false; replicationProcess->getConsistencyMarkers()->setAppliedThrough( opCtx, fixUpInfo.commonPoint, setTimestamp); // Take an unstable checkpoint to ensure the appliedThrough write is persisted to disk. - log() << "Waiting for an unstable checkpoint"; + LOGV2(21720, "Waiting for an unstable checkpoint"); const bool stableCheckpoint = false; opCtx->recoveryUnit()->waitUntilUnjournaledWritesDurable(opCtx, stableCheckpoint); // Ensure that appliedThrough is unset in the next stable checkpoint. - log() << "Clearing appliedThrough"; + LOGV2(21721, "Clearing appliedThrough"); replicationProcess->getConsistencyMarkers()->clearAppliedThrough(opCtx, Timestamp()); } Status status = AuthorizationManager::get(opCtx->getServiceContext())->initialize(opCtx); if (!status.isOK()) { - severe() << "Failed to reinitialize auth data after rollback: " << redact(status); + LOGV2_FATAL(21748, + "Failed to reinitialize auth data after rollback: {status}", + "status"_attr = redact(status)); fassertFailedNoTrace(40496); } @@ -1790,8 +1987,12 @@ Status syncRollback(OperationContext* opCtx, replCoord, replicationProcess); - log() << "Rollback finished. The final minValid is: " - << replicationProcess->getConsistencyMarkers()->getMinValid(opCtx) << rsLog; + LOGV2_OPTIONS(21722, + {logv2::LogTag::kRS}, + "Rollback finished. The final minValid is: " + "{replicationProcess_getConsistencyMarkers_getMinValid_opCtx}", + "replicationProcess_getConsistencyMarkers_getMinValid_opCtx"_attr = + replicationProcess->getConsistencyMarkers()->getMinValid(opCtx)); return status; } @@ -1821,15 +2022,21 @@ void rollback(OperationContext* opCtx, auto status = replCoord->setFollowerModeStrict(opCtx, MemberState::RS_ROLLBACK); if (!status.isOK()) { - log() << "Cannot transition from " << replCoord->getMemberState().toString() << " to " - << MemberState(MemberState::RS_ROLLBACK).toString() << causedBy(status); + LOGV2(21723, + "Cannot transition from {replCoord_getMemberState} to " + "{MemberState_MemberState_RS_ROLLBACK}{causedBy_status}", + "replCoord_getMemberState"_attr = replCoord->getMemberState().toString(), + "MemberState_MemberState_RS_ROLLBACK"_attr = + MemberState(MemberState::RS_ROLLBACK).toString(), + "causedBy_status"_attr = causedBy(status)); return; } } if (MONGO_unlikely(rollbackHangAfterTransitionToRollback.shouldFail())) { - log() << "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail " - "point is disabled (rs_rollback)."; + LOGV2(21724, + "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail " + "point is disabled (rs_rollback)."); rollbackHangAfterTransitionToRollback.pauseWhileSet(opCtx); } @@ -1846,8 +2053,9 @@ void rollback(OperationContext* opCtx, // WARNING: these statuses sometimes have location codes which are lost with uassertStatusOK // so we need to check here first. if (ErrorCodes::UnrecoverableRollbackError == status.code()) { - severe() << "Unable to complete rollback. A full resync may be needed: " - << redact(status); + LOGV2_FATAL(21749, + "Unable to complete rollback. A full resync may be needed: {status}", + "status"_attr = redact(status)); fassertFailedNoTrace(40507); } @@ -1858,9 +2066,14 @@ void rollback(OperationContext* opCtx, // above. invariant(ex.code() != ErrorCodes::UnrecoverableRollbackError); - warning() << "Rollback cannot complete at this time (retrying later): " << redact(ex) - << " appliedThrough= " << replCoord->getMyLastAppliedOpTime() << " minvalid= " - << replicationProcess->getConsistencyMarkers()->getMinValid(opCtx); + LOGV2_WARNING(21728, + "Rollback cannot complete at this time (retrying later): {ex} " + "appliedThrough= {replCoord_getMyLastAppliedOpTime} minvalid= " + "{replicationProcess_getConsistencyMarkers_getMinValid_opCtx}", + "ex"_attr = redact(ex), + "replCoord_getMyLastAppliedOpTime"_attr = replCoord->getMyLastAppliedOpTime(), + "replicationProcess_getConsistencyMarkers_getMinValid_opCtx"_attr = + replicationProcess->getConsistencyMarkers()->getMinValid(opCtx)); // Sleep a bit to allow upstream node to coalesce, if that was the cause of the failure. If // we failed in a way that will keep failing, but wasn't flagged as a fatal failure, this @@ -1882,17 +2095,24 @@ void rollback(OperationContext* opCtx, // then we must shut down to clear the in-memory ShardingState associated with the // shardIdentity document. if (ShardIdentityRollbackNotifier::get(opCtx)->didRollbackHappen()) { - severe() << "shardIdentity document rollback detected. Shutting down to clear " + LOGV2_FATAL(21750, + "shardIdentity document rollback detected. Shutting down to clear " "in-memory sharding state. Restarting this process should safely return it " - "to a healthy state"; + "to a healthy state"); fassertFailedNoTrace(40498); } auto status = replCoord->setFollowerMode(MemberState::RS_RECOVERING); if (!status.isOK()) { - severe() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING) - << "; expected to be in state " << MemberState(MemberState::RS_ROLLBACK) - << "; found self in " << replCoord->getMemberState() << causedBy(status); + LOGV2_FATAL( + 21751, + "Failed to transition into {MemberState_MemberState_RS_RECOVERING}; expected to be in " + "state {MemberState_MemberState_RS_ROLLBACK}; found self in " + "{replCoord_getMemberState}{causedBy_status}", + "MemberState_MemberState_RS_RECOVERING"_attr = MemberState(MemberState::RS_RECOVERING), + "MemberState_MemberState_RS_ROLLBACK"_attr = MemberState(MemberState::RS_ROLLBACK), + "replCoord_getMemberState"_attr = replCoord->getMemberState(), + "causedBy_status"_attr = causedBy(status)); fassertFailedNoTrace(40499); } } diff --git a/src/mongo/db/repl/scatter_gather_runner.cpp b/src/mongo/db/repl/scatter_gather_runner.cpp index 18e3bc761b9..9986987b3f4 100644 --- a/src/mongo/db/repl/scatter_gather_runner.cpp +++ b/src/mongo/db/repl/scatter_gather_runner.cpp @@ -38,6 +38,7 @@ #include "mongo/base/status_with.h" #include "mongo/db/repl/scatter_gather_algorithm.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -105,8 +106,10 @@ StatusWith<EventHandle> ScatterGatherRunner::RunnerImpl::start( std::vector<RemoteCommandRequest> requests = _algorithm->getRequests(); for (size_t i = 0; i < requests.size(); ++i) { - log() << "Scheduling remote command request for " << _logMessage << ": " - << requests[i].toString(); + LOGV2(21752, + "Scheduling remote command request for {logMessage}: {requests_i}", + "logMessage"_attr = _logMessage, + "requests_i"_attr = requests[i].toString()); const StatusWith<CallbackHandle> cbh = _executor->scheduleRemoteCommand(requests[i], processResponseCB); if (cbh.getStatus() == ErrorCodes::ShutdownInProgress) { diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index 17af180cd45..92841eeacae 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -76,6 +76,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/oplog_cap_maintainer_thread.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/background.h" #include "mongo/util/log.h" @@ -190,7 +191,10 @@ StorageInterfaceImpl::createCollectionForBulkLoading( const BSONObj idIndexSpec, const std::vector<BSONObj>& secondaryIndexSpecs) { - LOG(2) << "StorageInterfaceImpl::createCollectionForBulkLoading called for ns: " << nss.ns(); + LOGV2_DEBUG(21753, + 2, + "StorageInterfaceImpl::createCollectionForBulkLoading called for ns: {nss_ns}", + "nss_ns"_attr = nss.ns()); class StashClient { public: @@ -384,7 +388,9 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { std::vector<std::string> dbNames = opCtx->getServiceContext()->getStorageEngine()->listDatabases(); invariant(!dbNames.empty()); - log() << "dropReplicatedDatabases - dropping " << dbNames.size() << " databases"; + LOGV2(21754, + "dropReplicatedDatabases - dropping {dbNames_size} databases", + "dbNames_size"_attr = dbNames.size()); ReplicationCoordinator::get(opCtx)->dropAllSnapshots(); @@ -401,14 +407,17 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { } else { // This is needed since dropDatabase can't be rolled back. // This is safe be replaced by "invariant(db);dropDatabase(opCtx, db);" once fixed. - log() << "dropReplicatedDatabases - database disappeared after retrieving list of " - "database names but before drop: " - << dbName; + LOGV2(21755, + "dropReplicatedDatabases - database disappeared after retrieving list of " + "database names but before drop: {dbName}", + "dbName"_attr = dbName); } }); } invariant(hasLocalDatabase, "local database missing"); - log() << "dropReplicatedDatabases - dropped " << dbNames.size() << " databases"; + LOGV2(21756, + "dropReplicatedDatabases - dropped {dbNames_size} databases", + "dbNames_size"_attr = dbNames.size()); return Status::OK(); } diff --git a/src/mongo/db/repl/storage_interface_mock.cpp b/src/mongo/db/repl/storage_interface_mock.cpp index e9fa17504be..30d60626641 100644 --- a/src/mongo/db/repl/storage_interface_mock.cpp +++ b/src/mongo/db/repl/storage_interface_mock.cpp @@ -34,6 +34,7 @@ #include "mongo/db/repl/storage_interface_mock.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -103,14 +104,14 @@ bool StorageInterfaceMock::supportsDocLocking(ServiceContext* serviceCtx) const } Status CollectionBulkLoaderMock::init(const std::vector<BSONObj>& secondaryIndexSpecs) { - LOG(1) << "CollectionBulkLoaderMock::init called"; + LOGV2_DEBUG(21757, 1, "CollectionBulkLoaderMock::init called"); stats->initCalled = true; return Status::OK(); }; Status CollectionBulkLoaderMock::insertDocuments(const std::vector<BSONObj>::const_iterator begin, const std::vector<BSONObj>::const_iterator end) { - LOG(1) << "CollectionBulkLoaderMock::insertDocuments called"; + LOGV2_DEBUG(21758, 1, "CollectionBulkLoaderMock::insertDocuments called"); const auto status = insertDocsFn(begin, end); // Only count if it succeeds. @@ -121,7 +122,7 @@ Status CollectionBulkLoaderMock::insertDocuments(const std::vector<BSONObj>::con }; Status CollectionBulkLoaderMock::commit() { - LOG(1) << "CollectionBulkLoaderMock::commit called"; + LOGV2_DEBUG(21759, 1, "CollectionBulkLoaderMock::commit called"); stats->commitCalled = true; return commitFn(); }; diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp index 03b5af98376..0fc2f3f16ac 100644 --- a/src/mongo/db/repl/sync_source_feedback.cpp +++ b/src/mongo/db/repl/sync_source_feedback.cpp @@ -39,6 +39,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/repl/reporter.h" #include "mongo/executor/task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/log.h" #include "mongo/util/net/hostandport.h" @@ -104,8 +105,11 @@ void SyncSourceFeedback::forwardSlaveProgress() { if (_reporter) { auto triggerStatus = _reporter->trigger(); if (!triggerStatus.isOK()) { - warning() << "unable to forward slave progress to " << _reporter->getTarget() - << ": " << triggerStatus; + LOGV2_WARNING( + 21764, + "unable to forward slave progress to {reporter_getTarget}: {triggerStatus}", + "reporter_getTarget"_attr = _reporter->getTarget(), + "triggerStatus"_attr = triggerStatus); } } } @@ -116,15 +120,21 @@ Status SyncSourceFeedback::_updateUpstream(Reporter* reporter) { auto triggerStatus = reporter->trigger(); if (!triggerStatus.isOK()) { - warning() << "unable to schedule reporter to update replication progress on " << syncTarget - << ": " << triggerStatus; + LOGV2_WARNING(21765, + "unable to schedule reporter to update replication progress on {syncTarget}: " + "{triggerStatus}", + "syncTarget"_attr = syncTarget, + "triggerStatus"_attr = triggerStatus); return triggerStatus; } auto status = reporter->join(); if (!status.isOK()) { - log() << "SyncSourceFeedback error sending update to " << syncTarget << ": " << status; + LOGV2(21760, + "SyncSourceFeedback error sending update to {syncTarget}: {status}", + "syncTarget"_attr = syncTarget, + "status"_attr = status); } // Sync source blacklisting will be done in BackgroundSync and SyncSourceResolver. @@ -202,15 +212,19 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, } if (syncTarget != target) { - LOG(1) << "setting syncSourceFeedback to " << target; + LOGV2_DEBUG(21761, 1, "setting syncSourceFeedback to {target}", "target"_attr = target); syncTarget = target; // Update keepalive value from config. auto oldKeepAliveInterval = keepAliveInterval; keepAliveInterval = calculateKeepAliveInterval(replCoord->getConfig()); if (oldKeepAliveInterval != keepAliveInterval) { - LOG(1) << "new syncSourceFeedback keep alive duration = " << keepAliveInterval - << " (previously " << oldKeepAliveInterval << ")"; + LOGV2_DEBUG(21762, + 1, + "new syncSourceFeedback keep alive duration = {keepAliveInterval} " + "(previously {oldKeepAliveInterval})", + "keepAliveInterval"_attr = keepAliveInterval, + "oldKeepAliveInterval"_attr = oldKeepAliveInterval); } } @@ -233,9 +247,12 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, auto status = _updateUpstream(&reporter); if (!status.isOK()) { - LOG(1) << "The replication progress command (replSetUpdatePosition) failed and will be " - "retried: " - << status; + LOGV2_DEBUG( + 21763, + 1, + "The replication progress command (replSetUpdatePosition) failed and will be " + "retried: {status}", + "status"_attr = status); } } } diff --git a/src/mongo/db/repl/sync_source_resolver.cpp b/src/mongo/db/repl/sync_source_resolver.cpp index a6c87de8731..8ecdad2ebe4 100644 --- a/src/mongo/db/repl/sync_source_resolver.cpp +++ b/src/mongo/db/repl/sync_source_resolver.cpp @@ -39,6 +39,7 @@ #include "mongo/db/repl/oplog_entry.h" #include "mongo/db/repl/replication_process.h" #include "mongo/db/repl/sync_source_selector.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/assert_util.h" #include "mongo/util/destructor_guard.h" @@ -224,8 +225,11 @@ Status SyncSourceResolver::_scheduleFetcher(std::unique_ptr<Fetcher> fetcher) { _shuttingDownFetcher = std::move(_fetcher); _fetcher = std::move(fetcher); } else { - error() << "Error scheduling fetcher to evaluate host as sync source, host:" - << fetcher->getSource() << ", error: " << status; + LOGV2_ERROR(21776, + "Error scheduling fetcher to evaluate host as sync source, " + "host:{fetcher_getSource}, error: {status}", + "fetcher_getSource"_attr = fetcher->getSource(), + "status"_attr = status); } return status; } @@ -235,8 +239,12 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida if (queryResponse.documents.empty()) { // Remote oplog is empty. const auto until = _taskExecutor->now() + kOplogEmptyBlacklistDuration; - log() << "Blacklisting " << candidate << " due to empty oplog for " - << kOplogEmptyBlacklistDuration << " until: " << until; + LOGV2(21766, + "Blacklisting {candidate} due to empty oplog for {kOplogEmptyBlacklistDuration} " + "until: {until}", + "candidate"_attr = candidate, + "kOplogEmptyBlacklistDuration"_attr = kOplogEmptyBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); return OpTime(); } @@ -245,8 +253,13 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida if (firstObjFound.isEmpty()) { // First document in remote oplog is empty. const auto until = _taskExecutor->now() + kFirstOplogEntryEmptyBlacklistDuration; - log() << "Blacklisting " << candidate << " due to empty first document for " - << kFirstOplogEntryEmptyBlacklistDuration << " until: " << until; + LOGV2(21767, + "Blacklisting {candidate} due to empty first document for " + "{kFirstOplogEntryEmptyBlacklistDuration} until: {until}", + "candidate"_attr = candidate, + "kFirstOplogEntryEmptyBlacklistDuration"_attr = + kFirstOplogEntryEmptyBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); return OpTime(); } @@ -254,10 +267,16 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida const auto remoteEarliestOpTime = OpTime::parseFromOplogEntry(firstObjFound); if (!remoteEarliestOpTime.isOK()) { const auto until = _taskExecutor->now() + kFirstOplogEntryNullTimestampBlacklistDuration; - log() << "Blacklisting " << candidate << " due to error parsing OpTime from the oldest" - << " oplog entry for " << kFirstOplogEntryNullTimestampBlacklistDuration - << " until: " << until << ". Error: " << remoteEarliestOpTime.getStatus() - << ", Entry: " << redact(firstObjFound); + LOGV2(21768, + "Blacklisting {candidate} due to error parsing OpTime from the oldest oplog entry " + "for {kFirstOplogEntryNullTimestampBlacklistDuration} until: {until}. Error: " + "{remoteEarliestOpTime_getStatus}, Entry: {firstObjFound}", + "candidate"_attr = candidate, + "kFirstOplogEntryNullTimestampBlacklistDuration"_attr = + kFirstOplogEntryNullTimestampBlacklistDuration, + "until"_attr = until, + "remoteEarliestOpTime_getStatus"_attr = remoteEarliestOpTime.getStatus(), + "firstObjFound"_attr = redact(firstObjFound)); _syncSourceSelector->blacklistSyncSource(candidate, until); return OpTime(); } @@ -265,8 +284,13 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida if (remoteEarliestOpTime.getValue().isNull()) { // First document in remote oplog is empty. const auto until = _taskExecutor->now() + kFirstOplogEntryNullTimestampBlacklistDuration; - log() << "Blacklisting " << candidate << " due to null timestamp in first document for " - << kFirstOplogEntryNullTimestampBlacklistDuration << " until: " << until; + LOGV2(21769, + "Blacklisting {candidate} due to null timestamp in first document for " + "{kFirstOplogEntryNullTimestampBlacklistDuration} until: {until}", + "candidate"_attr = candidate, + "kFirstOplogEntryNullTimestampBlacklistDuration"_attr = + kFirstOplogEntryNullTimestampBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); return OpTime(); } @@ -295,8 +319,13 @@ void SyncSourceResolver::_firstOplogEntryFetcherCallback( if (!queryResult.isOK()) { // We got an error. const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration; - log() << "Blacklisting " << candidate << " due to error: '" << queryResult.getStatus() - << "' for " << kFetcherErrorBlacklistDuration << " until: " << until; + LOGV2(21770, + "Blacklisting {candidate} due to error: '{queryResult_getStatus}' for " + "{kFetcherErrorBlacklistDuration} until: {until}", + "candidate"_attr = candidate, + "queryResult_getStatus"_attr = queryResult.getStatus(), + "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); _chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore(); @@ -316,11 +345,16 @@ void SyncSourceResolver::_firstOplogEntryFetcherCallback( const auto blacklistDuration = kTooStaleBlacklistDuration; const auto until = _taskExecutor->now() + Minutes(1); - log() << "We are too stale to use " << candidate << " as a sync source. " - << "Blacklisting this sync source" - << " because our last fetched timestamp: " << _lastOpTimeFetched.getTimestamp() - << " is before their earliest timestamp: " << remoteEarliestOpTime.getTimestamp() - << " for " << blacklistDuration << " until: " << until; + LOGV2(21771, + "We are too stale to use {candidate} as a sync source. Blacklisting this sync source " + "because our last fetched timestamp: {lastOpTimeFetched_getTimestamp} is before " + "their earliest timestamp: {remoteEarliestOpTime_getTimestamp} for " + "{blacklistDuration} until: {until}", + "candidate"_attr = candidate, + "lastOpTimeFetched_getTimestamp"_attr = _lastOpTimeFetched.getTimestamp(), + "remoteEarliestOpTime_getTimestamp"_attr = remoteEarliestOpTime.getTimestamp(), + "blacklistDuration"_attr = blacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); @@ -386,8 +420,13 @@ void SyncSourceResolver::_rbidRequestCallback( rbid = rbidReply.response.data["rbid"].Int(); } catch (const DBException& ex) { const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration; - log() << "Blacklisting " << candidate << " due to error: '" << ex << "' for " - << kFetcherErrorBlacklistDuration << " until: " << until; + LOGV2(21772, + "Blacklisting {candidate} due to error: '{ex}' for {kFetcherErrorBlacklistDuration} " + "until: {until}", + "candidate"_attr = candidate, + "ex"_attr = ex, + "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); _chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore(); return; @@ -456,9 +495,15 @@ void SyncSourceResolver::_requiredOpTimeFetcherCallback( if (!queryResult.isOK()) { // We got an error. const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration; - log() << "Blacklisting " << candidate << " due to required optime fetcher error: '" - << queryResult.getStatus() << "' for " << kFetcherErrorBlacklistDuration - << " until: " << until << ". required optime: " << _requiredOpTime; + LOGV2(21773, + "Blacklisting {candidate} due to required optime fetcher error: " + "'{queryResult_getStatus}' for {kFetcherErrorBlacklistDuration} until: {until}. " + "required optime: {requiredOpTime}", + "candidate"_attr = candidate, + "queryResult_getStatus"_attr = queryResult.getStatus(), + "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration, + "until"_attr = until, + "requiredOpTime"_attr = _requiredOpTime); _syncSourceSelector->blacklistSyncSource(candidate, until); _chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore(); @@ -469,13 +514,18 @@ void SyncSourceResolver::_requiredOpTimeFetcherCallback( auto status = _compareRequiredOpTimeWithQueryResponse(queryResponse); if (!status.isOK()) { const auto until = _taskExecutor->now() + kNoRequiredOpTimeBlacklistDuration; - warning() << "We cannot use " << candidate.toString() - << " as a sync source because it does not contain the necessary " - "operations for us to reach a consistent state: " - << status << " last fetched optime: " << _lastOpTimeFetched - << ". required optime: " << _requiredOpTime - << ". Blacklisting this sync source for " << kNoRequiredOpTimeBlacklistDuration - << " until: " << until; + LOGV2_WARNING( + 21774, + "We cannot use {candidate} as a sync source because it does not contain the necessary " + "operations for us to reach a consistent state: {status} last fetched optime: " + "{lastOpTimeFetched}. required optime: {requiredOpTime}. Blacklisting this sync source " + "for {kNoRequiredOpTimeBlacklistDuration} until: {until}", + "candidate"_attr = candidate.toString(), + "status"_attr = status, + "lastOpTimeFetched"_attr = _lastOpTimeFetched, + "requiredOpTime"_attr = _requiredOpTime, + "kNoRequiredOpTimeBlacklistDuration"_attr = kNoRequiredOpTimeBlacklistDuration, + "until"_attr = until); _syncSourceSelector->blacklistSyncSource(candidate, until); _chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore(); @@ -532,8 +582,9 @@ Status SyncSourceResolver::_finishCallback(const SyncSourceResolverResponse& res try { _onCompletion(response); } catch (...) { - warning() << "sync source resolver finish callback threw exception: " - << exceptionToStatus(); + LOGV2_WARNING(21775, + "sync source resolver finish callback threw exception: {exceptionToStatus}", + "exceptionToStatus"_attr = exceptionToStatus()); } stdx::lock_guard<Latch> lock(_mutex); diff --git a/src/mongo/db/repl/task_runner.cpp b/src/mongo/db/repl/task_runner.cpp index 86edc6da9c5..5889b149393 100644 --- a/src/mongo/db/repl/task_runner.cpp +++ b/src/mongo/db/repl/task_runner.cpp @@ -40,6 +40,7 @@ #include "mongo/db/client.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/destructor_guard.h" @@ -65,7 +66,9 @@ TaskRunner::NextAction runSingleTask(const TaskRunner::Task& task, try { return task(opCtx, status); } catch (...) { - log() << "Unhandled exception in task runner: " << redact(exceptionToStatus()); + LOGV2(21777, + "Unhandled exception in task runner: {exceptionToStatus}", + "exceptionToStatus"_attr = redact(exceptionToStatus())); } return TaskRunner::NextAction::kCancel; } diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index a4e4ab8f9e9..fb7d8c65bd3 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -53,6 +53,7 @@ #include "mongo/db/repl/isself.h" #include "mongo/db/repl/member_data.h" #include "mongo/db/repl/rslog.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/util/assert_util.h" @@ -201,7 +202,8 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, ChainingPreference chainingPreference) { // If we are not a member of the current replica set configuration, no sync source is valid. if (_selfIndex == -1) { - LOG(1) << "Cannot sync from any members because we are not in the replica set config"; + LOGV2_DEBUG( + 21778, 1, "Cannot sync from any members because we are not in the replica set config"); return HostAndPort(); } @@ -209,31 +211,38 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, const auto& data = sfp.getData(); const auto hostAndPortElem = data["hostAndPort"]; if (!hostAndPortElem) { - severe() << "'forceSyncSoureCandidate' parameter set with invalid host and port: " - << data; + LOGV2_FATAL( + 21839, + "'forceSyncSoureCandidate' parameter set with invalid host and port: {data}", + "data"_attr = data); fassertFailed(50835); } const auto hostAndPort = HostAndPort(hostAndPortElem.checkAndGetStringData()); const int syncSourceIndex = _rsConfig.findMemberIndexByHostAndPort(hostAndPort); if (syncSourceIndex < 0) { - log() << "'forceSyncSourceCandidate' failed due to host and port not in " - "replica set config: " - << hostAndPort.toString(); + LOGV2(21779, + "'forceSyncSourceCandidate' failed due to host and port not in " + "replica set config: {hostAndPort}", + "hostAndPort"_attr = hostAndPort.toString()); fassertFailed(50836); } if (_memberIsBlacklisted(_rsConfig.getMemberAt(syncSourceIndex), now)) { - log() << "Cannot select a sync source because forced candidate is blacklisted: " - << hostAndPort.toString(); + LOGV2(21780, + "Cannot select a sync source because forced candidate is blacklisted: " + "{hostAndPort}", + "hostAndPort"_attr = hostAndPort.toString()); _syncSource = HostAndPort(); return _syncSource; } _syncSource = _rsConfig.getMemberAt(syncSourceIndex).getHostAndPort(); - log() << "choosing sync source candidate due to 'forceSyncSourceCandidate' parameter: " - << _syncSource; + LOGV2(21781, + "choosing sync source candidate due to 'forceSyncSourceCandidate' parameter: " + "{syncSource}", + "syncSource"_attr = _syncSource); std::string msg(str::stream() << "syncing from: " << _syncSource.toString() << " by 'forceSyncSourceCandidate' parameter"); setMyHeartbeatMessage(now, msg); @@ -245,7 +254,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, invariant(_forceSyncSourceIndex < _rsConfig.getNumMembers()); _syncSource = _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort(); _forceSyncSourceIndex = -1; - log() << "choosing sync source candidate by request: " << _syncSource; + LOGV2(21782, + "choosing sync source candidate by request: {syncSource}", + "syncSource"_attr = _syncSource); std::string msg(str::stream() << "syncing from: " << _syncSource.toString() << " by request"); setMyHeartbeatMessage(now, msg); @@ -258,7 +269,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, if (needMorePings > 0) { static Occasionally sampler; if (sampler.tick()) { - log() << "waiting for " << needMorePings << " pings from other members before syncing"; + LOGV2(21783, + "waiting for {needMorePings} pings from other members before syncing", + "needMorePings"_attr = needMorePings); } _syncSource = HostAndPort(); return _syncSource; @@ -268,19 +281,26 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, if (chainingPreference == ChainingPreference::kUseConfiguration && !_rsConfig.isChainingAllowed()) { if (_currentPrimaryIndex == -1) { - LOG(1) << "Cannot select a sync source because chaining is" - " not allowed and primary is unknown/down"; + LOGV2_DEBUG(21784, + 1, + "Cannot select a sync source because chaining is" + " not allowed and primary is unknown/down"); _syncSource = HostAndPort(); return _syncSource; } else if (_memberIsBlacklisted(*_currentPrimaryMember(), now)) { - LOG(1) << "Cannot select a sync source because chaining is not allowed and primary " - "member is blacklisted: " - << _currentPrimaryMember()->getHostAndPort(); + LOGV2_DEBUG(21785, + 1, + "Cannot select a sync source because chaining is not allowed and primary " + "member is blacklisted: {currentPrimaryMember_getHostAndPort}", + "currentPrimaryMember_getHostAndPort"_attr = + _currentPrimaryMember()->getHostAndPort()); _syncSource = HostAndPort(); return _syncSource; } else if (_currentPrimaryIndex == _selfIndex) { - LOG(1) - << "Cannot select a sync source because chaining is not allowed and we are primary"; + LOGV2_DEBUG( + 21786, + 1, + "Cannot select a sync source because chaining is not allowed and we are primary"); _syncSource = HostAndPort(); return _syncSource; } else if (_memberData.at(_currentPrimaryIndex).getLastAppliedOpTime() < @@ -295,8 +315,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, return _syncSource; } else { _syncSource = _currentPrimaryMember()->getHostAndPort(); - log() << "chaining not allowed, choosing primary as sync source candidate: " - << _syncSource; + LOGV2(21787, + "chaining not allowed, choosing primary as sync source candidate: {syncSource}", + "syncSource"_attr = _syncSource); std::string msg(str::stream() << "syncing from primary: " << _syncSource.toString()); setMyHeartbeatMessage(now, msg); return _syncSource; @@ -347,14 +368,20 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, // Candidate must be up to be considered. if (!it->up()) { - LOG(2) << "Cannot select sync source because it is not up: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21788, + 2, + "Cannot select sync source because it is not up: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort()); continue; } // Candidate must be PRIMARY or SECONDARY state to be considered. if (!it->getState().readable()) { - LOG(2) << "Cannot select sync source because it is not readable: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21789, + 2, + "Cannot select sync source because it is not readable: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort()); continue; } @@ -362,61 +389,94 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, if (attempts == 0) { // Candidate must be a voter if we are a voter. if (_selfConfig().isVoter() && !itMemberConfig.isVoter()) { - LOG(2) << "Cannot select sync source because we are a voter and it is not: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21790, + 2, + "Cannot select sync source because we are a voter and it is not: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = + itMemberConfig.getHostAndPort()); continue; } // Candidates must not be hidden. if (itMemberConfig.isHidden()) { - LOG(2) << "Cannot select sync source because it is hidden: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21791, + 2, + "Cannot select sync source because it is hidden: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = + itMemberConfig.getHostAndPort()); continue; } // Candidates cannot be excessively behind. if (it->getHeartbeatAppliedOpTime() < oldestSyncOpTime) { - LOG(2) << "Cannot select sync source because it is too far behind." - << "Latest optime of sync candidate " << itMemberConfig.getHostAndPort() - << ": " << it->getHeartbeatAppliedOpTime() - << ", oldest acceptable optime: " << oldestSyncOpTime; + LOGV2_DEBUG( + 21792, + 2, + "Cannot select sync source because it is too far behind.Latest optime of " + "sync candidate {itMemberConfig_getHostAndPort}: " + "{it_getHeartbeatAppliedOpTime}, oldest acceptable optime: " + "{oldestSyncOpTime}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort(), + "it_getHeartbeatAppliedOpTime"_attr = it->getHeartbeatAppliedOpTime(), + "oldestSyncOpTime"_attr = oldestSyncOpTime); continue; } // Candidate must not have a configured delay larger than ours. if (_selfConfig().getSlaveDelay() < itMemberConfig.getSlaveDelay()) { - LOG(2) << "Cannot select sync source with larger slaveDelay than ours: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21793, + 2, + "Cannot select sync source with larger slaveDelay than ours: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = + itMemberConfig.getHostAndPort()); continue; } } // Candidate must build indexes if we build indexes, to be considered. if (_selfConfig().shouldBuildIndexes()) { if (!itMemberConfig.shouldBuildIndexes()) { - LOG(2) << "Cannot select sync source with shouldBuildIndex differences: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21794, + 2, + "Cannot select sync source with shouldBuildIndex differences: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = + itMemberConfig.getHostAndPort()); continue; } } // Only select a candidate that is ahead of me. if (it->getHeartbeatAppliedOpTime() <= lastOpTimeFetched) { - LOG(1) << "Cannot select this sync source. Sync source must be ahead of me. " - << "Sync candidate: " << itMemberConfig.getHostAndPort() - << ", my last fetched oplog optime: " << lastOpTimeFetched.toBSON() - << ", latest oplog optime of sync candidate: " - << it->getHeartbeatAppliedOpTime().toBSON(); + LOGV2_DEBUG(21795, + 1, + "Cannot select this sync source. Sync source must be ahead of me. Sync " + "candidate: {itMemberConfig_getHostAndPort}, my last fetched oplog " + "optime: {lastOpTimeFetched}, latest oplog optime of sync candidate: " + "{it_getHeartbeatAppliedOpTime}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort(), + "lastOpTimeFetched"_attr = lastOpTimeFetched.toBSON(), + "it_getHeartbeatAppliedOpTime"_attr = + it->getHeartbeatAppliedOpTime().toBSON()); continue; } // Candidate cannot be more latent than anything we've already considered. if ((closestIndex != -1) && (_getPing(itMemberConfig.getHostAndPort()) > _getPing(_rsConfig.getMemberAt(closestIndex).getHostAndPort()))) { - LOG(2) << "Cannot select sync source with higher latency than the best candidate: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21796, + 2, + "Cannot select sync source with higher latency than the best " + "candidate: {itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort()); continue; } // Candidate cannot be blacklisted. if (_memberIsBlacklisted(itMemberConfig, now)) { - LOG(1) << "Cannot select sync source which is blacklisted: " - << itMemberConfig.getHostAndPort(); + LOGV2_DEBUG(21797, + 1, + "Cannot select sync source which is blacklisted: " + "{itMemberConfig_getHostAndPort}", + "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort()); continue; } @@ -432,7 +492,7 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, std::string msg("could not find member to sync from"); // Only log when we had a valid sync source before if (!_syncSource.empty()) { - log() << msg << rsLog; + LOGV2_OPTIONS(21798, {logv2::LogTag::kRS}, "{msg}", "msg"_attr = msg); } setMyHeartbeatMessage(now, msg); @@ -440,7 +500,7 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, return _syncSource; } _syncSource = _rsConfig.getMemberAt(closestIndex).getHostAndPort(); - log() << "sync source candidate: " << _syncSource; + LOGV2(21799, "sync source candidate: {syncSource}", "syncSource"_attr = _syncSource); std::string msg(str::stream() << "syncing from: " << _syncSource.toString(), 0); setMyHeartbeatMessage(now, msg); return _syncSource; @@ -458,14 +518,18 @@ bool TopologyCoordinator::_memberIsBlacklisted(const MemberConfig& memberConfig, } void TopologyCoordinator::blacklistSyncSource(const HostAndPort& host, Date_t until) { - LOG(2) << "blacklisting " << host << " until " << until.toString(); + LOGV2_DEBUG(21800, + 2, + "blacklisting {host} until {until}", + "host"_attr = host, + "until"_attr = until.toString()); _syncSourceBlacklist[host] = until; } void TopologyCoordinator::unblacklistSyncSource(const HostAndPort& host, Date_t now) { std::map<HostAndPort, Date_t>::iterator hostItr = _syncSourceBlacklist.find(host); if (hostItr != _syncSourceBlacklist.end() && now >= hostItr->second) { - LOG(2) << "unblacklisting " << host; + LOGV2_DEBUG(21801, 2, "unblacklisting {host}", "host"_attr = host); _syncSourceBlacklist.erase(hostItr); } } @@ -549,9 +613,14 @@ void TopologyCoordinator::prepareSyncFromResponse(const HostAndPort& target, } const OpTime lastOpApplied = getMyLastAppliedOpTime(); if (hbdata.getHeartbeatAppliedOpTime().getSecs() + 10 < lastOpApplied.getSecs()) { - warning() << "attempting to sync from " << target << ", but its latest opTime is " - << hbdata.getHeartbeatAppliedOpTime().getSecs() << " and ours is " - << lastOpApplied.getSecs() << " so this may not work"; + LOGV2_WARNING(21837, + "attempting to sync from {target}, but its latest opTime is " + "{hbdata_getHeartbeatAppliedOpTime_getSecs} and ours is " + "{lastOpApplied_getSecs} so this may not work", + "target"_attr = target, + "hbdata_getHeartbeatAppliedOpTime_getSecs"_attr = + hbdata.getHeartbeatAppliedOpTime().getSecs(), + "lastOpApplied_getSecs"_attr = lastOpApplied.getSecs()); response->append("warning", str::stream() << "requested member \"" << target.toString() << "\" is more than 10 seconds behind us"); @@ -575,8 +644,10 @@ Status TopologyCoordinator::prepareHeartbeatResponseV1(Date_t now, // Verify that replica set names match const std::string rshb = args.getSetName(); if (ourSetName != rshb) { - log() << "replSet set names do not match, ours: " << ourSetName - << "; remote node's: " << rshb; + LOGV2(21802, + "replSet set names do not match, ours: {ourSetName}; remote node's: {rshb}", + "ourSetName"_attr = ourSetName, + "rshb"_attr = rshb); return Status(ErrorCodes::InconsistentReplicaSetNames, str::stream() << "Our set name of " << ourSetName << " does not match name " << rshb << " reported by remote node"); @@ -761,9 +832,9 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse( // Could be we got the newer version before we got the response, or the // target erroneously sent us one, even though it isn't newer. if (newConfig.getConfigVersionAndTerm() < currentConfigVersionAndTerm) { - LOG(1) << "Config version from heartbeat was older than ours."; + LOGV2_DEBUG(21803, 1, "Config version from heartbeat was older than ours."); } else { - LOG(2) << "Config from heartbeat response was same as ours."; + LOGV2_DEBUG(21804, 2, "Config from heartbeat response was same as ours."); } if (shouldLog(MongoLogDefaultComponent_component, ::mongo::LogstreamBuilder::severityCast(2))) { @@ -785,18 +856,24 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse( } // If we're not in the config, we don't need to respond to heartbeats. if (_selfIndex == -1) { - LOG(1) << "Could not find ourself in current config so ignoring heartbeat from " << target - << " -- current config: " << _rsConfig.toBSON(); + LOGV2_DEBUG(21805, + 1, + "Could not find ourself in current config so ignoring heartbeat from {target} " + "-- current config: {rsConfig}", + "target"_attr = target, + "rsConfig"_attr = _rsConfig.toBSON()); HeartbeatResponseAction nextAction = HeartbeatResponseAction::makeNoAction(); nextAction.setNextHeartbeatStartDate(nextHeartbeatStartDate); return nextAction; } const int memberIndex = _rsConfig.findMemberIndexByHostAndPort(target); if (memberIndex == -1) { - LOG(1) << "Could not find " << target - << " in current config so ignoring --" - " current config: " - << _rsConfig.toBSON(); + LOGV2_DEBUG(21806, + 1, + "Could not find {target} in current config so ignoring --" + " current config: {rsConfig}", + "target"_attr = target, + "rsConfig"_attr = _rsConfig.toBSON()); HeartbeatResponseAction nextAction = HeartbeatResponseAction::makeNoAction(); nextAction.setNextHeartbeatStartDate(nextHeartbeatStartDate); return nextAction; @@ -816,13 +893,20 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse( else if (hbStats.failed() || (alreadyElapsed >= _rsConfig.getHeartbeatTimeoutPeriod())) { hbData.setDownValues(now, hbResponse.getStatus().reason()); } else { - LOG(3) << "Bad heartbeat response from " << target - << "; trying again; Retries left: " << (hbStats.retriesLeft()) << "; " - << alreadyElapsed << " have already elapsed"; + LOGV2_DEBUG(21807, + 3, + "Bad heartbeat response from {target}; trying again; Retries left: " + "{hbStats_retriesLeft}; {alreadyElapsed} have already elapsed", + "target"_attr = target, + "hbStats_retriesLeft"_attr = (hbStats.retriesLeft()), + "alreadyElapsed"_attr = alreadyElapsed); } } else { ReplSetHeartbeatResponse hbr = std::move(hbResponse.getValue()); - LOG(3) << "setUpValues: heartbeat response good for member _id:" << member.getId(); + LOGV2_DEBUG(21808, + 3, + "setUpValues: heartbeat response good for member _id:{member_getId}", + "member_getId"_attr = member.getId()); advancedOpTime = hbData.setUpValues(now, std::move(hbr)); } @@ -932,7 +1016,7 @@ HeartbeatResponseAction TopologyCoordinator::checkMemberTimeouts(Date_t now) { } } if (stepdown) { - log() << "can't see a majority of the set, relinquishing primary"; + LOGV2(21809, "can't see a majority of the set, relinquishing primary"); return HeartbeatResponseAction::makeStepDownSelfAction(_selfIndex); } return HeartbeatResponseAction::makeNoAction(); @@ -981,13 +1065,20 @@ std::pair<MemberId, Date_t> TopologyCoordinator::getStalestLiveMember() const { // Already stale. continue; } - LOG(3) << "memberData lastupdate is: " << memberData.getLastUpdate(); + LOGV2_DEBUG(21810, + 3, + "memberData lastupdate is: {memberData_getLastUpdate}", + "memberData_getLastUpdate"_attr = memberData.getLastUpdate()); if (earliestDate > memberData.getLastUpdate()) { earliestDate = memberData.getLastUpdate(); earliestMemberId = memberData.getMemberId(); } } - LOG(3) << "stalest member " << earliestMemberId << " date: " << earliestDate; + LOGV2_DEBUG(21811, + 3, + "stalest member {earliestMemberId} date: {earliestDate}", + "earliestMemberId"_attr = earliestMemberId, + "earliestDate"_attr = earliestDate); return std::make_pair(earliestMemberId, earliestDate); } @@ -1071,10 +1162,15 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up return false; } - LOG(2) << "received notification that node with memberID " << memberId - << " in config with version " << args.cfgver - << " has reached optime: " << args.appliedOpTime - << " and is durable through: " << args.durableOpTime; + LOGV2_DEBUG(21812, + 2, + "received notification that node with memberID {memberId} in config with version " + "{args_cfgver} has reached optime: {args_appliedOpTime} and is durable through: " + "{args_durableOpTime}", + "memberId"_attr = memberId, + "args_cfgver"_attr = args.cfgver, + "args_appliedOpTime"_attr = args.appliedOpTime, + "args_durableOpTime"_attr = args.durableOpTime); // If we're in FCV 4.4, allow replSetUpdatePosition commands between config versions. if (!serverGlobalParams.featureCompatibility.isVersion( @@ -1084,7 +1180,7 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up << "Received replSetUpdatePosition for node with memberId " << memberId << " whose config version of " << args.cfgver << " doesn't match our config version of " << _rsConfig.getConfigVersion(); - LOG(1) << errmsg; + LOGV2_DEBUG(21813, 1, "{errmsg}", "errmsg"_attr = errmsg); *configVersion = _rsConfig.getConfigVersion(); return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg); } @@ -1099,16 +1195,23 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up std::string errmsg = str::stream() << "Received replSetUpdatePosition for node with memberId " << memberId << " which doesn't exist in our config"; - LOG(1) << errmsg; + LOGV2_DEBUG(21814, 1, "{errmsg}", "errmsg"_attr = errmsg); return Status(ErrorCodes::NodeNotFound, errmsg); } invariant(memberId == memberData->getMemberId()); - LOG(3) << "Node with memberID " << memberId << " currently has optime " - << memberData->getLastAppliedOpTime() << " durable through " - << memberData->getLastDurableOpTime() << "; updating to optime " << args.appliedOpTime - << " and durable through " << args.durableOpTime; + LOGV2_DEBUG( + 21815, + 3, + "Node with memberID {memberId} currently has optime {memberData_getLastAppliedOpTime} " + "durable through {memberData_getLastDurableOpTime}; updating to optime " + "{args_appliedOpTime} and durable through {args_durableOpTime}", + "memberId"_attr = memberId, + "memberData_getLastAppliedOpTime"_attr = memberData->getLastAppliedOpTime(), + "memberData_getLastDurableOpTime"_attr = memberData->getLastDurableOpTime(), + "args_appliedOpTime"_attr = args.appliedOpTime, + "args_durableOpTime"_attr = args.durableOpTime); bool advancedOpTime = memberData->advanceLastAppliedOpTimeAndWallTime( {args.appliedOpTime, args.appliedWallTime}, now); @@ -1401,15 +1504,19 @@ void TopologyCoordinator::changeMemberState_forTest(const MemberState& newMember updateConfig(ReplSetConfig(), -1, Date_t()); break; default: - severe() << "Cannot switch to state " << newMemberState; + LOGV2_FATAL(21840, + "Cannot switch to state {newMemberState}", + "newMemberState"_attr = newMemberState); MONGO_UNREACHABLE; } if (getMemberState() != newMemberState.s) { - severe() << "Expected to enter state " << newMemberState << " but am now in " - << getMemberState(); + LOGV2_FATAL(21841, + "Expected to enter state {newMemberState} but am now in {getMemberState}", + "newMemberState"_attr = newMemberState, + "getMemberState"_attr = getMemberState()); MONGO_UNREACHABLE; } - log() << newMemberState; + LOGV2(21816, "{newMemberState}", "newMemberState"_attr = newMemberState); } void TopologyCoordinator::setCurrentPrimary_forTest(int primaryIndex, @@ -1823,13 +1930,13 @@ TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder* std::string msg = str::stream() << "cannot freeze node when primary or running for election. state: " << (_role == TopologyCoordinator::Role::kLeader ? "Primary" : "Running-Election"); - log() << msg; + LOGV2(21817, "{msg}", "msg"_attr = msg); return Status(ErrorCodes::NotSecondary, msg); } if (secs == 0) { _stepDownUntil = now; - log() << "'unfreezing'"; + LOGV2(21818, "'unfreezing'"); response->append("info", "unfreezing"); return PrepareFreezeResponseResult::kSingleNodeSelfElect; } else { @@ -1837,7 +1944,7 @@ TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder* response->append("warning", "you really want to freeze for only 1 second?"); _stepDownUntil = std::max(_stepDownUntil, now + Seconds(secs)); - log() << "'freezing' for " << secs << " seconds"; + LOGV2(21819, "'freezing' for {secs} seconds", "secs"_attr = secs); } return PrepareFreezeResponseResult::kNoAction; @@ -1914,7 +2021,10 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI // Reset term on startup. if (!_rsConfig.isInitialized()) { _term = OpTime::kInitialTerm; - LOG(1) << "Updated term in topology coordinator to " << _term << " due to new config"; + LOGV2_DEBUG(21820, + 1, + "Updated term in topology coordinator to {term} due to new config", + "term"_attr = _term); } _updateHeartbeatDataForReconfig(newConfig, selfIndex, now); @@ -1924,9 +2034,9 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI if (_role == Role::kLeader) { if (_selfIndex == -1) { - log() << "Could not remain primary because no longer a member of the replica set"; + LOGV2(21821, "Could not remain primary because no longer a member of the replica set"); } else if (!_selfConfig().isElectable()) { - log() << " Could not remain primary because no longer electable"; + LOGV2(21822, " Could not remain primary because no longer electable"); } else { // Don't stepdown if you don't have to. _currentPrimaryIndex = _selfIndex; @@ -2109,7 +2219,9 @@ std::string TopologyCoordinator::_getUnelectableReasonString(const UnelectableRe ss << "node is not a member of a valid replica set configuration"; } if (!hasWrittenToStream) { - severe() << "Invalid UnelectableReasonMask value 0x" << integerToHex(ur); + LOGV2_FATAL(21842, + "Invalid UnelectableReasonMask value 0x{integerToHex_ur}", + "integerToHex_ur"_attr = integerToHex(ur)); fassertFailed(26011); } ss << " (mask 0x" << integerToHex(ur) << ")"; @@ -2422,7 +2534,7 @@ void TopologyCoordinator::finishUnconditionalStepDown() { // two other nodes think they are primary (asynchronously polled) // -- wait for things to settle down. remotePrimaryIndex = -1; - warning() << "two remote primaries (transiently)"; + LOGV2_WARNING(21838, "two remote primaries (transiently)"); break; } remotePrimaryIndex = itIndex; @@ -2494,8 +2606,12 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim // This check is performed to ensure primaries do not commit an OpTime from a previous term. if (_iAmPrimary() && committedOpTime.opTime < _firstOpTimeOfMyTerm) { - LOG(1) << "Ignoring older committed snapshot from before I became primary, optime: " - << committedOpTime.opTime << ", firstOpTimeOfMyTerm: " << _firstOpTimeOfMyTerm; + LOGV2_DEBUG(21823, + 1, + "Ignoring older committed snapshot from before I became primary, optime: " + "{committedOpTime_opTime}, firstOpTimeOfMyTerm: {firstOpTimeOfMyTerm}", + "committedOpTime_opTime"_attr = committedOpTime.opTime, + "firstOpTimeOfMyTerm"_attr = _firstOpTimeOfMyTerm); return false; } @@ -2505,11 +2621,15 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim if (fromSyncSource) { committedOpTime = std::min(committedOpTime, getMyLastAppliedOpTimeAndWallTime()); } else { - LOG(1) << "Ignoring commit point with different term than my lastApplied, since it " - "may " - "not be on the same oplog branch as mine. optime: " - << committedOpTime - << ", my last applied: " << getMyLastAppliedOpTimeAndWallTime(); + LOGV2_DEBUG(21824, + 1, + "Ignoring commit point with different term than my lastApplied, since it " + "may " + "not be on the same oplog branch as mine. optime: {committedOpTime}, my " + "last applied: {getMyLastAppliedOpTimeAndWallTime}", + "committedOpTime"_attr = committedOpTime, + "getMyLastAppliedOpTimeAndWallTime"_attr = + getMyLastAppliedOpTimeAndWallTime()); return false; } } @@ -2519,12 +2639,19 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim } if (committedOpTime.opTime < _lastCommittedOpTimeAndWallTime.opTime) { - LOG(1) << "Ignoring older committed snapshot optime: " << committedOpTime - << ", currentCommittedOpTime: " << _lastCommittedOpTimeAndWallTime; + LOGV2_DEBUG(21825, + 1, + "Ignoring older committed snapshot optime: {committedOpTime}, " + "currentCommittedOpTime: {lastCommittedOpTimeAndWallTime}", + "committedOpTime"_attr = committedOpTime, + "lastCommittedOpTimeAndWallTime"_attr = _lastCommittedOpTimeAndWallTime); return false; } - LOG(2) << "Updating _lastCommittedOpTimeAndWallTime to " << committedOpTime; + LOGV2_DEBUG(21826, + 2, + "Updating _lastCommittedOpTimeAndWallTime to {committedOpTime}", + "committedOpTime"_attr = committedOpTime); _lastCommittedOpTimeAndWallTime = committedOpTime; return true; } @@ -2586,7 +2713,8 @@ TopologyCoordinator::UpdateTermResult TopologyCoordinator::updateTerm(long long if (_iAmPrimary()) { return TopologyCoordinator::UpdateTermResult::kTriggerStepDown; } - LOG(1) << "Updating term from " << _term << " to " << term; + LOGV2_DEBUG( + 21827, 1, "Updating term from {term} to {term2}", "term"_attr = _term, "term2"_attr = term); _term = term; return TopologyCoordinator::UpdateTermResult::kUpdatedTerm; } @@ -2611,15 +2739,17 @@ bool TopologyCoordinator::shouldChangeSyncSource( // progress, return true. if (_selfIndex == -1) { - log() << "Not choosing new sync source because we are not in the config."; + LOGV2(21828, "Not choosing new sync source because we are not in the config."); return false; } // If the user requested a sync source change, return true. if (_forceSyncSourceIndex != -1) { - log() << "Choosing new sync source because the user has requested to use " - << _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort() - << " as a sync source"; + LOGV2(21829, + "Choosing new sync source because the user has requested to use " + "{rsConfig_getMemberAt_forceSyncSourceIndex_getHostAndPort} as a sync source", + "rsConfig_getMemberAt_forceSyncSourceIndex_getHostAndPort"_attr = + _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort()); return true; } @@ -2628,9 +2758,13 @@ bool TopologyCoordinator::shouldChangeSyncSource( if (!serverGlobalParams.featureCompatibility.isVersion( ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44)) { if (replMetadata.getConfigVersion() != _rsConfig.getConfigVersion()) { - log() << "Choosing new sync source because the config version supplied by " - << currentSource << ", " << replMetadata.getConfigVersion() - << ", does not match ours, " << _rsConfig.getConfigVersion(); + LOGV2( + 21830, + "Choosing new sync source because the config version supplied by {currentSource}, " + "{replMetadata_getConfigVersion}, does not match ours, {rsConfig_getConfigVersion}", + "currentSource"_attr = currentSource, + "replMetadata_getConfigVersion"_attr = replMetadata.getConfigVersion(), + "rsConfig_getConfigVersion"_attr = _rsConfig.getConfigVersion()); return true; } } @@ -2639,8 +2773,9 @@ bool TopologyCoordinator::shouldChangeSyncSource( // from a node that is not in our config. const int currentSourceIndex = _rsConfig.findMemberIndexByHostAndPort(currentSource); if (currentSourceIndex == -1) { - log() << "Choosing new sync source because " << currentSource.toString() - << " is not in our config"; + LOGV2(21831, + "Choosing new sync source because {currentSource} is not in our config", + "currentSource"_attr = currentSource.toString()); return true; } @@ -2689,15 +2824,17 @@ bool TopologyCoordinator::shouldChangeSyncSource( } else { logMessage << " (sync source does not know the primary)"; } - log() << logMessage.str(); + LOGV2(21832, "{logMessage_str}", "logMessage_str"_attr = logMessage.str()); return true; } if (MONGO_unlikely(disableMaxSyncSourceLagSecs.shouldFail())) { - log() << "disableMaxSyncSourceLagSecs fail point enabled - not checking the most recent " - "OpTime, " - << currentSourceOpTime.toString() << ", of our current sync source, " << currentSource - << ", against the OpTimes of the other nodes in this replica set."; + LOGV2(21833, + "disableMaxSyncSourceLagSecs fail point enabled - not checking the most recent " + "OpTime, {currentSourceOpTime}, of our current sync source, {currentSource}, against " + "the OpTimes of the other nodes in this replica set.", + "currentSourceOpTime"_attr = currentSourceOpTime.toString(), + "currentSource"_attr = currentSource); } else { unsigned int currentSecs = currentSourceOpTime.getSecs(); unsigned int goalSecs = currentSecs + durationCount<Seconds>(_options.maxSyncSourceLagSecs); @@ -2711,13 +2848,19 @@ bool TopologyCoordinator::shouldChangeSyncSource( (candidateConfig.shouldBuildIndexes() || !_selfConfig().shouldBuildIndexes()) && it->getState().readable() && !_memberIsBlacklisted(candidateConfig, now) && goalSecs < it->getHeartbeatAppliedOpTime().getSecs()) { - log() << "Choosing new sync source because the most recent OpTime of our sync " - "source, " - << currentSource << ", is " << currentSourceOpTime.toString() - << " which is more than " << _options.maxSyncSourceLagSecs - << " behind member " << candidateConfig.getHostAndPort().toString() - << " whose most recent OpTime is " - << it->getHeartbeatAppliedOpTime().toString(); + LOGV2( + 21834, + "Choosing new sync source because the most recent OpTime of our sync " + "source, {currentSource}, is {currentSourceOpTime} which is more than " + "{options_maxSyncSourceLagSecs} behind member {candidateConfig_getHostAndPort} " + "whose most recent OpTime is {it_getHeartbeatAppliedOpTime}", + "currentSource"_attr = currentSource, + "currentSourceOpTime"_attr = currentSourceOpTime.toString(), + "options_maxSyncSourceLagSecs"_attr = _options.maxSyncSourceLagSecs, + "candidateConfig_getHostAndPort"_attr = + candidateConfig.getHostAndPort().toString(), + "it_getHeartbeatAppliedOpTime"_attr = + it->getHeartbeatAppliedOpTime().toString()); invariant(itIndex != _selfIndex); return true; } @@ -2751,7 +2894,7 @@ void TopologyCoordinator::processReplSetRequestVotes(const ReplSetRequestVotesAr response->setTerm(_term); if (MONGO_unlikely(voteNoInElection.shouldFail())) { - log() << "failpoint voteNoInElection enabled"; + LOGV2(21835, "failpoint voteNoInElection enabled"); response->setVoteGranted(false); response->setReason(str::stream() << "forced to vote no during dry run election due to " "failpoint voteNoInElection set"); @@ -2759,7 +2902,7 @@ void TopologyCoordinator::processReplSetRequestVotes(const ReplSetRequestVotesAr } if (MONGO_unlikely(voteYesInDryRunButNoInRealElection.shouldFail())) { - log() << "failpoint voteYesInDryRunButNoInRealElection enabled"; + LOGV2(21836, "failpoint voteYesInDryRunButNoInRealElection enabled"); if (args.isADryRun()) { response->setVoteGranted(true); response->setReason(str::stream() << "forced to vote yes in dry run due to failpoint " diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index 9fc313a6042..cf41b85b78d 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <iostream> @@ -42,10 +44,12 @@ #include "mongo/db/server_options.h" #include "mongo/executor/task_executor.h" #include "mongo/logger/logger.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" +#include "mongo/util/log.h" #include "mongo/util/log_global_settings.h" #include "mongo/util/net/hostandport.h" #include "mongo/util/scopeguard.h" @@ -1626,7 +1630,7 @@ TEST_F(TopoCoordTest, ReplSetGetStatus) { &resultStatus); ASSERT_OK(resultStatus); BSONObj rsStatus = statusBuilder.obj(); - unittest::log() << rsStatus; + LOGV2(21843, "{rsStatus}", "rsStatus"_attr = rsStatus); // Test results for all non-self members ASSERT_EQUALS(setName, rsStatus["set"].String()); @@ -1742,7 +1746,7 @@ TEST_F(TopoCoordTest, ReplSetGetStatus) { &resultStatus); ASSERT_OK(resultStatus); rsStatus = statusBuilder2.obj(); - unittest::log() << rsStatus; + LOGV2(21844, "{rsStatus}", "rsStatus"_attr = rsStatus); ASSERT_EQUALS(setName, rsStatus["set"].String()); ASSERT_FALSE(rsStatus.hasField("lastStableRecoveryTimestamp")); ASSERT_FALSE(rsStatus.hasField("electionCandidateMetrics")); diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index 83bbe54deb9..3d2f77905dc 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -45,6 +45,7 @@ #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/transaction_history_iterator.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -78,14 +79,20 @@ Status _applyOperationsForTransaction(OperationContext* opCtx, oplogApplicationMode == repl::OplogApplication::Mode::kRecovering); if (!ignoreException) { - LOG(1) << "Error applying operation in transaction. " << redact(ex) - << "- oplog entry: " << redact(op.toBSON()); + LOGV2_DEBUG(21845, + 1, + "Error applying operation in transaction. {ex}- oplog entry: {op}", + "ex"_attr = redact(ex), + "op"_attr = redact(op.toBSON())); return exceptionToStatus(); } - LOG(1) << "Encountered but ignoring error: " << redact(ex) - << " while applying operations for transaction because we are either in initial " - "sync or recovering mode - oplog entry: " - << redact(op.toBSON()); + LOGV2_DEBUG(21846, + 1, + "Encountered but ignoring error: {ex} while applying operations for " + "transaction because we are either in initial " + "sync or recovering mode - oplog entry: {op}", + "ex"_attr = redact(ex), + "op"_attr = redact(op.toBSON())); } } return Status::OK(); @@ -379,8 +386,10 @@ Status _applyPrepareTransaction(OperationContext* opCtx, auto ns = op.getNss(); auto uuid = *op.getUuid(); if (BackgroundOperation::inProgForNs(ns)) { - warning() << "blocking replication until index builds are finished on " - << redact(ns.toString()) << ", due to prepared transaction"; + LOGV2_WARNING(21849, + "blocking replication until index builds are finished on {ns}, due " + "to prepared transaction", + "ns"_attr = redact(ns.toString())); BackgroundOperation::awaitNoBgOpInProgForNs(ns); IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection(uuid); } @@ -411,7 +420,7 @@ Status _applyPrepareTransaction(OperationContext* opCtx, fassert(31137, status); if (MONGO_unlikely(applyOpsHangBeforePreparingTransaction.shouldFail())) { - LOG(0) << "Hit applyOpsHangBeforePreparingTransaction failpoint"; + LOGV2(21847, "Hit applyOpsHangBeforePreparingTransaction failpoint"); applyOpsHangBeforePreparingTransaction.pauseWhileSet(opCtx); } @@ -460,10 +469,11 @@ Status applyPrepareTransaction(OperationContext* opCtx, switch (mode) { case repl::OplogApplication::Mode::kRecovering: { if (!serverGlobalParams.enableMajorityReadConcern) { - error() - << "Cannot replay a prepared transaction when 'enableMajorityReadConcern' is " - "set to false. Restart the server with --enableMajorityReadConcern=true " - "to complete recovery."; + LOGV2_ERROR( + 21850, + "Cannot replay a prepared transaction when 'enableMajorityReadConcern' is " + "set to false. Restart the server with --enableMajorityReadConcern=true " + "to complete recovery."); fassertFailed(51146); } @@ -490,7 +500,7 @@ Status applyPrepareTransaction(OperationContext* opCtx, void reconstructPreparedTransactions(OperationContext* opCtx, repl::OplogApplication::Mode mode) { if (MONGO_unlikely(skipReconstructPreparedTransactions.shouldFail())) { - log() << "Hit skipReconstructPreparedTransactions failpoint"; + LOGV2(21848, "Hit skipReconstructPreparedTransactions failpoint"); return; } // Read the transactions table and the oplog collection without a timestamp. diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 25109941176..212b6d79713 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -46,6 +46,7 @@ #include "mongo/db/s/balancer/balancer_chunk_selection_policy_impl.h" #include "mongo/db/s/balancer/cluster_statistics_impl.h" #include "mongo/db/s/sharding_logging.h" +#include "mongo/logv2/log.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog_cache.h" @@ -157,7 +158,7 @@ void warnOnMultiVersion(const vector<ClusterStatistics::ShardStatistics>& cluste sb << stat.shardId << " is at " << stat.mongoVersion << "; "; } - warning() << sb.str(); + LOGV2_WARNING(21875, "{sb_str}", "sb_str"_attr = sb.str()); } } // namespace @@ -247,7 +248,10 @@ Status Balancer::rebalanceSingleChunk(OperationContext* opCtx, const ChunkType& auto migrateInfo = std::move(migrateStatus.getValue()); if (!migrateInfo) { - LOG(1) << "Unable to find more appropriate location for chunk " << redact(chunk.toString()); + LOGV2_DEBUG(21854, + 1, + "Unable to find more appropriate location for chunk {chunk}", + "chunk"_attr = redact(chunk.toString())); return Status::OK(); } @@ -307,14 +311,14 @@ void Balancer::_mainThread() { _state = kStopped; _joinCond.notify_all(); - LOG(1) << "Balancer thread terminated"; + LOGV2_DEBUG(21855, 1, "Balancer thread terminated"); }); Client::initThread("Balancer"); auto opCtx = cc().makeOperationContext(); auto shardingContext = Grid::get(opCtx.get()); - log() << "CSRS balancer is starting"; + LOGV2(21856, "CSRS balancer is starting"); { stdx::lock_guard<Latch> scopedLock(_mutex); @@ -327,9 +331,13 @@ void Balancer::_mainThread() { while (!_stopRequested()) { Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get()); if (!refreshStatus.isOK()) { - warning() << "Balancer settings could not be loaded and will be retried in " - << durationCount<Seconds>(kInitBackoffInterval) << " seconds" - << causedBy(refreshStatus); + LOGV2_WARNING( + 21876, + "Balancer settings could not be loaded and will be retried in " + "{durationCount_Seconds_kInitBackoffInterval} seconds{causedBy_refreshStatus}", + "durationCount_Seconds_kInitBackoffInterval"_attr = + durationCount<Seconds>(kInitBackoffInterval), + "causedBy_refreshStatus"_attr = causedBy(refreshStatus)); _sleepFor(opCtx.get(), kInitBackoffInterval); continue; @@ -338,13 +346,13 @@ void Balancer::_mainThread() { break; } - log() << "CSRS balancer thread is recovering"; + LOGV2(21857, "CSRS balancer thread is recovering"); _migrationManager.finishRecovery(opCtx.get(), balancerConfig->getMaxChunkSizeBytes(), balancerConfig->getSecondaryThrottle()); - log() << "CSRS balancer thread is recovered"; + LOGV2(21858, "CSRS balancer thread is recovered"); // Main balancer loop while (!_stopRequested()) { @@ -359,22 +367,28 @@ void Balancer::_mainThread() { Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get()); if (!refreshStatus.isOK()) { - warning() << "Skipping balancing round" << causedBy(refreshStatus); + LOGV2_WARNING(21877, + "Skipping balancing round{causedBy_refreshStatus}", + "causedBy_refreshStatus"_attr = causedBy(refreshStatus)); _endRound(opCtx.get(), kBalanceRoundDefaultInterval); continue; } if (!balancerConfig->shouldBalance()) { - LOG(1) << "Skipping balancing round because balancing is disabled"; + LOGV2_DEBUG(21859, 1, "Skipping balancing round because balancing is disabled"); _endRound(opCtx.get(), kBalanceRoundDefaultInterval); continue; } { - LOG(1) << "*** start balancing round. " - << "waitForDelete: " << balancerConfig->waitForDelete() - << ", secondaryThrottle: " - << balancerConfig->getSecondaryThrottle().toBSON(); + LOGV2_DEBUG( + 21860, + 1, + "*** start balancing round. waitForDelete: {balancerConfig_waitForDelete}, " + "secondaryThrottle: {balancerConfig_getSecondaryThrottle}", + "balancerConfig_waitForDelete"_attr = balancerConfig->waitForDelete(), + "balancerConfig_getSecondaryThrottle"_attr = + balancerConfig->getSecondaryThrottle().toBSON()); static Occasionally sampler; if (sampler.tick()) { @@ -383,16 +397,18 @@ void Balancer::_mainThread() { Status status = _enforceTagRanges(opCtx.get()); if (!status.isOK()) { - warning() << "Failed to enforce tag ranges" << causedBy(status); + LOGV2_WARNING(21878, + "Failed to enforce tag ranges{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } else { - LOG(1) << "Done enforcing tag range boundaries."; + LOGV2_DEBUG(21861, 1, "Done enforcing tag range boundaries."); } const auto candidateChunks = uassertStatusOK(_chunkSelectionPolicy->selectChunksToMove(opCtx.get())); if (candidateChunks.empty()) { - LOG(1) << "no need to move any chunk"; + LOGV2_DEBUG(21862, 1, "no need to move any chunk"); _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks(opCtx.get(), candidateChunks); @@ -405,7 +421,7 @@ void Balancer::_mainThread() { .ignore(); } - LOG(1) << "*** End of balancing round"; + LOGV2_DEBUG(21863, 1, "*** End of balancing round"); } Milliseconds balancerInterval = @@ -413,16 +429,19 @@ void Balancer::_mainThread() { overrideBalanceRoundInterval.execute([&](const BSONObj& data) { balancerInterval = Milliseconds(data["intervalMs"].numberInt()); - log() << "overrideBalanceRoundInterval: using shorter balancing interval: " - << balancerInterval; + LOGV2(21864, + "overrideBalanceRoundInterval: using shorter balancing interval: " + "{balancerInterval}", + "balancerInterval"_attr = balancerInterval); }); _endRound(opCtx.get(), balancerInterval); } catch (const DBException& e) { - log() << "caught exception while doing balance: " << e.what(); + LOGV2( + 21865, "caught exception while doing balance: {e_what}", "e_what"_attr = e.what()); // Just to match the opening statement if in log level 1 - LOG(1) << "*** End of balancing round"; + LOGV2_DEBUG(21866, 1, "*** End of balancing round"); // This round failed, tell the world! roundDetails.setFailed(e.what()); @@ -451,7 +470,7 @@ void Balancer::_mainThread() { _threadOperationContext = nullptr; } - log() << "CSRS balancer is now stopped"; + LOGV2(21867, "CSRS balancer is now stopped"); } bool Balancer::_stopRequested() { @@ -516,8 +535,11 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) { if (oids.count(x) == 0) { oids[x] = shardId; } else { - log() << "error: 2 machines have " << x << " as oid machine piece: " << shardId - << " and " << oids[x]; + LOGV2(21868, + "error: 2 machines have {x} as oid machine piece: {shardId} and {oids_x}", + "x"_attr = x, + "shardId"_attr = shardId, + "oids_x"_attr = oids[x]); result = uassertStatusOK(s->runCommandWithFixedRetryAttempts( opCtx, @@ -542,7 +564,7 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) { return false; } } else { - log() << "warning: oidMachine not set on: " << s->toString(); + LOGV2(21869, "warning: oidMachine not set on: {s}", "s"_attr = s->toString()); } } @@ -574,8 +596,11 @@ Status Balancer::_enforceTagRanges(OperationContext* opCtx) { ChunkRange(splitInfo.minKey, splitInfo.maxKey), splitInfo.splitKeys); if (!splitStatus.isOK()) { - warning() << "Failed to enforce tag range for chunk " << redact(splitInfo.toString()) - << causedBy(redact(splitStatus.getStatus())); + LOGV2_WARNING( + 21879, + "Failed to enforce tag range for chunk {splitInfo}{causedBy_splitStatus_getStatus}", + "splitInfo"_attr = redact(splitInfo.toString()), + "causedBy_splitStatus_getStatus"_attr = causedBy(redact(splitStatus.getStatus()))); } } @@ -588,7 +613,7 @@ int Balancer::_moveChunks(OperationContext* opCtx, // If the balancer was disabled since we started this round, don't start new chunk moves if (_stopRequested() || !balancerConfig->shouldBalance()) { - LOG(1) << "Skipping balancing round because balancer was stopped"; + LOGV2_DEBUG(21870, 1, "Skipping balancing round because balancer was stopped"); return 0; } @@ -626,15 +651,20 @@ int Balancer::_moveChunks(OperationContext* opCtx, if (status == ErrorCodes::ChunkTooBig || status == ErrorCodes::ExceededMemoryLimit) { numChunksProcessed++; - log() << "Performing a split because migration " << redact(requestIt->toString()) - << " failed for size reasons" << causedBy(redact(status)); + LOGV2(21871, + "Performing a split because migration {requestIt} failed for size " + "reasons{causedBy_status}", + "requestIt"_attr = redact(requestIt->toString()), + "causedBy_status"_attr = causedBy(redact(status))); _splitOrMarkJumbo(opCtx, requestIt->nss, requestIt->minKey); continue; } - log() << "Balancer move " << redact(requestIt->toString()) << " failed" - << causedBy(redact(status)); + LOGV2(21872, + "Balancer move {requestIt} failed{causedBy_status}", + "requestIt"_attr = redact(requestIt->toString()), + "causedBy_status"_attr = causedBy(redact(status))); } return numChunksProcessed; @@ -660,7 +690,8 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx, boost::none)); if (splitPoints.empty()) { - log() << "Marking chunk " << redact(chunk.toString()) << " as jumbo."; + LOGV2( + 21873, "Marking chunk {chunk} as jumbo.", "chunk"_attr = redact(chunk.toString())); chunk.markAsJumbo(); auto status = Grid::get(opCtx)->catalogClient()->updateConfigDocument( @@ -671,9 +702,12 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx, false, ShardingCatalogClient::kMajorityWriteConcern); if (!status.isOK()) { - log() << "Couldn't set jumbo for chunk with namespace " << redact(nss.ns()) - << " and min key " << redact(chunk.getMin()) - << causedBy(redact(status.getStatus())); + LOGV2(21874, + "Couldn't set jumbo for chunk with namespace {nss_ns} and min key " + "{chunk_getMin}{causedBy_status_getStatus}", + "nss_ns"_attr = redact(nss.ns()), + "chunk_getMin"_attr = redact(chunk.getMin()), + "causedBy_status_getStatus"_attr = causedBy(redact(status.getStatus()))); } return; diff --git a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp index f387556b02b..9f50b4f5169 100644 --- a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp +++ b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp @@ -39,6 +39,7 @@ #include "mongo/base/status_with.h" #include "mongo/bson/bsonobj_comparator_interface.h" +#include "mongo/logv2/log.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_collection.h" @@ -218,8 +219,12 @@ StatusWith<SplitInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToSpli // Namespace got dropped before we managed to get to it, so just skip it continue; } else if (!candidatesStatus.isOK()) { - warning() << "Unable to enforce tag range policy for collection " << nss.ns() - << causedBy(candidatesStatus.getStatus()); + LOGV2_WARNING(21852, + "Unable to enforce tag range policy for collection " + "{nss_ns}{causedBy_candidatesStatus_getStatus}", + "nss_ns"_attr = nss.ns(), + "causedBy_candidatesStatus_getStatus"_attr = + causedBy(candidatesStatus.getStatus())); continue; } @@ -282,7 +287,8 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToMo const NamespaceString nss(coll.getNs()); if (!coll.getAllowBalance()) { - LOG(1) << "Not balancing collection " << nss << "; explicitly disabled."; + LOGV2_DEBUG( + 21851, 1, "Not balancing collection {nss}; explicitly disabled.", "nss"_attr = nss); continue; } @@ -292,8 +298,12 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToMo // Namespace got dropped before we managed to get to it, so just skip it continue; } else if (!candidatesStatus.isOK()) { - warning() << "Unable to balance collection " << nss.ns() - << causedBy(candidatesStatus.getStatus()); + LOGV2_WARNING( + 21853, + "Unable to balance collection {nss_ns}{causedBy_candidatesStatus_getStatus}", + "nss_ns"_attr = nss.ns(), + "causedBy_candidatesStatus_getStatus"_attr = + causedBy(candidatesStatus.getStatus())); continue; } diff --git a/src/mongo/db/s/balancer/balancer_policy.cpp b/src/mongo/db/s/balancer/balancer_policy.cpp index 022379992f0..44e3f1302b5 100644 --- a/src/mongo/db/s/balancer/balancer_policy.cpp +++ b/src/mongo/db/s/balancer/balancer_policy.cpp @@ -36,6 +36,7 @@ #include <random> #include "mongo/db/s/balancer/type_migration.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/util/fail_point.h" @@ -342,8 +343,11 @@ MigrateInfo chooseRandomMigration(const ShardStatisticsVector& shardStats, const int destIndex = indices[choice]; const auto& destShardId = shardStats[destIndex].shardId; - LOG(1) << "balancerShouldReturnRandomMigrations: source: " << sourceShardId - << " dest: " << destShardId; + LOGV2_DEBUG(21880, + 1, + "balancerShouldReturnRandomMigrations: source: {sourceShardId} dest: {destShardId}", + "sourceShardId"_attr = sourceShardId, + "destShardId"_attr = destShardId); const auto& chunks = distribution.getChunks(sourceShardId); @@ -361,7 +365,7 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt if (MONGO_unlikely(balancerShouldReturnRandomMigrations.shouldFail()) && !distribution.nss().isConfigDB()) { - LOG(1) << "balancerShouldReturnRandomMigrations failpoint is set"; + LOGV2_DEBUG(21881, 1, "balancerShouldReturnRandomMigrations failpoint is set"); if (shardStats.size() < 2) return migrations; @@ -402,8 +406,10 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations.empty()) { - warning() << "Chunk " << redact(chunk.toString()) - << " is on a draining shard, but no appropriate recipient found"; + LOGV2_WARNING(21889, + "Chunk {chunk} is on a draining shard, but no appropriate " + "recipient found", + "chunk"_attr = redact(chunk.toString())); } continue; } @@ -417,8 +423,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt } if (migrations.empty()) { - warning() << "Unable to find any chunk to move from draining shard " << stat.shardId - << ". numJumboChunks: " << numJumboChunks; + LOGV2_WARNING(21890, + "Unable to find any chunk to move from draining shard " + "{stat_shardId}. numJumboChunks: {numJumboChunks}", + "stat_shardId"_attr = stat.shardId, + "numJumboChunks"_attr = numJumboChunks); } } } @@ -441,8 +450,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt continue; if (chunk.getJumbo()) { - warning() << "Chunk " << redact(chunk.toString()) << " violates zone " - << redact(tag) << ", but it is jumbo and cannot be moved"; + LOGV2_WARNING( + 21891, + "Chunk {chunk} violates zone {tag}, but it is jumbo and cannot be moved", + "chunk"_attr = redact(chunk.toString()), + "tag"_attr = redact(tag)); continue; } @@ -450,8 +462,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations.empty()) { - warning() << "Chunk " << redact(chunk.toString()) << " violates zone " - << redact(tag) << ", but no appropriate recipient found"; + LOGV2_WARNING( + 21892, + "Chunk {chunk} violates zone {tag}, but no appropriate recipient found", + "chunk"_attr = redact(chunk.toString()), + "tag"_attr = redact(tag)); } continue; } @@ -490,10 +505,14 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt // should not be possible so warn the operator to correct it. if (totalNumberOfShardsWithTag == 0) { if (!tag.empty()) { - warning() << "Zone " << redact(tag) << " in collection " << distribution.nss() - << " has no assigned shards and chunks which fall into it cannot be " - "balanced. This should be corrected by either assigning shards to the " - "zone or by deleting it."; + LOGV2_WARNING( + 21893, + "Zone {tag} in collection {distribution_nss} has no assigned shards and chunks " + "which fall into it cannot be " + "balanced. This should be corrected by either assigning shards to the " + "zone or by deleting it.", + "tag"_attr = redact(tag), + "distribution_nss"_attr = distribution.nss()); } continue; } @@ -552,7 +571,7 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, const ShardId to = _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations->empty()) { - log() << "No available shards to take chunks for zone [" << tag << "]"; + LOGV2(21882, "No available shards to take chunks for zone [{tag}]", "tag"_attr = tag); } return false; } @@ -565,12 +584,22 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, const size_t imbalance = max - idealNumberOfChunksPerShardForTag; - LOG(1) << "collection : " << distribution.nss().ns(); - LOG(1) << "zone : " << tag; - LOG(1) << "donor : " << from << " chunks on " << max; - LOG(1) << "receiver : " << to << " chunks on " << min; - LOG(1) << "ideal : " << idealNumberOfChunksPerShardForTag; - LOG(1) << "threshold : " << kDefaultImbalanceThreshold; + LOGV2_DEBUG(21883, + 1, + "collection : {distribution_nss_ns}", + "distribution_nss_ns"_attr = distribution.nss().ns()); + LOGV2_DEBUG(21884, 1, "zone : {tag}", "tag"_attr = tag); + LOGV2_DEBUG( + 21885, 1, "donor : {from} chunks on {max}", "from"_attr = from, "max"_attr = max); + LOGV2_DEBUG(21886, 1, "receiver : {to} chunks on {min}", "to"_attr = to, "min"_attr = min); + LOGV2_DEBUG(21887, + 1, + "ideal : {idealNumberOfChunksPerShardForTag}", + "idealNumberOfChunksPerShardForTag"_attr = idealNumberOfChunksPerShardForTag); + LOGV2_DEBUG(21888, + 1, + "threshold : {kDefaultImbalanceThreshold}", + "kDefaultImbalanceThreshold"_attr = kDefaultImbalanceThreshold); // Check whether it is necessary to balance within this zone if (imbalance < kDefaultImbalanceThreshold) @@ -596,9 +625,13 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, } if (numJumboChunks) { - warning() << "Shard: " << from << ", collection: " << distribution.nss().ns() - << " has only jumbo chunks for zone \'" << tag - << "\' and cannot be balanced. Jumbo chunks count: " << numJumboChunks; + LOGV2_WARNING(21894, + "Shard: {from}, collection: {distribution_nss_ns} has only jumbo chunks for " + "zone \'{tag}\' and cannot be balanced. Jumbo chunks count: {numJumboChunks}", + "from"_attr = from, + "distribution_nss_ns"_attr = distribution.nss().ns(), + "tag"_attr = tag, + "numJumboChunks"_attr = numJumboChunks); } return false; diff --git a/src/mongo/db/s/balancer/cluster_statistics_impl.cpp b/src/mongo/db/s/balancer/cluster_statistics_impl.cpp index 9fd3ebf675d..73e47dd5c9d 100644 --- a/src/mongo/db/s/balancer/cluster_statistics_impl.cpp +++ b/src/mongo/db/s/balancer/cluster_statistics_impl.cpp @@ -38,6 +38,7 @@ #include "mongo/base/status_with.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/client/read_preference.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" @@ -141,8 +142,12 @@ StatusWith<std::vector<ShardStatistics>> ClusterStatisticsImpl::getStats(Operati } else { // Since the mongod version is only used for reporting, there is no need to fail the // entire round if it cannot be retrieved, so just leave it empty - log() << "Unable to obtain shard version for " << shard.getName() - << causedBy(mongoDVersionStatus.getStatus()); + LOGV2(21895, + "Unable to obtain shard version for " + "{shard_getName}{causedBy_mongoDVersionStatus_getStatus}", + "shard_getName"_attr = shard.getName(), + "causedBy_mongoDVersionStatus_getStatus"_attr = + causedBy(mongoDVersionStatus.getStatus())); } std::set<std::string> shardTags; diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp index ae0997fa9de..a14202c643d 100644 --- a/src/mongo/db/s/balancer/migration_manager.cpp +++ b/src/mongo/db/s/balancer/migration_manager.cpp @@ -44,6 +44,7 @@ #include "mongo/db/s/balancer/scoped_migration_request.h" #include "mongo/db/s/balancer/type_migration.h" #include "mongo/executor/task_executor_pool.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" @@ -234,9 +235,12 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx) boost::none); if (!statusWithMigrationsQueryResponse.isOK()) { - log() << "Unable to read config.migrations collection documents for balancer migration" - << " recovery. Abandoning balancer recovery." - << causedBy(redact(statusWithMigrationsQueryResponse.getStatus())); + LOGV2(21896, + "Unable to read config.migrations collection documents for balancer migration " + "recovery. Abandoning balancer " + "recovery.{causedBy_statusWithMigrationsQueryResponse_getStatus}", + "causedBy_statusWithMigrationsQueryResponse_getStatus"_attr = + causedBy(redact(statusWithMigrationsQueryResponse.getStatus()))); return; } @@ -246,9 +250,13 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx) // The format of this migration document is incorrect. The balancer holds a distlock for // this migration, but without parsing the migration document we cannot identify which // distlock must be released. So we must release all distlocks. - log() << "Unable to parse config.migrations document '" << redact(migration.toString()) - << "' for balancer migration recovery. Abandoning balancer recovery." - << causedBy(redact(statusWithMigrationType.getStatus())); + LOGV2(21897, + "Unable to parse config.migrations document '{migration}' for balancer migration " + "recovery. Abandoning balancer " + "recovery.{causedBy_statusWithMigrationType_getStatus}", + "migration"_attr = redact(migration.toString()), + "causedBy_statusWithMigrationType_getStatus"_attr = + causedBy(redact(statusWithMigrationType.getStatus()))); return; } MigrationType migrateType = std::move(statusWithMigrationType.getValue()); @@ -265,11 +273,13 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx) auto statusWithDistLockHandle = distLockManager->tryLockWithLocalWriteConcern( opCtx, migrateType.getNss().ns(), whyMessage, _lockSessionID); if (!statusWithDistLockHandle.isOK()) { - log() << "Failed to acquire distributed lock for collection '" - << migrateType.getNss().ns() - << "' during balancer recovery of an active migration. Abandoning" - << " balancer recovery." - << causedBy(redact(statusWithDistLockHandle.getStatus())); + LOGV2(21898, + "Failed to acquire distributed lock for collection '{migrateType_getNss_ns}' " + "during balancer recovery of an active migration. Abandoning balancer " + "recovery.{causedBy_statusWithDistLockHandle_getStatus}", + "migrateType_getNss_ns"_attr = migrateType.getNss().ns(), + "causedBy_statusWithDistLockHandle_getStatus"_attr = + causedBy(redact(statusWithDistLockHandle.getStatus()))); return; } } @@ -320,9 +330,12 @@ void MigrationManager::finishRecovery(OperationContext* opCtx, // This shouldn't happen because the collection was intact and sharded when the previous // config primary was active and the dist locks have been held by the balancer // throughout. Abort migration recovery. - log() << "Unable to reload chunk metadata for collection '" << nss - << "' during balancer recovery. Abandoning recovery." - << causedBy(redact(routingInfoStatus.getStatus())); + LOGV2(21899, + "Unable to reload chunk metadata for collection '{nss}' during balancer " + "recovery. Abandoning recovery.{causedBy_routingInfoStatus_getStatus}", + "nss"_attr = nss, + "causedBy_routingInfoStatus_getStatus"_attr = + causedBy(redact(routingInfoStatus.getStatus()))); return; } diff --git a/src/mongo/db/s/balancer/scoped_migration_request.cpp b/src/mongo/db/s/balancer/scoped_migration_request.cpp index 3333b5f3ab8..b06cb1fa9f0 100644 --- a/src/mongo/db/s/balancer/scoped_migration_request.cpp +++ b/src/mongo/db/s/balancer/scoped_migration_request.cpp @@ -35,6 +35,7 @@ #include "mongo/db/s/balancer/type_migration.h" #include "mongo/db/write_concern_options.h" +#include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -68,8 +69,11 @@ ScopedMigrationRequest::~ScopedMigrationRequest() { _opCtx, MigrationType::ConfigNS, migrationDocumentIdentifier, kMajorityWriteConcern); if (!result.isOK()) { - LOG(0) << "Failed to remove config.migrations document for migration '" - << migrationDocumentIdentifier.toString() << "'" << causedBy(redact(result)); + LOGV2(21900, + "Failed to remove config.migrations document for migration " + "'{migrationDocumentIdentifier}'{causedBy_result}", + "migrationDocumentIdentifier"_attr = migrationDocumentIdentifier.toString(), + "causedBy_result"_attr = causedBy(redact(result))); } } @@ -141,10 +145,13 @@ StatusWith<ScopedMigrationRequest> ScopedMigrationRequest::writeMigration( MigrateInfo activeMigrateInfo = statusWithActiveMigration.getValue().toMigrateInfo(); if (activeMigrateInfo.to != migrateInfo.to || activeMigrateInfo.from != migrateInfo.from) { - log() << "Failed to write document '" << redact(migrateInfo.toString()) - << "' to config.migrations because there is already an active migration for" - << " that chunk: '" << redact(activeMigrateInfo.toString()) << "'." - << causedBy(redact(result)); + LOGV2(21901, + "Failed to write document '{migrateInfo}' to config.migrations because there " + "is already an active migration for that chunk: " + "'{activeMigrateInfo}'.{causedBy_result}", + "migrateInfo"_attr = redact(migrateInfo.toString()), + "activeMigrateInfo"_attr = redact(activeMigrateInfo.toString()), + "causedBy_result"_attr = causedBy(redact(result))); return result; } @@ -195,8 +202,12 @@ Status ScopedMigrationRequest::tryToRemoveMigration() { void ScopedMigrationRequest::keepDocumentOnDestruct() { invariant(_opCtx); _opCtx = nullptr; - LOG(1) << "Keeping config.migrations document with namespace '" << _nss << "' and minKey '" - << _minKey << "' for balancer recovery"; + LOGV2_DEBUG(21902, + 1, + "Keeping config.migrations document with namespace '{nss}' and minKey '{minKey}' " + "for balancer recovery", + "nss"_attr = _nss, + "minKey"_attr = _minKey); } } // namespace mongo diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp index f49d08743a7..3c420e838fb 100644 --- a/src/mongo/db/s/chunk_splitter.cpp +++ b/src/mongo/db/s/chunk_splitter.cpp @@ -44,6 +44,7 @@ #include "mongo/db/s/split_chunk.h" #include "mongo/db/s/split_vector.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog_cache.h" @@ -204,8 +205,11 @@ bool isAutoBalanceEnabled(OperationContext* opCtx, auto collStatus = Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss); if (!collStatus.isOK()) { - log() << "Auto-split for " << nss << " failed to load collection metadata" - << causedBy(redact(collStatus.getStatus())); + LOGV2(21903, + "Auto-split for {nss} failed to load collection " + "metadata{causedBy_collStatus_getStatus}", + "nss"_attr = nss, + "causedBy_collStatus_getStatus"_attr = causedBy(redact(collStatus.getStatus()))); return false; } @@ -245,7 +249,7 @@ void ChunkSplitter::onStepUp() { } _isPrimary = true; - log() << "The ChunkSplitter has started and will accept autosplit tasks."; + LOGV2(21904, "The ChunkSplitter has started and will accept autosplit tasks."); } void ChunkSplitter::onStepDown() { @@ -255,8 +259,9 @@ void ChunkSplitter::onStepDown() { } _isPrimary = false; - log() << "The ChunkSplitter has stopped and will no longer run new autosplit tasks. Any " - << "autosplit tasks that have already started will be allowed to finish."; + LOGV2(21905, + "The ChunkSplitter has stopped and will no longer run new autosplit tasks. Any autosplit " + "tasks that have already started will be allowed to finish."); } void ChunkSplitter::waitForIdle() { @@ -312,9 +317,13 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp const uint64_t maxChunkSizeBytes = balancerConfig->getMaxChunkSizeBytes(); - LOG(1) << "about to initiate autosplit: " << redact(chunk.toString()) - << " dataWritten since last check: " << dataWritten - << " maxChunkSizeBytes: " << maxChunkSizeBytes; + LOGV2_DEBUG(21906, + 1, + "about to initiate autosplit: {chunk} dataWritten since last check: " + "{dataWritten} maxChunkSizeBytes: {maxChunkSizeBytes}", + "chunk"_attr = redact(chunk.toString()), + "dataWritten"_attr = dataWritten, + "maxChunkSizeBytes"_attr = maxChunkSizeBytes); chunkSplitStateDriver->prepareSplit(); auto splitPoints = uassertStatusOK(splitVector(opCtx.get(), @@ -328,9 +337,11 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp maxChunkSizeBytes)); if (splitPoints.empty()) { - LOG(1) - << "ChunkSplitter attempted split but not enough split points were found for chunk " - << redact(chunk.toString()); + LOGV2_DEBUG(21907, + 1, + "ChunkSplitter attempted split but not enough split points were found for " + "chunk {chunk}", + "chunk"_attr = redact(chunk.toString())); // Reset our size estimate that we had prior to splitVector to 0, while still counting // the bytes that have been written in parallel to this split task chunkSplitStateDriver->abandonPrepare(); @@ -377,12 +388,19 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp const bool shouldBalance = isAutoBalanceEnabled(opCtx.get(), nss, balancerConfig); - log() << "autosplitted " << nss << " chunk: " << redact(chunk.toString()) << " into " - << (splitPoints.size() + 1) << " parts (maxChunkSizeBytes " << maxChunkSizeBytes - << ")" - << (topChunkMinKey.isEmpty() ? "" - : " (top chunk migration suggested" + - (std::string)(shouldBalance ? ")" : ", but no migrations allowed)")); + LOGV2( + 21908, + "autosplitted {nss} chunk: {chunk} into {splitPoints_size_1} parts (maxChunkSizeBytes " + "{maxChunkSizeBytes}){topChunkMinKey_isEmpty_top_chunk_migration_suggested_std_string_" + "shouldBalance_but_no_migrations_allowed}", + "nss"_attr = nss, + "chunk"_attr = redact(chunk.toString()), + "splitPoints_size_1"_attr = (splitPoints.size() + 1), + "maxChunkSizeBytes"_attr = maxChunkSizeBytes, + "topChunkMinKey_isEmpty_top_chunk_migration_suggested_std_string_shouldBalance_but_no_migrations_allowed"_attr = + (topChunkMinKey.isEmpty() ? "" + : " (top chunk migration suggested" + + (std::string)(shouldBalance ? ")" : ", but no migrations allowed)"))); // Because the ShardServerOpObserver uses the metadata from the CSS for tracking incoming // writes, if we split a chunk but do not force a CSS refresh, subsequent inserts will see @@ -403,13 +421,20 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp // assumption that succeeding inserts will fall on the top chunk. moveChunk(opCtx.get(), nss, topChunkMinKey); } catch (const DBException& ex) { - log() << "Top-chunk optimization failed to move chunk " - << redact(ChunkRange(min, max).toString()) << " in collection " << nss - << " after a successful split" << causedBy(redact(ex.toStatus())); + LOGV2(21909, + "Top-chunk optimization failed to move chunk {ChunkRange_min_max} in collection " + "{nss} after a successful split{causedBy_ex_toStatus}", + "ChunkRange_min_max"_attr = redact(ChunkRange(min, max).toString()), + "nss"_attr = nss, + "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus()))); } } catch (const DBException& ex) { - log() << "Unable to auto-split chunk " << redact(ChunkRange(min, max).toString()) - << " in namespace " << nss << causedBy(redact(ex.toStatus())); + LOGV2(21910, + "Unable to auto-split chunk {ChunkRange_min_max} in namespace " + "{nss}{causedBy_ex_toStatus}", + "ChunkRange_min_max"_attr = redact(ChunkRange(min, max).toString()), + "nss"_attr = nss, + "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus()))); } } diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index 444fd536a50..b7b565f6726 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -48,6 +48,7 @@ #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/s/request_types/migration_secondary_throttle_options.h" #include "mongo/util/log.h" @@ -80,8 +81,9 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, auto* const css = CollectionShardingRuntime::get(opCtx, ns); const auto metadata = css->getCurrentMetadata(); if (!metadata->isSharded()) { - LOG(0) << "skipping orphaned data cleanup for " << ns.ns() - << ", collection is not sharded"; + LOGV2(21911, + "skipping orphaned data cleanup for {ns_ns}, collection is not sharded", + "ns_ns"_attr = ns.ns()); return CleanupResult::kDone; } @@ -92,7 +94,7 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, << "could not cleanup orphaned data, start key " << startingFromKey << " does not match shard key pattern " << keyPattern; - log() << *errMsg; + LOGV2(21912, "{errMsg}", "errMsg"_attr = *errMsg); return CleanupResult::kError; } } else { @@ -101,8 +103,12 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, targetRange = css->getNextOrphanRange(startingFromKey); if (!targetRange) { - LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from " - << redact(startingFromKey) << ", no orphan ranges remain"; + LOGV2_DEBUG(21913, + 1, + "cleanupOrphaned requested for {ns} starting from {startingFromKey}, no " + "orphan ranges remain", + "ns"_attr = ns.toString(), + "startingFromKey"_attr = redact(startingFromKey)); return CleanupResult::kDone; } @@ -115,16 +121,21 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, // Sleep waiting for our own deletion. We don't actually care about any others, so there is no // need to call css::waitForClean() here. - LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from " - << redact(startingFromKey) << ", removing next orphan range " - << redact(targetRange->toString()) << "; waiting..."; + LOGV2_DEBUG(21914, + 1, + "cleanupOrphaned requested for {ns} starting from {startingFromKey}, removing next " + "orphan range {targetRange}; waiting...", + "ns"_attr = ns.toString(), + "startingFromKey"_attr = redact(startingFromKey), + "targetRange"_attr = redact(targetRange->toString())); Status result = cleanupCompleteFuture.getNoThrow(opCtx); - LOG(1) << "Finished waiting for last " << ns.toString() << " orphan range cleanup"; + LOGV2_DEBUG( + 21915, 1, "Finished waiting for last {ns} orphan range cleanup", "ns"_attr = ns.toString()); if (!result.isOK()) { - log() << redact(result.reason()); + LOGV2(21916, "{result_reason}", "result_reason"_attr = redact(result.reason())); *errMsg = result.reason(); return CleanupResult::kError; } diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index f5d679b83b4..d2ce632ad95 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -39,6 +39,7 @@ #include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/util/duration.h" #include "mongo/util/log.h" @@ -205,7 +206,10 @@ void CollectionShardingRuntime::setFilteringMetadata(OperationContext* opCtx, stdx::lock_guard lk(_metadataManagerLock); if (!newMetadata.isSharded()) { - LOG(0) << "Marking collection " << _nss.ns() << " as " << newMetadata.toStringBasic(); + LOGV2(21917, + "Marking collection {nss_ns} as {newMetadata_Basic}", + "nss_ns"_attr = _nss.ns(), + "newMetadata_Basic"_attr = newMetadata.toStringBasic()); _metadataType = MetadataType::kUnsharded; _metadataManager.reset(); ++_numMetadataManagerChanges; @@ -269,13 +273,18 @@ Status CollectionShardingRuntime::waitForClean(OperationContext* opCtx, stillScheduled = self->_metadataManager->trackOrphanedDataCleanup(orphanRange); if (!stillScheduled) { - log() << "Finished deleting " << nss.ns() << " range " - << redact(orphanRange.toString()); + LOGV2(21918, + "Finished deleting {nss_ns} range {orphanRange}", + "nss_ns"_attr = nss.ns(), + "orphanRange"_attr = redact(orphanRange.toString())); return Status::OK(); } } - log() << "Waiting for deletion of " << nss.ns() << " range " << orphanRange; + LOGV2(21919, + "Waiting for deletion of {nss_ns} range {orphanRange}", + "nss_ns"_attr = nss.ns(), + "orphanRange"_attr = orphanRange); Status result = stillScheduled->getNoThrow(opCtx); diff --git a/src/mongo/db/s/config/configsvr_add_shard_command.cpp b/src/mongo/db/s/config/configsvr_add_shard_command.cpp index bf61721b30f..6f6b449b0cf 100644 --- a/src/mongo/db/s/config/configsvr_add_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_add_shard_command.cpp @@ -42,6 +42,7 @@ #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/config/sharding_catalog_manager.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/add_shard_request_type.h" @@ -129,8 +130,10 @@ public: parsedRequest.hasMaxSize() ? parsedRequest.getMaxSize() : kMaxSizeMBDefault); if (!addShardResult.isOK()) { - log() << "addShard request '" << parsedRequest << "'" - << "failed" << causedBy(addShardResult.getStatus()); + LOGV2(21920, + "addShard request '{parsedRequest}'failed{causedBy_addShardResult_getStatus}", + "parsedRequest"_attr = parsedRequest, + "causedBy_addShardResult_getStatus"_attr = causedBy(addShardResult.getStatus())); uassertStatusOK(addShardResult.getStatus()); } diff --git a/src/mongo/db/s/config/configsvr_move_primary_command.cpp b/src/mongo/db/s/config/configsvr_move_primary_command.cpp index fe5c843303e..1595d7fdcdd 100644 --- a/src/mongo/db/s/config/configsvr_move_primary_command.cpp +++ b/src/mongo/db/s/config/configsvr_move_primary_command.cpp @@ -44,6 +44,7 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/s/config/sharding_catalog_manager.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" @@ -158,8 +159,13 @@ public: const auto toShard = [&]() { auto toShardStatus = shardRegistry->getShard(opCtx, to); if (!toShardStatus.isOK()) { - log() << "Could not move database '" << dbname << "' to shard '" << to - << causedBy(toShardStatus.getStatus()); + LOGV2(21921, + "Could not move database '{dbname}' to shard " + "'{to}{causedBy_toShardStatus_getStatus}", + "dbname"_attr = dbname, + "to"_attr = to, + "causedBy_toShardStatus_getStatus"_attr = + causedBy(toShardStatus.getStatus())); uassertStatusOKWithContext(toShardStatus.getStatus(), str::stream() << "Could not move database '" << dbname << "' to shard '" << to << "'"); diff --git a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp index 3b6a9337014..3d862d632d1 100644 --- a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp +++ b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp @@ -38,6 +38,7 @@ #include "mongo/db/s/config/sharding_catalog_manager.h" #include "mongo/db/s/shard_key_util.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/dist_lock_manager.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/refine_collection_shard_key_gen.h" @@ -148,7 +149,9 @@ public: collType.getUnique(), false); // createIndexIfPossible - LOG(0) << "CMD: refineCollectionShardKey: " << request().toBSON({}); + LOGV2(21922, + "CMD: refineCollectionShardKey: {request}", + "request"_attr = request().toBSON({})); audit::logRefineCollectionShardKey(opCtx->getClient(), nss.ns(), proposedKey); diff --git a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp index 9fd9e7298b4..2b3cfc9a1ae 100644 --- a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp @@ -42,6 +42,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/s/config/sharding_catalog_manager.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" @@ -116,7 +117,7 @@ public: try { return shardingCatalogManager->removeShard(opCtx, shardId); } catch (const DBException& ex) { - LOG(0) << "Failed to remove shard due to " << redact(ex); + LOGV2(21923, "Failed to remove shard due to {ex}", "ex"_attr = redact(ex)); throw; } }(); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 38ef0df3f11..b1d23be5b0c 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -56,6 +56,7 @@ #include "mongo/db/s/sharding_logging.h" #include "mongo/executor/network_interface.h" #include "mongo/executor/task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/sharding_catalog_client_impl.h" @@ -421,15 +422,16 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names BSONObj(), ShardingCatalogClient::kMajorityWriteConcern)); - LOG(1) << "dropCollection " << nss.ns() << " started"; + LOGV2_DEBUG(21924, 1, "dropCollection {nss_ns} started", "nss_ns"_attr = nss.ns()); sendDropCollectionToAllShards(opCtx, nss); - LOG(1) << "dropCollection " << nss.ns() << " shard data deleted"; + LOGV2_DEBUG(21925, 1, "dropCollection {nss_ns} shard data deleted", "nss_ns"_attr = nss.ns()); removeChunksAndTagsForDroppedCollection(opCtx, nss); - LOG(1) << "dropCollection " << nss.ns() << " chunk and tag data deleted"; + LOGV2_DEBUG( + 21926, 1, "dropCollection {nss_ns} chunk and tag data deleted", "nss_ns"_attr = nss.ns()); // Mark the collection as dropped CollectionType coll; @@ -442,11 +444,12 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names uassertStatusOK(ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection( opCtx, nss, coll, upsert)); - LOG(1) << "dropCollection " << nss.ns() << " collection marked as dropped"; + LOGV2_DEBUG( + 21927, 1, "dropCollection {nss_ns} collection marked as dropped", "nss_ns"_attr = nss.ns()); sendSSVToAllShards(opCtx, nss); - LOG(1) << "dropCollection " << nss.ns() << " completed"; + LOGV2_DEBUG(21928, 1, "dropCollection {nss_ns} completed", "nss_ns"_attr = nss.ns()); ShardingLogging::get(opCtx)->logChange( opCtx, "dropCollection", nss.ns(), BSONObj(), ShardingCatalogClient::kMajorityWriteConcern); @@ -455,8 +458,10 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names void ShardingCatalogManager::ensureDropCollectionCompleted(OperationContext* opCtx, const NamespaceString& nss) { - LOG(1) << "Ensuring config entries for " << nss.ns() - << " from previous dropCollection are cleared"; + LOGV2_DEBUG(21929, + 1, + "Ensuring config entries for {nss_ns} from previous dropCollection are cleared", + "nss_ns"_attr = nss.ns()); sendDropCollectionToAllShards(opCtx, nss); removeChunksAndTagsForDroppedCollection(opCtx, nss); sendSSVToAllShards(opCtx, nss); @@ -479,7 +484,7 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio .docs; if (shardedColls.empty()) { - LOG(0) << "all sharded collections already have UUIDs"; + LOGV2(21930, "all sharded collections already have UUIDs"); // We did a local read of the collections collection above and found that all sharded // collections already have UUIDs. However, the data may not be majority committed (a @@ -491,8 +496,10 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio } // Generate and persist a new UUID for each collection that did not have a UUID. - LOG(0) << "generating UUIDs for " << shardedColls.size() - << " sharded collections that do not yet have a UUID"; + LOGV2( + 21931, + "generating UUIDs for {shardedColls_size} sharded collections that do not yet have a UUID", + "shardedColls_size"_attr = shardedColls.size()); for (auto& coll : shardedColls) { auto collType = uassertStatusOK(CollectionType::fromBSON(coll)); invariant(!collType.getUUID()); @@ -502,8 +509,12 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio uassertStatusOK(ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection( opCtx, collType.getNs(), collType, false /* upsert */)); - LOG(2) << "updated entry in config.collections for sharded collection " << collType.getNs() - << " with generated UUID " << uuid; + LOGV2_DEBUG(21932, + 2, + "updated entry in config.collections for sharded collection {collType_getNs} " + "with generated UUID {uuid}", + "collType_getNs"_attr = collType.getNs(), + "uuid"_attr = uuid); } } @@ -617,9 +628,12 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, true /* startTransaction */, txnNumber)); - log() << "refineCollectionShardKey: updated collection entry for '" << nss.ns() - << "': took " << executionTimer.millis() - << " ms. Total time taken: " << totalTimer.millis() << " ms."; + LOGV2(21933, + "refineCollectionShardKey: updated collection entry for '{nss_ns}': took " + "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.", + "nss_ns"_attr = nss.ns(), + "executionTimer_millis"_attr = executionTimer.millis(), + "totalTimer_millis"_attr = totalTimer.millis()); executionTimer.reset(); // Update all config.chunks entries for the given namespace by setting (i) their epoch to @@ -627,7 +641,7 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, // MinKey (except for the global max chunk where the max bounds are set to MaxKey), and // unsetting (iii) their jumbo field. if (MONGO_unlikely(hangRefineCollectionShardKeyBeforeUpdatingChunks.shouldFail())) { - log() << "Hit hangRefineCollectionShardKeyBeforeUpdatingChunks failpoint"; + LOGV2(21934, "Hit hangRefineCollectionShardKeyBeforeUpdatingChunks failpoint"); hangRefineCollectionShardKeyBeforeUpdatingChunks.pauseWhileSet(opCtx); } @@ -653,9 +667,12 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, false, // startTransaction txnNumber)); - log() << "refineCollectionShardKey: updated chunk entries for '" << nss.ns() << "': took " - << executionTimer.millis() << " ms. Total time taken: " << totalTimer.millis() - << " ms."; + LOGV2(21935, + "refineCollectionShardKey: updated chunk entries for '{nss_ns}': took " + "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.", + "nss_ns"_attr = nss.ns(), + "executionTimer_millis"_attr = executionTimer.millis(), + "totalTimer_millis"_attr = totalTimer.millis()); executionTimer.reset(); // Update all config.tags entries for the given namespace by setting their bounds for each @@ -680,12 +697,15 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, false, // startTransaction txnNumber)); - log() << "refineCollectionShardKey: updated zone entries for '" << nss.ns() << "': took " - << executionTimer.millis() << " ms. Total time taken: " << totalTimer.millis() - << " ms."; + LOGV2(21936, + "refineCollectionShardKey: updated zone entries for '{nss_ns}': took " + "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.", + "nss_ns"_attr = nss.ns(), + "executionTimer_millis"_attr = executionTimer.millis(), + "totalTimer_millis"_attr = totalTimer.millis()); if (MONGO_unlikely(hangRefineCollectionShardKeyBeforeCommit.shouldFail())) { - log() << "Hit hangRefineCollectionShardKeyBeforeCommit failpoint"; + LOGV2(21937, "Hit hangRefineCollectionShardKeyBeforeCommit failpoint"); hangRefineCollectionShardKeyBeforeCommit.pauseWhileSet(opCtx); } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp index 4028d41a34d..c46a65966a7 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp @@ -39,6 +39,7 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/server_options.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard.h" @@ -150,7 +151,7 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, // Pick a primary shard for the new database. DatabaseType db(dbName.toString(), shardPtr->getId(), false, databaseVersion::makeNew()); - log() << "Registering new database " << db << " in sharding catalog"; + LOGV2(21938, "Registering new database {db} in sharding catalog", "db"_attr = db); // Do this write with majority writeConcern to guarantee that the shard sees the write when it // receives the _flushDatabaseCacheUpdates. @@ -214,7 +215,7 @@ void ShardingCatalogManager::enableSharding(OperationContext* opCtx, Milliseconds{30000}), &unusedResult)); - log() << "Enabling sharding for database [" << dbName << "] in config db"; + LOGV2(21939, "Enabling sharding for database [{dbName}] in config db", "dbName"_attr = dbName); uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument( opCtx, @@ -303,8 +304,10 @@ Status ShardingCatalogManager::commitMovePrimary(OperationContext* opCtx, ShardingCatalogClient::kLocalWriteConcern); if (!updateStatus.isOK()) { - log() << "error committing movePrimary: " << dbname - << causedBy(redact(updateStatus.getStatus())); + LOGV2(21940, + "error committing movePrimary: {dbname}{causedBy_updateStatus_getStatus}", + "dbname"_attr = dbname, + "causedBy_updateStatus_getStatus"_attr = causedBy(redact(updateStatus.getStatus()))); return updateStatus.getStatus(); } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp index c388e826010..b2148656e52 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp @@ -59,6 +59,7 @@ #include "mongo/db/s/type_shard_identity.h" #include "mongo/db/wire_version.h" #include "mongo/executor/task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/config_server_version.h" #include "mongo/s/catalog/sharding_catalog_client.h" @@ -161,7 +162,9 @@ StatusWith<Shard::CommandResponse> ShardingCatalogManager::_runCommandForAddShar _executorForAddShard->wait(swCallbackHandle.getValue()); if (response.status == ErrorCodes::ExceededTimeLimit) { - LOG(0) << "Operation timed out with status " << redact(response.status); + LOGV2(21941, + "Operation timed out with status {response_status}", + "response_status"_attr = redact(response.status)); } if (!response.isOK()) { @@ -672,7 +675,9 @@ StatusWith<std::string> ShardingCatalogManager::addShard( return versionResponse.getValue().commandStatus; } - log() << "going to insert new entry for shard into config.shards: " << shardType.toString(); + LOGV2(21942, + "going to insert new entry for shard into config.shards: {shardType}", + "shardType"_attr = shardType.toString()); Status result = Grid::get(opCtx)->catalogClient()->insertConfigDocument( opCtx, @@ -680,7 +685,10 @@ StatusWith<std::string> ShardingCatalogManager::addShard( shardType.toBSON(), ShardingCatalogClient::kLocalWriteConcern); if (!result.isOK()) { - log() << "error adding shard: " << shardType.toBSON() << " err: " << result.reason(); + LOGV2(21943, + "error adding shard: {shardType} err: {result_reason}", + "shardType"_attr = shardType.toBSON(), + "result_reason"_attr = result.reason()); return result; } } @@ -698,8 +706,11 @@ StatusWith<std::string> ShardingCatalogManager::addShard( true, ShardingCatalogClient::kLocalWriteConcern); if (!status.isOK()) { - log() << "adding shard " << shardConnectionString.toString() - << " even though could not add database " << dbName; + LOGV2(21944, + "adding shard {shardConnectionString} even though could not add database " + "{dbName}", + "shardConnectionString"_attr = shardConnectionString.toString(), + "dbName"_attr = dbName); } } } @@ -773,7 +784,7 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx, auto* const catalogClient = Grid::get(opCtx)->catalogClient(); if (!isShardCurrentlyDraining) { - log() << "going to start draining shard: " << name; + LOGV2(21945, "going to start draining shard: {name}", "name"_attr = name); // Record start in changelog uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked( @@ -811,9 +822,9 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx, if (chunkCount > 0 || databaseCount > 0) { // Still more draining to do - LOG(0) << "chunkCount: " << chunkCount; - LOG(0) << "databaseCount: " << databaseCount; - LOG(0) << "jumboCount: " << jumboCount; + LOGV2(21946, "chunkCount: {chunkCount}", "chunkCount"_attr = chunkCount); + LOGV2(21947, "databaseCount: {databaseCount}", "databaseCount"_attr = databaseCount); + LOGV2(21948, "jumboCount: {jumboCount}", "jumboCount"_attr = jumboCount); return {RemoveShardProgress::ONGOING, boost::optional<RemoveShardProgress::DrainingShardUsage>( @@ -821,7 +832,7 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx, } // Draining is done, now finish removing the shard. - log() << "going to remove shard: " << name; + LOGV2(21949, "going to remove shard: {name}", "name"_attr = name); audit::logRemoveShard(opCtx->getClient(), name); uassertStatusOKWithContext( diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp index 9580cf6026a..ed018daec96 100644 --- a/src/mongo/db/s/database_sharding_state.cpp +++ b/src/mongo/db/s/database_sharding_state.cpp @@ -35,6 +35,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/operation_sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/s/database_version_helpers.h" #include "mongo/s/stale_exception.h" #include "mongo/util/fail_point.h" @@ -120,8 +121,12 @@ void DatabaseShardingState::setDbVersion(OperationContext* opCtx, boost::optional<DatabaseVersion> newDbVersion, DSSLock&) { invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_X)); - log() << "setting this node's cached database version for " << _dbName << " to " - << (newDbVersion ? newDbVersion->toBSON() : BSONObj()); + LOGV2(21950, + "setting this node's cached database version for {dbName} to " + "{newDbVersion_newDbVersion_BSONObj}", + "dbName"_attr = _dbName, + "newDbVersion_newDbVersion_BSONObj"_attr = + (newDbVersion ? newDbVersion->toBSON() : BSONObj())); _dbVersion = newDbVersion; } diff --git a/src/mongo/db/s/flush_database_cache_updates_command.cpp b/src/mongo/db/s/flush_database_cache_updates_command.cpp index 5e4fadfaae0..e96159b3cbd 100644 --- a/src/mongo/db/s/flush_database_cache_updates_command.cpp +++ b/src/mongo/db/s/flush_database_cache_updates_command.cpp @@ -50,6 +50,7 @@ #include "mongo/s/request_types/flush_database_cache_updates_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -133,7 +134,10 @@ public: oss.waitForMigrationCriticalSectionSignal(opCtx); if (request().getSyncFromConfig()) { - LOG(1) << "Forcing remote routing table refresh for " << _dbName(); + LOGV2_DEBUG(21981, + 1, + "Forcing remote routing table refresh for {dbName}", + "dbName"_attr = _dbName()); forceDatabaseRefresh(opCtx, _dbName()); } diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp index f2791bf1fbd..2a2fd18a89f 100644 --- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp +++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp @@ -44,6 +44,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog_cache_loader.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/flush_routing_table_cache_updates_gen.h" @@ -132,7 +133,8 @@ public: oss.waitForMigrationCriticalSectionSignal(opCtx); if (request().getSyncFromConfig()) { - LOG(1) << "Forcing remote routing table refresh for " << ns(); + LOGV2_DEBUG( + 21982, 1, "Forcing remote routing table refresh for {ns}", "ns"_attr = ns()); forceShardFilteringMetadataRefresh(opCtx, ns()); } diff --git a/src/mongo/db/s/merge_chunks_command.cpp b/src/mongo/db/s/merge_chunks_command.cpp index d6db92888e2..5fd4574590b 100644 --- a/src/mongo/db/s/merge_chunks_command.cpp +++ b/src/mongo/db/s/merge_chunks_command.cpp @@ -42,6 +42,7 @@ #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" @@ -227,8 +228,11 @@ void mergeChunks(OperationContext* opCtx, if ((!commandStatus.isOK() || !writeConcernStatus.isOK()) && checkMetadataForSuccess(opCtx, nss, epoch, ChunkRange(minKey, maxKey))) { - LOG(1) << "mergeChunk [" << redact(minKey) << "," << redact(maxKey) - << ") has already been committed."; + LOGV2_DEBUG(21983, + 1, + "mergeChunk [{minKey},{maxKey}) has already been committed.", + "minKey"_attr = redact(minKey), + "maxKey"_attr = redact(maxKey)); return; } diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp index f038c328052..ca3c324e7f8 100644 --- a/src/mongo/db/s/metadata_manager.cpp +++ b/src/mongo/db/s/metadata_manager.cpp @@ -42,6 +42,7 @@ #include "mongo/db/range_arithmetic.h" #include "mongo/db/s/range_deletion_util.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" @@ -167,14 +168,21 @@ void MetadataManager::setFilteringMetadata(CollectionMetadata remoteMetadata) { // We already have the same or newer version if (activeMetadata.getCollVersion().epoch() == remoteMetadata.getCollVersion().epoch() && activeMetadata.getCollVersion() >= remoteMetadata.getCollVersion()) { - LOG(1) << "Ignoring update of active metadata " << activeMetadata.toStringBasic() - << " with an older " << remoteMetadata.toStringBasic(); + LOGV2_DEBUG(21984, + 1, + "Ignoring update of active metadata {activeMetadata_Basic} with an older " + "{remoteMetadata_Basic}", + "activeMetadata_Basic"_attr = activeMetadata.toStringBasic(), + "remoteMetadata_Basic"_attr = remoteMetadata.toStringBasic()); return; } - LOG(0) << "Updating metadata for collection " << _nss.ns() << " from " - << activeMetadata.toStringBasic() << " to " << remoteMetadata.toStringBasic() - << " due to version change"; + LOGV2(21985, + "Updating metadata for collection {nss_ns} from {activeMetadata_Basic} to " + "{remoteMetadata_Basic} due to version change", + "nss_ns"_attr = _nss.ns(), + "activeMetadata_Basic"_attr = activeMetadata.toStringBasic(), + "remoteMetadata_Basic"_attr = remoteMetadata.toStringBasic()); // Resolve any receiving chunks, which might have completed by now for (auto it = _receivingChunks.begin(); it != _receivingChunks.end();) { @@ -187,8 +195,12 @@ void MetadataManager::setFilteringMetadata(CollectionMetadata remoteMetadata) { // The remote metadata contains a chunk we were earlier in the process of receiving, so we // deem it successfully received - LOG(2) << "Verified chunk " << redact(receivingRange.toString()) << " for collection " - << _nss.ns() << " has been migrated to this shard earlier"; + LOGV2_DEBUG(21986, + 2, + "Verified chunk {receivingRange} for collection {nss_ns} has been migrated to " + "this shard earlier", + "receivingRange"_attr = redact(receivingRange.toString()), + "nss_ns"_attr = _nss.ns()); _receivingChunks.erase(it); it = _receivingChunks.begin(); @@ -279,8 +291,11 @@ SharedSemiFuture<void> MetadataManager::beginReceive(ChunkRange const& range) { _receivingChunks.emplace(range.getMin().getOwned(), range.getMax().getOwned()); - log() << "Scheduling deletion of any documents in " << _nss.ns() << " range " - << redact(range.toString()) << " before migrating in a chunk covering the range"; + LOGV2(21987, + "Scheduling deletion of any documents in {nss_ns} range {range} before migrating in a " + "chunk covering the range", + "nss_ns"_attr = _nss.ns(), + "range"_attr = redact(range.toString())); return _submitRangeForDeletion( lg, SemiFuture<void>::makeReady(), range, Seconds(orphanCleanupDelaySecs.load())); @@ -292,8 +307,11 @@ void MetadataManager::forgetReceive(ChunkRange const& range) { // This is potentially a partially received chunk, which needs to be cleaned up. We know none // of these documents are in use, so they can go straight to the deletion queue. - log() << "Abandoning in-migration of " << _nss.ns() << " range " << range - << "; scheduling deletion of any documents already copied"; + LOGV2(21988, + "Abandoning in-migration of {nss_ns} range {range}; scheduling deletion of any documents " + "already copied", + "nss_ns"_attr = _nss.ns(), + "range"_attr = range); invariant(!_overlapsInUseChunk(lg, range)); @@ -327,8 +345,11 @@ SharedSemiFuture<void> MetadataManager::cleanUpRange(ChunkRange const& range, shouldDelayBeforeDeletion ? Seconds(orphanCleanupDelaySecs.load()) : Seconds(0); if (overlapMetadata) { - log() << "Deletion of " << _nss.ns() << " range " << redact(range.toString()) - << " will be scheduled after all possibly dependent queries finish"; + LOGV2(21989, + "Deletion of {nss_ns} range {range} will be scheduled after all possibly dependent " + "queries finish", + "nss_ns"_attr = _nss.ns(), + "range"_attr = redact(range.toString())); ++overlapMetadata->numContingentRangeDeletionTasks; // Schedule the range for deletion once the overlapping metadata object is destroyed // (meaning no more queries can be using the range) and obtain a future which will be @@ -339,7 +360,10 @@ SharedSemiFuture<void> MetadataManager::cleanUpRange(ChunkRange const& range, delayForActiveQueriesOnSecondariesToComplete); } else { // No running queries can depend on this range, so queue it for deletion immediately. - log() << "Scheduling deletion of " << _nss.ns() << " range " << redact(range.toString()); + LOGV2(21990, + "Scheduling deletion of {nss_ns} range {range}", + "nss_ns"_attr = _nss.ns(), + "range"_attr = redact(range.toString())); return _submitRangeForDeletion( lg, SemiFuture<void>::makeReady(), range, delayForActiveQueriesOnSecondariesToComplete); diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp index 454fe2ac76b..76dd0bcde8e 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -52,6 +52,7 @@ #include "mongo/executor/remote_command_response.h" #include "mongo/executor/task_executor.h" #include "mongo/executor/task_executor_pool.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" @@ -182,7 +183,9 @@ void LogTransactionOperationsForShardingHandler::commit(boost::optional<Timestam auto idElement = documentKey["_id"]; if (idElement.eoo()) { - warning() << "Received a document with no id, ignoring: " << redact(documentKey); + LOGV2_WARNING(21994, + "Received a document with no id, ignoring: {documentKey}", + "documentKey"_attr = redact(documentKey)); continue; } @@ -396,7 +399,9 @@ void MigrationChunkClonerSourceLegacy::cancelClone(OperationContext* opCtx) { kRecvChunkAbort, _args.getNss(), _sessionId)) .getStatus(); if (!status.isOK()) { - LOG(0) << "Failed to cancel migration " << causedBy(redact(status)); + LOGV2(21991, + "Failed to cancel migration {causedBy_status}", + "causedBy_status"_attr = causedBy(redact(status))); } } // Intentional fall through @@ -419,8 +424,10 @@ void MigrationChunkClonerSourceLegacy::onInsertOp(OperationContext* opCtx, BSONElement idElement = insertedDoc["_id"]; if (idElement.eoo()) { - warning() << "logInsertOp got a document with no _id field, ignoring inserted document: " - << redact(insertedDoc); + LOGV2_WARNING(21995, + "logInsertOp got a document with no _id field, ignoring inserted document: " + "{insertedDoc}", + "insertedDoc"_attr = redact(insertedDoc)); return; } @@ -450,8 +457,10 @@ void MigrationChunkClonerSourceLegacy::onUpdateOp(OperationContext* opCtx, BSONElement idElement = postImageDoc["_id"]; if (idElement.eoo()) { - warning() << "logUpdateOp got a document with no _id field, ignoring updatedDoc: " - << redact(postImageDoc); + LOGV2_WARNING( + 21996, + "logUpdateOp got a document with no _id field, ignoring updatedDoc: {postImageDoc}", + "postImageDoc"_attr = redact(postImageDoc)); return; } @@ -488,8 +497,10 @@ void MigrationChunkClonerSourceLegacy::onDeleteOp(OperationContext* opCtx, BSONElement idElement = deletedDocId["_id"]; if (idElement.eoo()) { - warning() << "logDeleteOp got a document with no _id field, ignoring deleted doc: " - << redact(deletedDocId); + LOGV2_WARNING( + 21997, + "logDeleteOp got a document with no _id field, ignoring deleted doc: {deletedDocId}", + "deletedDocId"_attr = redact(deletedDocId)); return; } @@ -994,13 +1005,19 @@ Status MigrationChunkClonerSourceLegacy::_checkRecipientCloningStatus(OperationC const std::size_t cloneLocsRemaining = _cloneLocs.size(); if (_forceJumbo && _jumboChunkCloneState) { - log() << "moveChunk data transfer progress: " << redact(res) - << " mem used: " << _memoryUsed - << " documents cloned so far: " << _jumboChunkCloneState->docsCloned; + LOGV2(21992, + "moveChunk data transfer progress: {res} mem used: {memoryUsed} documents cloned " + "so far: {jumboChunkCloneState_docsCloned}", + "res"_attr = redact(res), + "memoryUsed"_attr = _memoryUsed, + "jumboChunkCloneState_docsCloned"_attr = _jumboChunkCloneState->docsCloned); } else { - log() << "moveChunk data transfer progress: " << redact(res) - << " mem used: " << _memoryUsed - << " documents remaining to clone: " << cloneLocsRemaining; + LOGV2(21993, + "moveChunk data transfer progress: {res} mem used: {memoryUsed} documents " + "remaining to clone: {cloneLocsRemaining}", + "res"_attr = redact(res), + "memoryUsed"_attr = _memoryUsed, + "cloneLocsRemaining"_attr = cloneLocsRemaining); } if (res["state"].String() == "steady") { diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index a11bb49b8a4..54f4a01e87b 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -63,6 +63,7 @@ #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/storage/remove_saver.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" @@ -240,7 +241,7 @@ void MigrationDestinationManager::setState(State newState) { } void MigrationDestinationManager::_setStateFail(StringData msg) { - log() << msg; + LOGV2(21998, "{msg}", "msg"_attr = msg); { stdx::lock_guard<Latch> sl(_mutex); _errmsg = msg.toString(); @@ -252,7 +253,7 @@ void MigrationDestinationManager::_setStateFail(StringData msg) { } void MigrationDestinationManager::_setStateFailWarn(StringData msg) { - warning() << msg; + LOGV2_WARNING(22010, "{msg}", "msg"_attr = msg); { stdx::lock_guard<Latch> sl(_mutex); _errmsg = msg.toString(); @@ -436,7 +437,9 @@ repl::OpTime MigrationDestinationManager::cloneDocumentsFromDonor( } catch (...) { stdx::lock_guard<Client> lk(*opCtx->getClient()); opCtx->getServiceContext()->killOperation(lk, opCtx, ErrorCodes::Error(51008)); - log() << "Batch insertion failed " << causedBy(redact(exceptionToStatus())); + LOGV2(21999, + "Batch insertion failed {causedBy_exceptionToStatus}", + "causedBy_exceptionToStatus"_attr = causedBy(redact(exceptionToStatus()))); } }}; auto inserterThreadJoinGuard = makeGuard([&] { @@ -813,9 +816,15 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { invariant(!_min.isEmpty()); invariant(!_max.isEmpty()); - log() << "Starting receiving end of migration of chunk " << redact(_min) << " -> " - << redact(_max) << " for collection " << _nss.ns() << " from " << _fromShard - << " at epoch " << _epoch.toString() << " with session id " << *_sessionId; + LOGV2(22000, + "Starting receiving end of migration of chunk {min} -> {max} for collection {nss_ns} " + "from {fromShard} at epoch {epoch} with session id {sessionId}", + "min"_attr = redact(_min), + "max"_attr = redact(_max), + "nss_ns"_attr = _nss.ns(), + "fromShard"_attr = _fromShard, + "epoch"_attr = _epoch.toString(), + "sessionId"_attr = *_sessionId); MoveTimingHelper timing( outerOpCtx, "to", _nss.ns(), _min, _max, 6 /* steps */, &_errmsg, ShardId(), ShardId()); @@ -823,7 +832,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { const auto initialState = getState(); if (initialState == ABORT) { - error() << "Migration abort requested before it started"; + LOGV2_ERROR(22013, "Migration abort requested before it started"); return; } @@ -843,9 +852,11 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { if (_enableResumableRangeDeleter) { while (migrationutil::checkForConflictingDeletions( outerOpCtx, range, donorCollectionOptionsAndIndexes.uuid)) { - LOG(0) << "Migration paused because range overlaps with a " - "range that is scheduled for deletion: collection: " - << _nss.ns() << " range: " << redact(range.toString()); + LOGV2(22001, + "Migration paused because range overlaps with a " + "range that is scheduled for deletion: collection: {nss_ns} range: {range}", + "nss_ns"_attr = _nss.ns(), + "range"_attr = redact(range.toString())); auto status = CollectionShardingRuntime::waitForClean( outerOpCtx, _nss, donorCollectionOptionsAndIndexes.uuid, range); @@ -984,8 +995,9 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(), _writeConcern); if (replStatus.status.code() == ErrorCodes::WriteConcernFailed) { - warning() << "secondaryThrottle on, but doc insert timed out; " - "continuing"; + LOGV2_WARNING(22011, + "secondaryThrottle on, but doc insert timed out; " + "continuing"); } else { uassertStatusOK(replStatus.status); } @@ -1059,7 +1071,8 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { opCtx->checkForInterrupt(); if (getState() == ABORT) { - log() << "Migration aborted while waiting for replication at catch up stage"; + LOGV2(22002, + "Migration aborted while waiting for replication at catch up stage"); return; } @@ -1067,7 +1080,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { break; if (i > 100) { - log() << "secondaries having hard time keeping up with migrate"; + LOGV2(22003, "secondaries having hard time keeping up with migrate"); } sleepmillis(20); @@ -1087,14 +1100,14 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { // Pause to wait for replication. This will prevent us from going into critical section // until we're ready. - log() << "Waiting for replication to catch up before entering critical section"; + LOGV2(22004, "Waiting for replication to catch up before entering critical section"); auto awaitReplicationResult = repl::ReplicationCoordinator::get(opCtx)->awaitReplication( opCtx, lastOpApplied, _writeConcern); uassertStatusOKWithContext(awaitReplicationResult.status, awaitReplicationResult.status.codeString()); - log() << "Chunk data replicated successfully."; + LOGV2(22005, "Chunk data replicated successfully."); } { @@ -1131,7 +1144,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { } if (getState() == ABORT) { - log() << "Migration aborted while transferring mods"; + LOGV2(22006, "Migration aborted while transferring mods"); return; } @@ -1254,7 +1267,7 @@ bool MigrationDestinationManager::_applyMigrateOp(OperationContext* opCtx, const std::string errMsg = str::stream() << "cannot migrate chunk, local document " << redact(localDoc) << " has same _id as reloaded remote document " << redact(updatedDoc); - warning() << errMsg; + LOGV2_WARNING(22012, "{errMsg}", "errMsg"_attr = errMsg); // Exception will abort migration cleanly uasserted(16977, errMsg); @@ -1277,14 +1290,22 @@ bool MigrationDestinationManager::_flushPendingWrites(OperationContext* opCtx, repl::OpTime op(lastOpApplied); static Occasionally sampler; if (sampler.tick()) { - log() << "migrate commit waiting for a majority of slaves for '" << _nss.ns() << "' " - << redact(_min) << " -> " << redact(_max) << " waiting for: " << op; + LOGV2(22007, + "migrate commit waiting for a majority of slaves for '{nss_ns}' {min} -> {max} " + "waiting for: {op}", + "nss_ns"_attr = _nss.ns(), + "min"_attr = redact(_min), + "max"_attr = redact(_max), + "op"_attr = op); } return false; } - log() << "migrate commit succeeded flushing to secondaries for '" << _nss.ns() << "' " - << redact(_min) << " -> " << redact(_max); + LOGV2(22008, + "migrate commit succeeded flushing to secondaries for '{nss_ns}' {min} -> {max}", + "nss_ns"_attr = _nss.ns(), + "min"_attr = redact(_min), + "max"_attr = redact(_max)); return true; } @@ -1330,8 +1351,10 @@ void MigrationDestinationManager::_forgetPending(OperationContext* opCtx, ChunkR // checking this here is that in the future we shouldn't have this problem. if (!optMetadata || !(*optMetadata)->isSharded() || (*optMetadata)->getCollVersion().epoch() != _epoch) { - LOG(0) << "No need to forget pending chunk " << redact(range.toString()) - << " because the epoch for " << _nss.ns() << " changed"; + LOGV2(22009, + "No need to forget pending chunk {range} because the epoch for {nss_ns} changed", + "range"_attr = redact(range.toString()), + "nss_ns"_attr = _nss.ns()); return; } diff --git a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp index acfdbb306f1..50d63eec920 100644 --- a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp +++ b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp @@ -43,6 +43,7 @@ #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/start_chunk_clone_request.h" +#include "mongo/logv2/log.h" #include "mongo/s/chunk_version.h" #include "mongo/s/request_types/migration_secondary_throttle_options.h" #include "mongo/util/assert_util.h" @@ -202,7 +203,7 @@ public: Status const status = mdm->startCommit(sessionId); mdm->report(result, opCtx, false); if (!status.isOK()) { - log() << status.reason(); + LOGV2(22014, "{status_reason}", "status_reason"_attr = status.reason()); uassertStatusOK(status); } return true; @@ -250,7 +251,7 @@ public: Status const status = mdm->abort(migrationSessionIdStatus.getValue()); mdm->report(result, opCtx, false); if (!status.isOK()) { - log() << status.reason(); + LOGV2(22015, "{status_reason}", "status_reason"_attr = status.reason()); uassertStatusOK(status); } } else if (migrationSessionIdStatus == ErrorCodes::NoSuchKey) { diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 34012e759d4..c94b0777ad2 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -57,6 +57,7 @@ #include "mongo/db/s/sharding_statistics.h" #include "mongo/executor/task_executor.h" #include "mongo/executor/task_executor_pool.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_shard_collection.h" #include "mongo/s/catalog_cache_loader.h" @@ -164,8 +165,11 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx, "Destination shard cannot be the same as source", _args.getFromShardId() != _args.getToShardId()); - log() << "Starting chunk migration " << redact(_args.toString()) - << " with expected collection version epoch " << _args.getVersionEpoch(); + LOGV2(22016, + "Starting chunk migration {args} with expected collection version epoch " + "{args_getVersionEpoch}", + "args"_attr = redact(_args.toString()), + "args_getVersionEpoch"_attr = _args.getVersionEpoch()); // Force refresh of the metadata to ensure we have the latest forceShardFilteringMetadataRefresh(_opCtx, getNss()); @@ -391,7 +395,7 @@ Status MigrationSourceManager::enterCriticalSection() { << signalStatus.toString()}; } - log() << "Migration successfully entered critical section"; + LOGV2(22017, "Migration successfully entered critical section"); scopedGuard.dismiss(); return Status::OK(); @@ -502,8 +506,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() { } // Migration succeeded - LOG(0) << "Migration succeeded and updated collection version to " - << refreshedMetadata->getCollVersion(); + LOGV2( + 22018, + "Migration succeeded and updated collection version to {refreshedMetadata_getCollVersion}", + "refreshedMetadata_getCollVersion"_attr = refreshedMetadata->getCollVersion()); if (_enableResumableRangeDeleter) { _coordinator->setMigrationDecision( @@ -547,8 +553,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() { if (_enableResumableRangeDeleter) { if (_args.getWaitForDelete()) { - log() << "Waiting for cleanup of " << getNss().ns() << " range " - << redact(range.toString()); + LOGV2(22019, + "Waiting for cleanup of {getNss_ns} range {range}", + "getNss_ns"_attr = getNss().ns(), + "range"_attr = redact(range.toString())); invariant(_scheduledRangeDeletionOnSuccess); auto scheduleSW = _scheduledRangeDeletionOnSuccess->getNoThrow(_opCtx); @@ -575,8 +583,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() { }(); if (_args.getWaitForDelete()) { - log() << "Waiting for cleanup of " << getNss().ns() << " range " - << redact(range.toString()); + LOGV2(22020, + "Waiting for cleanup of {getNss_ns} range {range}", + "getNss_ns"_attr = getNss().ns(), + "range"_attr = redact(range.toString())); auto deleteStatus = cleanupCompleteFuture.getNoThrow(_opCtx); @@ -592,8 +602,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() { return {ErrorCodes::OrphanedRangeCleanUpFailed, orphanedRangeCleanUpErrMsg + redact(cleanupCompleteFuture.getNoThrow(_opCtx))}; } else { - log() << "Leaving cleanup of " << getNss().ns() << " range " << redact(range.toString()) - << " to complete in background"; + LOGV2(22021, + "Leaving cleanup of {getNss_ns} range {range} to complete in background", + "getNss_ns"_attr = getNss().ns(), + "range"_attr = redact(range.toString())); } } @@ -616,8 +628,10 @@ void MigrationSourceManager::cleanupOnError() { try { _cleanup(); } catch (const DBException& ex) { - warning() << "Failed to clean up migration: " << redact(_args.toString()) - << "due to: " << redact(ex); + LOGV2_WARNING(22022, + "Failed to clean up migration: {args}due to: {ex}", + "args"_attr = redact(_args.toString()), + "ex"_attr = redact(ex)); } } diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index 58f9198057c..a5938c94b79 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -52,6 +52,7 @@ #include "mongo/db/write_concern.h" #include "mongo/executor/task_executor_pool.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/client/shard.h" @@ -83,7 +84,7 @@ void sendToRecipient(OperationContext* opCtx, const ShardId& recipientId, const auto recipientShard = uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, recipientId)); - LOG(1) << "Sending request " << cmd.toBSON({}) << " to recipient."; + LOGV2_DEBUG(22023, 1, "Sending request {cmd} to recipient.", "cmd"_attr = cmd.toBSON({})); auto response = recipientShard->runCommandWithFixedRetryAttempts( opCtx, @@ -150,14 +151,20 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx, // does not match the UUID of the deletion task, force a filtering metadata refresh // once, because this node may have just stepped up and therefore may have a stale // cache. - LOG(0) << "Filtering metadata for namespace in deletion task " - << deletionTask.toBSON() - << (css->getCurrentMetadataIfKnown() - ? (css->getCurrentMetadata()->isSharded() - ? " has UUID that does not match UUID of the deletion task" - : " is unsharded") - : " is not known") - << ", forcing a refresh of " << deletionTask.getNss(); + LOGV2( + 22024, + "Filtering metadata for namespace in deletion task " + "{deletionTask}{css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_" + "has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_" + "known}, forcing a refresh of {deletionTask_getNss}", + "deletionTask"_attr = deletionTask.toBSON(), + "css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_known"_attr = + (css->getCurrentMetadataIfKnown() + ? (css->getCurrentMetadata()->isSharded() + ? " has UUID that does not match UUID of the deletion task" + : " is unsharded") + : " is not known"), + "deletionTask_getNss"_attr = deletionTask.getNss()); // TODO (SERVER-46075): Add an asynchronous version of // forceShardFilteringMetadataRefresh to avoid blocking on the network in the @@ -178,15 +185,20 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx, autoColl.emplace(opCtx, deletionTask.getNss(), MODE_IS); if (!css->getCurrentMetadataIfKnown() || !css->getCurrentMetadata()->isSharded() || !css->getCurrentMetadata()->uuidMatches(deletionTask.getCollectionUuid())) { - LOG(0) << "Even after forced refresh, filtering metadata for namespace in deletion " - "task " - << deletionTask.toBSON() - << (css->getCurrentMetadataIfKnown() - ? (css->getCurrentMetadata()->isSharded() - ? " has UUID that does not match UUID of the deletion task" - : " is unsharded") - : " is not known") - << ", deleting the task."; + LOGV2( + 22025, + "Even after forced refresh, filtering metadata for namespace in deletion " + "task " + "{deletionTask}{css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_" + "has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_" + "known}, deleting the task.", + "deletionTask"_attr = deletionTask.toBSON(), + "css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_known"_attr = + (css->getCurrentMetadataIfKnown() + ? (css->getCurrentMetadata()->isSharded() + ? " has UUID that does not match UUID of the deletion task" + : " is unsharded") + : " is not known")); autoColl.reset(); deleteRangeDeletionTaskLocally( @@ -194,7 +206,9 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx, return false; } - LOG(0) << "Submitting range deletion task " << deletionTask.toBSON(); + LOGV2(22026, + "Submitting range deletion task {deletionTask}", + "deletionTask"_attr = deletionTask.toBSON()); const auto whenToClean = deletionTask.getWhenToClean() == CleanWhenEnum::kNow ? CollectionShardingRuntime::kNow @@ -204,8 +218,12 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx, if (cleanupCompleteFuture.isReady() && !cleanupCompleteFuture.getNoThrow(opCtx).isOK()) { - LOG(0) << "Failed to submit range deletion task " << deletionTask.toBSON() - << causedBy(cleanupCompleteFuture.getNoThrow(opCtx)); + LOGV2(22027, + "Failed to submit range deletion task " + "{deletionTask}{causedBy_cleanupCompleteFuture_getNoThrow_opCtx}", + "deletionTask"_attr = deletionTask.toBSON(), + "causedBy_cleanupCompleteFuture_getNoThrow_opCtx"_attr = + causedBy(cleanupCompleteFuture.getNoThrow(opCtx))); return false; } return true; @@ -225,7 +243,7 @@ void submitPendingDeletions(OperationContext* opCtx) { } void resubmitRangeDeletionsOnStepUp(ServiceContext* serviceContext) { - LOG(0) << "Starting pending deletion submission thread."; + LOGV2(22028, "Starting pending deletion submission thread."); auto executor = Grid::get(serviceContext)->getExecutorPool()->getFixedExecutor(); @@ -258,8 +276,9 @@ void forEachOrphanRange(OperationContext* opCtx, const NamespaceString& nss, Cal RangeMap{SimpleBSONObjComparator::kInstance.makeBSONObjIndexedMap<BSONObj>()}; if (!metadata->isSharded()) { - LOG(0) << "Upgrade: skipping orphaned range enumeration for " << nss - << ", collection is not sharded"; + LOGV2(22029, + "Upgrade: skipping orphaned range enumeration for {nss}, collection is not sharded", + "nss"_attr = nss); return; } @@ -268,8 +287,12 @@ void forEachOrphanRange(OperationContext* opCtx, const NamespaceString& nss, Cal while (true) { auto range = metadata->getNextOrphanRange(emptyChunkMap, startingKey); if (!range) { - LOG(2) << "Upgrade: Completed orphaned range enumeration for " << nss.toString() - << " starting from " << redact(startingKey) << ", no orphan ranges remain"; + LOGV2_DEBUG(22030, + 2, + "Upgrade: Completed orphaned range enumeration for {nss} starting from " + "{startingKey}, no orphan ranges remain", + "nss"_attr = nss.toString(), + "startingKey"_attr = redact(startingKey)); return; } @@ -287,7 +310,11 @@ void submitOrphanRanges(OperationContext* opCtx, const NamespaceString& nss, con if (version == ChunkVersion::UNSHARDED()) return; - LOG(2) << "Upgrade: Cleaning up existing orphans for " << nss << " : " << uuid; + LOGV2_DEBUG(22031, + 2, + "Upgrade: Cleaning up existing orphans for {nss} : {uuid}", + "nss"_attr = nss, + "uuid"_attr = uuid); std::vector<RangeDeletionTask> deletions; forEachOrphanRange(opCtx, nss, [&deletions, &opCtx, &nss, &uuid](const auto& range) { @@ -305,14 +332,19 @@ void submitOrphanRanges(OperationContext* opCtx, const NamespaceString& nss, con NamespaceString::kRangeDeletionNamespace); for (const auto& task : deletions) { - LOG(2) << "Upgrade: Submitting range for cleanup: " << task.getRange() << " from " - << nss; + LOGV2_DEBUG(22032, + 2, + "Upgrade: Submitting range for cleanup: {task_getRange} from {nss}", + "task_getRange"_attr = task.getRange(), + "nss"_attr = nss); store.add(opCtx, task); } } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>& e) { - LOG(0) << "Upgrade: Failed to cleanup orphans for " << nss - << " because the namespace was not found: " << e.what() - << ", the collection must have been dropped"; + LOGV2(22033, + "Upgrade: Failed to cleanup orphans for {nss} because the namespace was not found: " + "{e_what}, the collection must have been dropped", + "nss"_attr = nss, + "e_what"_attr = e.what()); } } @@ -327,7 +359,7 @@ void submitOrphanRangesForCleanup(OperationContext* opCtx) { for (auto collIt = catalog.begin(dbName); collIt != catalog.end(); ++collIt) { auto uuid = collIt.uuid().get(); auto nss = catalog.lookupNSSByUUID(opCtx, uuid).get(); - LOG(2) << "Upgrade: processing collection: " << nss; + LOGV2_DEBUG(22034, 2, "Upgrade: processing collection: {nss}", "nss"_attr = nss); submitOrphanRanges(opCtx, nss, uuid); } @@ -504,8 +536,11 @@ void ensureChunkVersionIsGreaterThan(OperationContext* opCtx, repl::MemberState::RS_PRIMARY && term == repl::ReplicationCoordinator::get(opCtx)->getTerm()); - LOG(0) << "_configsvrEnsureChunkVersionIsGreaterThan failed after " << attempts - << " attempts " << causedBy(redact(ex.toStatus())) << " . Will try again."; + LOGV2(22035, + "_configsvrEnsureChunkVersionIsGreaterThan failed after {attempts} attempts " + "{causedBy_ex_toStatus} . Will try again.", + "attempts"_attr = attempts, + "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus()))); } } } @@ -551,15 +586,18 @@ void refreshFilteringMetadataUntilSuccess(OperationContext* opCtx, const Namespa repl::MemberState::RS_PRIMARY && term == repl::ReplicationCoordinator::get(opCtx)->getTerm()); - LOG(0) << "Failed to refresh metadata for " << nss.ns() << " after " << attempts - << " attempts " << causedBy(redact(ex.toStatus())) - << ". Will try to refresh again."; + LOGV2(22036, + "Failed to refresh metadata for {nss_ns} after {attempts} attempts " + "{causedBy_ex_toStatus}. Will try to refresh again.", + "nss_ns"_attr = nss.ns(), + "attempts"_attr = attempts, + "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus()))); } } } void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) { - LOG(0) << "Starting migration coordinator stepup recovery thread."; + LOGV2(22037, "Starting migration coordinator stepup recovery thread."); auto executor = Grid::get(serviceContext)->getExecutorPool()->getFixedExecutor(); ExecutorFuture<void>(executor).getAsync([serviceContext](const Status& status) { @@ -590,7 +628,9 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) { auto& replClientInfo = repl::ReplClientInfo::forClient(opCtx->getClient()); replClientInfo.setLastOpToSystemLastOpTime(opCtx); const auto lastOpTime = replClientInfo.getLastOp(); - LOG(0) << "Waiting for OpTime " << lastOpTime << " to become majority committed"; + LOGV2(22038, + "Waiting for OpTime {lastOpTime} to become majority committed", + "lastOpTime"_attr = lastOpTime); WriteConcernResult unusedWCResult; uassertStatusOK( waitForWriteConcern(opCtx, @@ -604,7 +644,7 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) { opCtx, NamespaceString::kMigrationCoordinatorsNamespace); Query query; store.forEach(opCtx, query, [&opCtx](const MigrationCoordinatorDocument& doc) { - LOG(0) << "Recovering migration " << doc.toBSON(); + LOGV2(22039, "Recovering migration {doc}", "doc"_attr = doc.toBSON()); // Create a MigrationCoordinator to complete the coordination. MigrationCoordinator coordinator(doc.getId(), @@ -643,15 +683,20 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) { if (!refreshedMetadata || !(*refreshedMetadata)->isSharded() || !(*refreshedMetadata)->uuidMatches(doc.getCollectionUuid())) { - LOG(0) << "Even after forced refresh, filtering metadata for namespace in " - "migration coordinator doc " - << doc.toBSON() - << (!refreshedMetadata || !(*refreshedMetadata)->isSharded() - ? "is not known" - : "has UUID that does not match the collection UUID in the " - "coordinator doc") - << ". Deleting the range deletion tasks on the donor and recipient as " - "well as the migration coordinator document on this node."; + LOGV2( + 22040, + "Even after forced refresh, filtering metadata for namespace in " + "migration coordinator doc " + "{doc}{refreshedMetadata_refreshedMetadata_isSharded_is_not_known_has_UUID_" + "that_does_not_match_the_collection_UUID_in_the_coordinator_doc}. Deleting " + "the range deletion tasks on the donor and recipient as " + "well as the migration coordinator document on this node.", + "doc"_attr = doc.toBSON(), + "refreshedMetadata_refreshedMetadata_isSharded_is_not_known_has_UUID_that_does_not_match_the_collection_UUID_in_the_coordinator_doc"_attr = + (!refreshedMetadata || !(*refreshedMetadata)->isSharded() + ? "is not known" + : "has UUID that does not match the collection UUID in the " + "coordinator doc")); // TODO (SERVER-45707): Test that range deletion tasks are eventually // deleted even if the collection is dropped before migration coordination @@ -672,8 +717,9 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) { return true; }); } catch (const DBException& ex) { - LOG(0) << "Failed to resume coordinating migrations on stepup " - << causedBy(ex.toStatus()); + LOGV2(22041, + "Failed to resume coordinating migrations on stepup {causedBy_ex_toStatus}", + "causedBy_ex_toStatus"_attr = causedBy(ex.toStatus())); } }); } diff --git a/src/mongo/db/s/move_primary_source_manager.cpp b/src/mongo/db/s/move_primary_source_manager.cpp index ec87bce1bfa..c6b97b5b1be 100644 --- a/src/mongo/db/s/move_primary_source_manager.cpp +++ b/src/mongo/db/s/move_primary_source_manager.cpp @@ -41,6 +41,7 @@ #include "mongo/db/s/sharding_logging.h" #include "mongo/db/s/sharding_state_recovery.h" #include "mongo/db/s/sharding_statistics.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/type_shard_database.h" #include "mongo/s/catalog_cache.h" @@ -74,7 +75,11 @@ Status MovePrimarySourceManager::clone(OperationContext* opCtx) { invariant(_state == kCreated); auto scopedGuard = makeGuard([&] { cleanupOnError(opCtx); }); - log() << "Moving " << _dbname << " primary from: " << _fromShard << " to: " << _toShard; + LOGV2(22042, + "Moving {dbname} primary from: {fromShard} to: {toShard}", + "dbname"_attr = _dbname, + "fromShard"_attr = _fromShard, + "toShard"_attr = _toShard); // Record start in changelog uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked( @@ -195,7 +200,7 @@ Status MovePrimarySourceManager::enterCriticalSection(OperationContext* opCtx) { << signalStatus.toString()}; } - log() << "movePrimary successfully entered critical section"; + LOGV2(22043, "movePrimary successfully entered critical section"); scopedGuard.dismiss(); return Status::OK(); @@ -244,9 +249,10 @@ Status MovePrimarySourceManager::commitOnConfig(OperationContext* opCtx) { // Need to get the latest optime in case the refresh request goes to a secondary -- // otherwise the read won't wait for the write that _configsvrCommitMovePrimary may have // done - log() << "Error occurred while committing the movePrimary. Performing a majority write " - "against the config server to obtain its latest optime" - << causedBy(redact(commitStatus)); + LOGV2(22044, + "Error occurred while committing the movePrimary. Performing a majority write " + "against the config server to obtain its latest optime{causedBy_commitStatus}", + "causedBy_commitStatus"_attr = causedBy(redact(commitStatus))); Status validateStatus = ShardingLogging::get(opCtx)->logChangeChecked( opCtx, @@ -337,7 +343,10 @@ Status MovePrimarySourceManager::cleanStaleData(OperationContext* opCtx) { client.runCommand(_dbname.toString(), BSON("drop" << coll.coll()), dropCollResult); Status dropStatus = getStatusFromCommandResult(dropCollResult); if (!dropStatus.isOK()) { - log() << "failed to drop cloned collection " << coll << causedBy(redact(dropStatus)); + LOGV2(22045, + "failed to drop cloned collection {coll}{causedBy_dropStatus}", + "coll"_attr = coll, + "causedBy_dropStatus"_attr = causedBy(redact(dropStatus))); } } @@ -363,8 +372,10 @@ void MovePrimarySourceManager::cleanupOnError(OperationContext* opCtx) { } catch (const ExceptionForCat<ErrorCategory::NotMasterError>& ex) { BSONObjBuilder requestArgsBSON; _requestArgs.serialize(&requestArgsBSON); - warning() << "Failed to clean up movePrimary: " << redact(requestArgsBSON.obj()) - << "due to: " << redact(ex); + LOGV2_WARNING(22046, + "Failed to clean up movePrimary: {requestArgsBSON_obj}due to: {ex}", + "requestArgsBSON_obj"_attr = redact(requestArgsBSON.obj()), + "ex"_attr = redact(ex)); } } diff --git a/src/mongo/db/s/periodic_balancer_config_refresher.cpp b/src/mongo/db/s/periodic_balancer_config_refresher.cpp index f9cab569d89..96c33e0ceb3 100644 --- a/src/mongo/db/s/periodic_balancer_config_refresher.cpp +++ b/src/mongo/db/s/periodic_balancer_config_refresher.cpp @@ -35,6 +35,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -60,7 +61,9 @@ PeriodicJobAnchor launchBalancerConfigRefresher(ServiceContext* serviceContext) Status status = balancerConfig->refreshAndCheck(opCtx.get()); if (!status.isOK()) { - log() << "Failed to refresh balancer configuration" << causedBy(status); + LOGV2(22048, + "Failed to refresh balancer configuration{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } }, Seconds(30)); diff --git a/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp b/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp index 387d2c72652..b30403d42ff 100644 --- a/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp +++ b/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp @@ -37,6 +37,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/s/query/cluster_aggregate.h" #include "mongo/util/log.h" @@ -77,7 +78,7 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck return; } - log() << "Checking consistency of sharded collection indexes across the cluster"; + LOGV2(22049, "Checking consistency of sharded collection indexes across the cluster"); const auto aggRequestBSON = fromjson( "{pipeline: [{$indexStats: {}}," @@ -141,8 +142,12 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck } break; } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) { - log() << "Attempt " << tries << " to check index consistency for " - << nss << " received StaleShardVersion error" << causedBy(ex); + LOGV2(22050, + "Attempt {tries} to check index consistency for {nss} received " + "StaleShardVersion error{causedBy_ex}", + "tries"_attr = tries, + "nss"_attr = nss, + "causedBy_ex"_attr = causedBy(ex)); if (canRetry) { continue; } @@ -151,14 +156,19 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck } } - log() << "Found " << numShardedCollsWithInconsistentIndexes - << " collections with inconsistent indexes"; + LOGV2(22051, + "Found {numShardedCollsWithInconsistentIndexes} collections with " + "inconsistent indexes", + "numShardedCollsWithInconsistentIndexes"_attr = + numShardedCollsWithInconsistentIndexes); // Update the count. _numShardedCollsWithInconsistentIndexes.store( numShardedCollsWithInconsistentIndexes); } catch (DBException& ex) { - log() << "Failed to check index consistency " << causedBy(ex.toStatus()); + LOGV2(22052, + "Failed to check index consistency {causedBy_ex_toStatus}", + "causedBy_ex_toStatus"_attr = causedBy(ex.toStatus())); } }, Milliseconds(shardedIndexConsistencyCheckIntervalMS)); diff --git a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp index 5a8d900a810..2328a973aef 100644 --- a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp +++ b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp @@ -38,6 +38,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/stale_exception.h" #include "mongo/util/log.h" @@ -89,16 +90,18 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi auto handleMismatchStatus = onShardVersionMismatchNoExcept( _opCtx, staleInfo->getNss(), staleInfo->getVersionReceived()); if (!handleMismatchStatus.isOK()) - log() << "Failed to handle stale version exception" - << causedBy(redact(handleMismatchStatus)); + LOGV2(22053, + "Failed to handle stale version exception{causedBy_handleMismatchStatus}", + "causedBy_handleMismatchStatus"_attr = causedBy(redact(handleMismatchStatus))); } else if (auto staleInfo = status->extraInfo<StaleDbRoutingVersion>()) { auto handleMismatchStatus = onDbVersionMismatchNoExcept(_opCtx, staleInfo->getDb(), staleInfo->getVersionReceived(), staleInfo->getVersionWanted()); if (!handleMismatchStatus.isOK()) - log() << "Failed to handle database version exception" - << causedBy(redact(handleMismatchStatus)); + LOGV2(22054, + "Failed to handle database version exception{causedBy_handleMismatchStatus}", + "causedBy_handleMismatchStatus"_attr = causedBy(redact(handleMismatchStatus))); } else if (auto cannotImplicitCreateCollInfo = status->extraInfo<CannotImplicitlyCreateCollectionInfo>()) { if (ShardingState::get(_opCtx)->enabled() && @@ -107,8 +110,11 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi auto handleCannotImplicitCreateStatus = onCannotImplicitlyCreateCollection(_opCtx, cannotImplicitCreateCollInfo->getNss()); if (!handleCannotImplicitCreateStatus.isOK()) - log() << "Failed to handle CannotImplicitlyCreateCollection exception" - << causedBy(redact(handleCannotImplicitCreateStatus)); + LOGV2(22055, + "Failed to handle CannotImplicitlyCreateCollection " + "exception{causedBy_handleCannotImplicitCreateStatus}", + "causedBy_handleCannotImplicitCreateStatus"_attr = + causedBy(redact(handleCannotImplicitCreateStatus))); } } } diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index 839c87ea602..a28ba943bb4 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -47,6 +47,7 @@ #include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/set_shard_version_request.h" @@ -305,7 +306,7 @@ public: if (critSecSignal) { collLock.reset(); autoDb.reset(); - log() << "waiting till out of critical section"; + LOGV2(22056, "waiting till out of critical section"); critSecSignal->waitFor(opCtx, Seconds(10)); } @@ -326,7 +327,7 @@ public: if (critSecSignal) { collLock.reset(); autoDb.reset(); - log() << "waiting till out of critical section"; + LOGV2(22057, "waiting till out of critical section"); critSecSignal->waitFor(opCtx, Seconds(10)); } @@ -371,7 +372,7 @@ public: << ", stored shard version is " << currVersion.toString() << causedBy(redact(status)); - warning() << errmsg; + LOGV2_WARNING(22058, "{errmsg}", "errmsg"_attr = errmsg); result.append("ns", nss.ns()); result.append("code", status.code()); @@ -390,7 +391,7 @@ public: static Occasionally sampler; if (sampler.tick()) { - warning() << errmsg; + LOGV2_WARNING(22059, "{errmsg}", "errmsg"_attr = errmsg); } // WARNING: the exact fields below are important for compatibility with mongos diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp index 5926ddcb456..ed66137c3d4 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp @@ -42,6 +42,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_statistics.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/grid.h" #include "mongo/util/fail_point.h" @@ -63,8 +64,11 @@ void onShardVersionMismatch(OperationContext* opCtx, invariant(ShardingState::get(opCtx)->canAcceptShardedCommands()); - LOG(2) << "Metadata refresh requested for " << nss.ns() << " at shard version " - << shardVersionReceived; + LOGV2_DEBUG(22061, + 2, + "Metadata refresh requested for {nss_ns} at shard version {shardVersionReceived}", + "nss_ns"_attr = nss.ns(), + "shardVersionReceived"_attr = shardVersionReceived); ShardingStatistics::get(opCtx).countStaleConfigErrors.addAndFetch(1); @@ -134,7 +138,10 @@ Status onShardVersionMismatchNoExcept(OperationContext* opCtx, onShardVersionMismatch(opCtx, nss, shardVersionReceived, forceRefreshFromThisThread); return Status::OK(); } catch (const DBException& ex) { - log() << "Failed to refresh metadata for collection " << nss << causedBy(redact(ex)); + LOGV2(22062, + "Failed to refresh metadata for collection {nss}{causedBy_ex}", + "nss"_attr = nss, + "causedBy_ex"_attr = causedBy(redact(ex))); return ex.toStatus(); } } @@ -179,8 +186,13 @@ ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx, if (metadata->isSharded() && metadata->getCollVersion().epoch() == cm->getVersion().epoch() && metadata->getCollVersion() >= cm->getVersion()) { - LOG(1) << "Skipping refresh of metadata for " << nss << " " - << metadata->getCollVersion() << " with an older " << cm->getVersion(); + LOGV2_DEBUG(22063, + 1, + "Skipping refresh of metadata for {nss} {metadata_getCollVersion} with " + "an older {cm_getVersion}", + "nss"_attr = nss, + "metadata_getCollVersion"_attr = metadata->getCollVersion(), + "cm_getVersion"_attr = cm->getVersion()); return metadata->getShardVersion(); } } @@ -202,8 +214,13 @@ ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx, if (metadata->isSharded() && metadata->getCollVersion().epoch() == cm->getVersion().epoch() && metadata->getCollVersion() >= cm->getVersion()) { - LOG(1) << "Skipping refresh of metadata for " << nss << " " - << metadata->getCollVersion() << " with an older " << cm->getVersion(); + LOGV2_DEBUG(22064, + 1, + "Skipping refresh of metadata for {nss} {metadata_getCollVersion} with " + "an older {cm_getVersion}", + "nss"_attr = nss, + "metadata_getCollVersion"_attr = metadata->getCollVersion(), + "cm_getVersion"_attr = cm->getVersion()); return metadata->getShardVersion(); } } @@ -225,8 +242,10 @@ Status onDbVersionMismatchNoExcept( onDbVersionMismatch(opCtx, dbName, clientDbVersion, serverDbVersion); return Status::OK(); } catch (const DBException& ex) { - log() << "Failed to refresh databaseVersion for database " << dbName - << causedBy(redact(ex)); + LOGV2(22065, + "Failed to refresh databaseVersion for database {dbName}{causedBy_ex}", + "dbName"_attr = dbName, + "causedBy_ex"_attr = causedBy(redact(ex))); return ex.toStatus(); } } @@ -266,10 +285,14 @@ void forceDatabaseRefresh(OperationContext* opCtx, const StringData dbName) { const auto cachedDbVersion = dss->getDbVersion(opCtx, dssLock); if (cachedDbVersion && cachedDbVersion->getUuid() == refreshedDbVersion.getUuid() && cachedDbVersion->getLastMod() >= refreshedDbVersion.getLastMod()) { - LOG(2) << "Skipping setting cached databaseVersion for " << dbName - << " to refreshed version " << refreshedDbVersion.toBSON() - << " because current cached databaseVersion is already " - << cachedDbVersion->toBSON(); + LOGV2_DEBUG(22066, + 2, + "Skipping setting cached databaseVersion for {dbName} to refreshed version " + "{refreshedDbVersion} because current cached databaseVersion is already " + "{cachedDbVersion}", + "dbName"_attr = dbName, + "refreshedDbVersion"_attr = refreshedDbVersion.toBSON(), + "cachedDbVersion"_attr = cachedDbVersion->toBSON()); return; } } diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp index d08c5f4cd79..37500a2ee15 100644 --- a/src/mongo/db/s/shard_metadata_util.cpp +++ b/src/mongo/db/s/shard_metadata_util.cpp @@ -38,6 +38,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/ops/write_ops.h" #include "mongo/db/write_concern_options.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/unique_message.h" #include "mongo/s/catalog/type_chunk.h" @@ -425,7 +426,10 @@ Status dropChunksAndDeleteCollectionsEntry(OperationContext* opCtx, const Namesp } } - LOG(1) << "Successfully cleared persisted chunk metadata for collection '" << nss << "'."; + LOGV2_DEBUG(22090, + 1, + "Successfully cleared persisted chunk metadata for collection '{nss}'.", + "nss"_attr = nss); return Status::OK(); } catch (const DBException& ex) { return ex.toStatus(); @@ -444,7 +448,10 @@ void dropChunks(OperationContext* opCtx, const NamespaceString& nss) { } } - LOG(1) << "Successfully cleared persisted chunk metadata for collection '" << nss << "'."; + LOGV2_DEBUG(22091, + 1, + "Successfully cleared persisted chunk metadata for collection '{nss}'.", + "nss"_attr = nss); } Status deleteDatabasesEntry(OperationContext* opCtx, StringData dbName) { @@ -464,7 +471,10 @@ Status deleteDatabasesEntry(OperationContext* opCtx, StringData dbName) { uassertStatusOK( getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply())); - LOG(1) << "Successfully cleared persisted metadata for db '" << dbName.toString() << "'."; + LOGV2_DEBUG(22092, + 1, + "Successfully cleared persisted metadata for db '{dbName}'.", + "dbName"_attr = dbName.toString()); return Status::OK(); } catch (const DBException& ex) { return ex.toStatus(); diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp index 682954e7b43..449e812bc2c 100644 --- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp +++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp @@ -43,6 +43,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/shard_metadata_util.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard_collection.h" #include "mongo/s/catalog/type_shard_database.h" #include "mongo/s/client/shard_registry.h" @@ -90,7 +91,7 @@ void dropChunksIfEpochChanged(OperationContext* opCtx, dropChunks(opCtx, nss); if (MONGO_unlikely(hangPersistCollectionAndChangedChunksAfterDropChunks.shouldFail())) { - log() << "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint"; + LOGV2(22093, "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint"); hangPersistCollectionAndChangedChunksAfterDropChunks.pauseWhileSet(opCtx); } } @@ -954,12 +955,15 @@ void ShardServerCatalogCacheLoader::_runCollAndChunksTasks(const NamespaceString _updatePersistedCollAndChunksMetadata(context.opCtx(), nss); taskFinished = true; } catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) { - LOG(0) << "Failed to persist chunk metadata update for collection '" << nss - << "' due to shutdown."; + LOGV2(22094, + "Failed to persist chunk metadata update for collection '{nss}' due to shutdown.", + "nss"_attr = nss); inShutdown = true; } catch (const DBException& ex) { - LOG(0) << "Failed to persist chunk metadata update for collection '" << nss - << causedBy(redact(ex)); + LOGV2(22095, + "Failed to persist chunk metadata update for collection '{nss}{causedBy_ex}", + "nss"_attr = nss, + "causedBy_ex"_attr = causedBy(redact(ex))); } { @@ -988,10 +992,12 @@ void ShardServerCatalogCacheLoader::_runCollAndChunksTasks(const NamespaceString _threadPool.schedule([this, nss](auto status) { if (ErrorCodes::isCancelationError(status.code())) { - LOG(0) << "Cache loader failed to schedule a persisted metadata update" - << " task for namespace '" << nss << "' due to '" << redact(status) - << "'. Clearing task list so that scheduling will be attempted by the next" - << " caller to refresh this namespace."; + LOGV2(22096, + "Cache loader failed to schedule a persisted metadata update task for namespace " + "'{nss}' due to '{status}'. Clearing task list so that scheduling will be " + "attempted by the next caller to refresh this namespace.", + "nss"_attr = nss, + "status"_attr = redact(status)); { stdx::lock_guard<Latch> lock(_mutex); @@ -1014,11 +1020,15 @@ void ShardServerCatalogCacheLoader::_runDbTasks(StringData dbName) { _updatePersistedDbMetadata(context.opCtx(), dbName); taskFinished = true; } catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) { - LOG(0) << "Failed to persist metadata update for db '" << dbName << "' due to shutdown."; + LOGV2(22097, + "Failed to persist metadata update for db '{dbName}' due to shutdown.", + "dbName"_attr = dbName); inShutdown = true; } catch (const DBException& ex) { - LOG(0) << "Failed to persist chunk metadata update for database " << dbName - << causedBy(redact(ex)); + LOGV2(22098, + "Failed to persist chunk metadata update for database {dbName}{causedBy_ex}", + "dbName"_attr = dbName, + "causedBy_ex"_attr = causedBy(redact(ex))); } { @@ -1047,10 +1057,12 @@ void ShardServerCatalogCacheLoader::_runDbTasks(StringData dbName) { _threadPool.schedule([this, name = dbName.toString()](auto status) { if (ErrorCodes::isCancelationError(status.code())) { - LOG(0) << "Cache loader failed to schedule a persisted metadata update" - << " task for namespace '" << name << "' due to '" << redact(status) - << "'. Clearing task list so that scheduling will be attempted by the next" - << " caller to refresh this namespace."; + LOGV2(22099, + "Cache loader failed to schedule a persisted metadata update task for namespace " + "'{name}' due to '{status}'. Clearing task list so that scheduling will be " + "attempted by the next caller to refresh this namespace.", + "name"_attr = name, + "status"_attr = redact(status)); { stdx::lock_guard<Latch> lock(_mutex); diff --git a/src/mongo/db/s/sharded_connection_info.cpp b/src/mongo/db/s/sharded_connection_info.cpp index 228572e1354..7348c90c486 100644 --- a/src/mongo/db/s/sharded_connection_info.cpp +++ b/src/mongo/db/s/sharded_connection_info.cpp @@ -34,6 +34,7 @@ #include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/client.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -51,7 +52,7 @@ ShardedConnectionInfo* ShardedConnectionInfo::get(Client* client, bool create) { auto& current = clientSCI(client); if (!current && create) { - LOG(1) << "entering shard mode for connection"; + LOGV2_DEBUG(22060, 1, "entering shard mode for connection"); current.emplace(); } diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp index 7c81c06766c..ec320b06c07 100644 --- a/src/mongo/db/s/sharding_initialization_mongod.cpp +++ b/src/mongo/db/s/sharding_initialization_mongod.cpp @@ -54,6 +54,7 @@ #include "mongo/db/s/transaction_coordinator_service.h" #include "mongo/db/server_options.h" #include "mongo/executor/task_executor_pool.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/metadata/egress_metadata_hook_list.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_connection.h" @@ -102,13 +103,18 @@ public: ->getFixedExecutor() ->schedule([serviceContext = _serviceContext, connStr = state.connStr](Status status) { if (ErrorCodes::isCancelationError(status.code())) { - LOG(2) << "Unable to schedule confirmed set update due to " << status; + LOGV2_DEBUG(22067, + 2, + "Unable to schedule confirmed set update due to {status}", + "status"_attr = status); return; } invariant(status); try { - LOG(0) << "Updating config server with confirmed set " << connStr; + LOGV2(22068, + "Updating config server with confirmed set {connStr}", + "connStr"_attr = connStr); Grid::get(serviceContext)->shardRegistry()->updateReplSetHosts(connStr); if (MONGO_unlikely(failUpdateShardIdentityConfigString.shouldFail())) { @@ -130,7 +136,7 @@ public: ShardingInitializationMongoD::updateShardIdentityConfigString(opCtx.get(), connStr); } catch (const ExceptionForCat<ErrorCategory::ShutdownError>& e) { - LOG(0) << "Unable to update config server due to " << e; + LOGV2(22069, "Unable to update config server due to {e}", "e"_attr = e); } }); } @@ -138,7 +144,10 @@ public: try { Grid::get(_serviceContext)->shardRegistry()->updateReplSetHosts(state.connStr); } catch (const DBException& ex) { - LOG(2) << "Unable to update config server with possible set due to " << ex; + LOGV2_DEBUG(22070, + 2, + "Unable to update config server with possible set due to {ex}", + "ex"_attr = ex); } } void onDroppedSet(const Key&) noexcept final {} @@ -176,8 +185,11 @@ void ShardingInitializationMongoD::initializeShardingEnvironmentOnShardServer( Grid::get(opCtx)->setShardingInitialized(); - LOG(0) << "Finished initializing sharding components for " - << (isStandaloneOrPrimary ? "primary" : "secondary") << " node."; + LOGV2(22071, + "Finished initializing sharding components for {isStandaloneOrPrimary_primary_secondary} " + "node.", + "isStandaloneOrPrimary_primary_secondary"_attr = + (isStandaloneOrPrimary ? "primary" : "secondary")); } ShardingInitializationMongoD::ShardingInitializationMongoD() @@ -269,11 +281,13 @@ bool ShardingInitializationMongoD::initializeShardingAwarenessIfNeeded(Operation if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { if (!foundShardIdentity) { - warning() << "Started with --shardsvr, but no shardIdentity document was found on " - "disk in " - << NamespaceString::kServerConfigurationNamespace - << ". This most likely means this server has not yet been added to a " - "sharded cluster."; + LOGV2_WARNING(22074, + "Started with --shardsvr, but no shardIdentity document was found on " + "disk in {NamespaceString_kServerConfigurationNamespace}. This most " + "likely means this server has not yet been added to a " + "sharded cluster.", + "NamespaceString_kServerConfigurationNamespace"_attr = + NamespaceString::kServerConfigurationNamespace); return false; } @@ -292,10 +306,13 @@ bool ShardingInitializationMongoD::initializeShardingAwarenessIfNeeded(Operation } else { // Warn if a shardIdentity document is found on disk but *not* started with --shardsvr. if (!shardIdentityBSON.isEmpty()) { - warning() << "Not started with --shardsvr, but a shardIdentity document was found " - "on disk in " - << NamespaceString::kServerConfigurationNamespace << ": " - << shardIdentityBSON; + LOGV2_WARNING( + 22075, + "Not started with --shardsvr, but a shardIdentity document was found " + "on disk in {NamespaceString_kServerConfigurationNamespace}: {shardIdentityBSON}", + "NamespaceString_kServerConfigurationNamespace"_attr = + NamespaceString::kServerConfigurationNamespace, + "shardIdentityBSON"_attr = shardIdentityBSON); } return false; } @@ -310,7 +327,9 @@ void ShardingInitializationMongoD::initializeFromShardIdentity( shardIdentity.validate(), "Invalid shard identity document found when initializing sharding state"); - log() << "initializing sharding state with: " << shardIdentity; + LOGV2(22072, + "initializing sharding state with: {shardIdentity}", + "shardIdentity"_attr = shardIdentity); const auto& configSvrConnStr = shardIdentity.getConfigsvrConnectionString(); @@ -361,17 +380,24 @@ void ShardingInitializationMongoD::updateShardIdentityConfigString( auto result = update(opCtx, autoDb.getDb(), updateReq); if (result.numMatched == 0) { - warning() << "failed to update config string of shard identity document because " - << "it does not exist. This shard could have been removed from the cluster"; + LOGV2_WARNING(22076, + "failed to update config string of shard identity document because it " + "does not exist. This shard could have been removed from the cluster"); } else { - LOG(2) << "Updated config server connection string in shardIdentity document to" - << newConnectionString; + LOGV2_DEBUG(22073, + 2, + "Updated config server connection string in shardIdentity document " + "to{newConnectionString}", + "newConnectionString"_attr = newConnectionString); } } catch (const DBException& exception) { auto status = exception.toStatus(); if (!ErrorCodes::isNotMasterError(status.code())) { - warning() << "Error encountered while trying to update config connection string to " - << newConnectionString.toString() << causedBy(redact(status)); + LOGV2_WARNING(22077, + "Error encountered while trying to update config connection string to " + "{newConnectionString}{causedBy_status}", + "newConnectionString"_attr = newConnectionString.toString(), + "causedBy_status"_attr = causedBy(redact(status))); } } } diff --git a/src/mongo/db/s/sharding_logging.cpp b/src/mongo/db/s/sharding_logging.cpp index c3d07903ceb..e714e59e73d 100644 --- a/src/mongo/db/s/sharding_logging.cpp +++ b/src/mongo/db/s/sharding_logging.cpp @@ -37,6 +37,7 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/server_options.h" #include "mongo/executor/network_interface.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_changelog.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -80,7 +81,9 @@ Status ShardingLogging::logAction(OperationContext* opCtx, if (result.isOK()) { _actionLogCollectionCreated.store(1); } else { - log() << "couldn't create config.actionlog collection:" << causedBy(result); + LOGV2(22078, + "couldn't create config.actionlog collection:{causedBy_result}", + "causedBy_result"_attr = causedBy(result)); return result; } } @@ -106,7 +109,9 @@ Status ShardingLogging::logChangeChecked(OperationContext* opCtx, if (result.isOK()) { _changeLogCollectionCreated.store(1); } else { - log() << "couldn't create config.changelog collection:" << causedBy(result); + LOGV2(22079, + "couldn't create config.changelog collection:{causedBy_result}", + "causedBy_result"_attr = causedBy(result)); return result; } } @@ -144,15 +149,22 @@ Status ShardingLogging::_log(OperationContext* opCtx, changeLog.setDetails(detail); BSONObj changeLogBSON = changeLog.toBSON(); - log() << "about to log metadata event into " << logCollName << ": " << redact(changeLogBSON); + LOGV2(22080, + "about to log metadata event into {logCollName}: {changeLogBSON}", + "logCollName"_attr = logCollName, + "changeLogBSON"_attr = redact(changeLogBSON)); const NamespaceString nss("config", logCollName); Status result = Grid::get(opCtx)->catalogClient()->insertConfigDocument( opCtx, nss, changeLogBSON, writeConcern); if (!result.isOK()) { - warning() << "Error encountered while logging config change with ID [" << changeId - << "] into collection " << logCollName << ": " << redact(result); + LOGV2_WARNING(22081, + "Error encountered while logging config change with ID [{changeId}] into " + "collection {logCollName}: {result}", + "changeId"_attr = changeId, + "logCollName"_attr = logCollName, + "result"_attr = redact(result)); } return result; diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp index 441d303a038..50c127f4de0 100644 --- a/src/mongo/db/s/sharding_state.cpp +++ b/src/mongo/db/s/sharding_state.cpp @@ -35,6 +35,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -69,7 +70,9 @@ void ShardingState::setInitialized(ShardId shardId, OID clusterId) { void ShardingState::setInitialized(Status failedStatus) { invariant(!failedStatus.isOK()); - log() << "Failed to initialize sharding components" << causedBy(failedStatus); + LOGV2(22082, + "Failed to initialize sharding components{causedBy_failedStatus}", + "causedBy_failedStatus"_attr = causedBy(failedStatus)); stdx::unique_lock<Latch> ul(_mutex); invariant(_getInitializationState() == InitializationState::kNew); diff --git a/src/mongo/db/s/sharding_state_recovery.cpp b/src/mongo/db/s/sharding_state_recovery.cpp index f8a869564ca..98d7a915e49 100644 --- a/src/mongo/db/s/sharding_state_recovery.cpp +++ b/src/mongo/db/s/sharding_state_recovery.cpp @@ -50,6 +50,7 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/write_concern.h" #include "mongo/db/write_concern_options.h" +#include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -151,7 +152,10 @@ Status modifyRecoveryDocument(OperationContext* opCtx, auto const grid = Grid::get(opCtx); BSONObj updateObj = RecoveryDocument::createChangeObj(grid->configOpTime(), change); - LOG(1) << "Changing sharding recovery document " << redact(updateObj); + LOGV2_DEBUG(22083, + 1, + "Changing sharding recovery document {updateObj}", + "updateObj"_attr = redact(updateObj)); UpdateRequest updateReq(NamespaceString::kServerConfigurationNamespace); updateReq.setQuery(RecoveryDocument::getQuery()); @@ -196,7 +200,9 @@ void ShardingStateRecovery::endMetadataOp(OperationContext* opCtx) { Status status = modifyRecoveryDocument(opCtx, RecoveryDocument::Decrement, WriteConcernOptions()); if (!status.isOK()) { - warning() << "Failed to decrement minOpTimeUpdaters due to " << redact(status); + LOGV2_WARNING(22088, + "Failed to decrement minOpTimeUpdaters due to {status}", + "status"_attr = redact(status)); } } @@ -223,24 +229,30 @@ Status ShardingStateRecovery::recover(OperationContext* opCtx) { const auto recoveryDoc = std::move(recoveryDocStatus.getValue()); - log() << "Sharding state recovery process found document " << redact(recoveryDoc.toBSON()); + LOGV2(22084, + "Sharding state recovery process found document {recoveryDoc}", + "recoveryDoc"_attr = redact(recoveryDoc.toBSON())); if (!recoveryDoc.getMinOpTimeUpdaters()) { // Treat the minOpTime as up-to-date const auto prevOpTime = grid->advanceConfigOpTime( opCtx, recoveryDoc.getMinOpTime(), "sharding state recovery document"); if (prevOpTime) { - log() - << "No in flight metadata change operations, so config server optime updated from " - << *prevOpTime << " to " << recoveryDoc.getMinOpTime(); + LOGV2(22085, + "No in flight metadata change operations, so config server optime updated from " + "{prevOpTime} to {recoveryDoc_getMinOpTime}", + "prevOpTime"_attr = *prevOpTime, + "recoveryDoc_getMinOpTime"_attr = recoveryDoc.getMinOpTime()); } return Status::OK(); } - log() << "Sharding state recovery document indicates there were " - << recoveryDoc.getMinOpTimeUpdaters() - << " metadata change operations in flight. Contacting the config server primary in order " - "to retrieve the most recent opTime."; + LOGV2( + 22086, + "Sharding state recovery document indicates there were {recoveryDoc_getMinOpTimeUpdaters} " + "metadata change operations in flight. Contacting the config server primary in order " + "to retrieve the most recent opTime.", + "recoveryDoc_getMinOpTimeUpdaters"_attr = recoveryDoc.getMinOpTimeUpdaters()); // Need to fetch the latest uptime from the config server, so do a logging write Status status = ShardingLogging::get(opCtx)->logChangeChecked( @@ -252,12 +264,16 @@ Status ShardingStateRecovery::recover(OperationContext* opCtx) { if (!status.isOK()) return status; - log() << "Sharding state recovered. New config server opTime is " << grid->configOpTime(); + LOGV2(22087, + "Sharding state recovered. New config server opTime is {grid_configOpTime}", + "grid_configOpTime"_attr = grid->configOpTime()); // Finally, clear the recovery document so next time we don't need to recover status = modifyRecoveryDocument(opCtx, RecoveryDocument::Clear, kLocalWriteConcern); if (!status.isOK()) { - warning() << "Failed to reset sharding state recovery document due to " << redact(status); + LOGV2_WARNING(22089, + "Failed to reset sharding state recovery document due to {status}", + "status"_attr = redact(status)); } return Status::OK(); diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp index c56eaeb0470..61d844b6fe8 100644 --- a/src/mongo/db/s/shardsvr_shard_collection.cpp +++ b/src/mongo/db/s/shardsvr_shard_collection.cpp @@ -51,6 +51,7 @@ #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_logging.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/sharding_catalog_client_impl.h" @@ -92,7 +93,9 @@ const ReadPreferenceSetting kConfigReadSelector(ReadPreference::Nearest, TagSet{ */ void uassertStatusOKWithWarning(const Status& status) { if (!status.isOK()) { - warning() << "shardsvrShardCollection failed" << causedBy(redact(status)); + LOGV2_WARNING(22103, + "shardsvrShardCollection failed{causedBy_status}", + "causedBy_status"_attr = causedBy(redact(status))); uassertStatusOK(status); } } @@ -467,7 +470,7 @@ void logStartShardCollection(OperationContext* opCtx, const ShardsvrShardCollection& request, const ShardCollectionTargetState& prerequisites, const ShardId& dbPrimaryShardId) { - LOG(0) << "CMD: shardcollection: " << cmdObj; + LOGV2(22100, "CMD: shardcollection: {cmdObj}", "cmdObj"_attr = cmdObj); audit::logShardCollection( opCtx->getClient(), nss.ns(), prerequisites.shardKeyPattern.toBSON(), request.getUnique()); @@ -722,8 +725,12 @@ UUID shardCollection(OperationContext* opCtx, writeChunkDocumentsAndRefreshShards(*targetState, initialChunks); } - LOG(0) << "Created " << initialChunks.chunks.size() << " chunk(s) for: " << nss - << ", producing collection version " << initialChunks.collVersion(); + LOGV2(22101, + "Created {initialChunks_chunks_size} chunk(s) for: {nss}, producing collection version " + "{initialChunks_collVersion}", + "initialChunks_chunks_size"_attr = initialChunks.chunks.size(), + "nss"_attr = nss, + "initialChunks_collVersion"_attr = initialChunks.collVersion()); ShardingLogging::get(opCtx)->logChange( @@ -813,7 +820,7 @@ public: uuid); if (MONGO_unlikely(pauseShardCollectionBeforeReturning.shouldFail())) { - log() << "Hit pauseShardCollectionBeforeReturning"; + LOGV2(22102, "Hit pauseShardCollectionBeforeReturning"); pauseShardCollectionBeforeReturning.pauseWhileSet(opCtx); } diff --git a/src/mongo/db/s/split_chunk_command.cpp b/src/mongo/db/s/split_chunk_command.cpp index 4ddc478c405..2bc27bb5fb8 100644 --- a/src/mongo/db/s/split_chunk_command.cpp +++ b/src/mongo/db/s/split_chunk_command.cpp @@ -42,6 +42,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/split_chunk.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -120,7 +121,7 @@ public: auto parseShardNameStatus = bsonExtractStringField(cmdObj, "from", &shardName); uassertStatusOK(parseShardNameStatus); - log() << "received splitChunk request: " << redact(cmdObj); + LOGV2(22104, "received splitChunk request: {cmdObj}", "cmdObj"_attr = redact(cmdObj)); vector<BSONObj> splitKeys; { diff --git a/src/mongo/db/s/split_chunk_test.cpp b/src/mongo/db/s/split_chunk_test.cpp index 5adb6c0b359..563692cac50 100644 --- a/src/mongo/db/s/split_chunk_test.cpp +++ b/src/mongo/db/s/split_chunk_test.cpp @@ -42,6 +42,7 @@ #include "mongo/executor/remote_command_request.h" #include "mongo/executor/remote_command_response.h" #include "mongo/executor/task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/dist_lock_manager_mock.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_collection.h" @@ -169,8 +170,8 @@ void SplitChunkTest::expectLock() { dynamic_cast<DistLockManagerMock*>(distLock()) ->expectLock( [this](StringData name, StringData whyMessage, Milliseconds) { - LOG(0) << name; - LOG(0) << whyMessage; + LOGV2(22105, "{name}", "name"_attr = name); + LOGV2(22106, "{whyMessage}", "whyMessage"_attr = whyMessage); }, Status::OK()); } diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp index 6b257208da1..725a60f95b1 100644 --- a/src/mongo/db/s/split_vector.cpp +++ b/src/mongo/db/s/split_vector.cpp @@ -44,6 +44,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/query/plan_executor.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -130,8 +131,11 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, return emptyVector; } - log() << "request split points lookup for chunk " << nss.toString() << " " << redact(minKey) - << " -->> " << redact(maxKey); + LOGV2(22107, + "request split points lookup for chunk {nss} {minKey} -->> {maxKey}", + "nss"_attr = nss.toString(), + "minKey"_attr = redact(minKey), + "maxKey"_attr = redact(maxKey)); // We'll use the average object size and number of object to find approximately how many // keys each chunk should have. We'll split at half the maxChunkSizeBytes or @@ -141,8 +145,10 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, long long keyCount = maxChunkSizeBytes.get() / (2 * avgRecSize); if (maxChunkObjects.get() && (maxChunkObjects.get() < keyCount)) { - log() << "limiting split vector to " << maxChunkObjects.get() << " (from " << keyCount - << ") objects "; + LOGV2(22108, + "limiting split vector to {maxChunkObjects_get} (from {keyCount}) objects ", + "maxChunkObjects_get"_attr = maxChunkObjects.get(), + "keyCount"_attr = keyCount); keyCount = maxChunkObjects.get(); } @@ -195,9 +201,14 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, if (currKey.woCompare(maxKeyInChunk) == 0) { // Range contains only documents with a single key value. So we cannot possibly find a // split point, and there is no need to scan any further. - warning() << "possible low cardinality key detected in " << nss.toString() - << " - range " << redact(minKey) << " -->> " << redact(maxKey) - << " contains only the key " << redact(prettyKey(idx->keyPattern(), currKey)); + LOGV2_WARNING(22113, + "possible low cardinality key detected in {nss} - range {minKey} -->> " + "{maxKey} contains only the key {prettyKey_idx_keyPattern_currKey}", + "nss"_attr = nss.toString(), + "minKey"_attr = redact(minKey), + "maxKey"_attr = redact(maxKey), + "prettyKey_idx_keyPattern_currKey"_attr = + redact(prettyKey(idx->keyPattern(), currKey))); std::vector<BSONObj> emptyVector; return emptyVector; } @@ -232,9 +243,12 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, continue; } - log() << "Max BSON response size reached for split vector before the" - << " end of chunk " << nss.toString() << " " << redact(minKey) - << " -->> " << redact(maxKey); + LOGV2(22109, + "Max BSON response size reached for split vector before the end " + "of chunk {nss} {minKey} -->> {maxKey}", + "nss"_attr = nss.toString(), + "minKey"_attr = redact(minKey), + "maxKey"_attr = redact(maxKey)); break; } @@ -242,15 +256,22 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, splitKeys.push_back(currKey.getOwned()); currCount = 0; numChunks++; - LOG(4) << "picked a split key: " << redact(currKey); + LOGV2_DEBUG(22110, + 4, + "picked a split key: {currKey}", + "currKey"_attr = redact(currKey)); } } // Stop if we have enough split points. if (maxSplitPoints && maxSplitPoints.get() && (numChunks >= maxSplitPoints.get())) { - log() << "max number of requested split points reached (" << numChunks - << ") before the end of chunk " << nss.toString() << " " << redact(minKey) - << " -->> " << redact(maxKey); + LOGV2(22111, + "max number of requested split points reached ({numChunks}) before the " + "end of chunk {nss} {minKey} -->> {maxKey}", + "numChunks"_attr = numChunks, + "nss"_attr = nss.toString(), + "minKey"_attr = redact(minKey), + "maxKey"_attr = redact(maxKey)); break; } @@ -273,7 +294,9 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, force = false; keyCount = currCount / 2; currCount = 0; - log() << "splitVector doing another cycle because of force, keyCount now: " << keyCount; + LOGV2(22112, + "splitVector doing another cycle because of force, keyCount now: {keyCount}", + "keyCount"_attr = keyCount); exec = InternalPlanner::indexScan(opCtx, collection, @@ -294,18 +317,28 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx, // Warn for keys that are more numerous than maxChunkSizeBytes allows. for (auto it = tooFrequentKeys.cbegin(); it != tooFrequentKeys.cend(); ++it) { - warning() << "possible low cardinality key detected in " << nss.toString() - << " - key is " << redact(prettyKey(idx->keyPattern(), *it)); + LOGV2_WARNING(22114, + "possible low cardinality key detected in {nss} - key is " + "{prettyKey_idx_keyPattern_it}", + "nss"_attr = nss.toString(), + "prettyKey_idx_keyPattern_it"_attr = + redact(prettyKey(idx->keyPattern(), *it))); } // Remove the sentinel at the beginning before returning splitKeys.erase(splitKeys.begin()); if (timer.millis() > serverGlobalParams.slowMS) { - warning() << "Finding the split vector for " << nss.toString() << " over " - << redact(keyPattern) << " keyCount: " << keyCount - << " numSplits: " << splitKeys.size() << " lookedAt: " << currCount - << " took " << timer.millis() << "ms"; + LOGV2_WARNING( + 22115, + "Finding the split vector for {nss} over {keyPattern} keyCount: {keyCount} " + "numSplits: {splitKeys_size} lookedAt: {currCount} took {timer_millis}ms", + "nss"_attr = nss.toString(), + "keyPattern"_attr = redact(keyPattern), + "keyCount"_attr = keyCount, + "splitKeys_size"_attr = splitKeys.size(), + "currCount"_attr = currCount, + "timer_millis"_attr = timer.millis()); } } diff --git a/src/mongo/db/s/transaction_coordinator.cpp b/src/mongo/db/s/transaction_coordinator.cpp index 9393168a86b..f890ee3ef5a 100644 --- a/src/mongo/db/s/transaction_coordinator.cpp +++ b/src/mongo/db/s/transaction_coordinator.cpp @@ -37,6 +37,7 @@ #include "mongo/db/s/transaction_coordinator_metrics_observer.h" #include "mongo/db/s/wait_for_majority_service.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -63,7 +64,7 @@ ExecutorFuture<void> waitForMajorityWithHangFailpoint(ServiceContext* service, if (auto sfp = failpoint.scoped(); MONGO_unlikely(sfp.isActive())) { const BSONObj& data = sfp.getData(); - LOG(0) << "Hit " << failPointName << " failpoint"; + LOGV2(22445, "Hit {failPointName} failpoint", "failPointName"_attr = failPointName); // Run the hang failpoint asynchronously on a different thread to avoid self deadlocks. return ExecutorFuture<void>(executor).then( @@ -200,9 +201,14 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex } if (_decision->getDecision() == CommitDecision::kCommit) { - LOG(3) << txn::txnIdToString(_lsid, _txnNumber) - << " Advancing cluster time to the commit timestamp " - << *_decision->getCommitTimestamp(); + LOGV2_DEBUG(22446, + 3, + "{txn_txnIdToString_lsid_txnNumber} Advancing cluster time to " + "the commit timestamp {decision_getCommitTimestamp}", + "txn_txnIdToString_lsid_txnNumber"_attr = + txn::txnIdToString(_lsid, _txnNumber), + "decision_getCommitTimestamp"_attr = + *_decision->getCommitTimestamp()); uassertStatusOK(LogicalClock::get(_serviceContext) ->advanceClusterTime( @@ -382,8 +388,11 @@ void TransactionCoordinator::_done(Status status) { str::stream() << "Coordinator " << _lsid.getId() << ':' << _txnNumber << " stopped due to: " << status.reason()); - LOG(3) << txn::txnIdToString(_lsid, _txnNumber) << " Two-phase commit completed with " - << redact(status); + LOGV2_DEBUG(22447, + 3, + "{txn_txnIdToString_lsid_txnNumber} Two-phase commit completed with {status}", + "txn_txnIdToString_lsid_txnNumber"_attr = txn::txnIdToString(_lsid, _txnNumber), + "status"_attr = redact(status)); stdx::unique_lock<Latch> ul(_mutex); @@ -413,7 +422,9 @@ void TransactionCoordinator::_done(Status status) { void TransactionCoordinator::_logSlowTwoPhaseCommit( const txn::CoordinatorCommitDecision& decision) { - log() << _twoPhaseCommitInfoForLog(decision); + LOGV2(22448, + "{twoPhaseCommitInfoForLog_decision}", + "twoPhaseCommitInfoForLog_decision"_attr = _twoPhaseCommitInfoForLog(decision)); } std::string TransactionCoordinator::_twoPhaseCommitInfoForLog( diff --git a/src/mongo/db/s/transaction_coordinator_catalog.cpp b/src/mongo/db/s/transaction_coordinator_catalog.cpp index fc0612515b2..0b90a8694f3 100644 --- a/src/mongo/db/s/transaction_coordinator_catalog.cpp +++ b/src/mongo/db/s/transaction_coordinator_catalog.cpp @@ -33,6 +33,7 @@ #include "mongo/db/s/transaction_coordinator_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -46,10 +47,12 @@ TransactionCoordinatorCatalog::~TransactionCoordinatorCatalog() { void TransactionCoordinatorCatalog::exitStepUp(Status status) { if (status.isOK()) { - LOG(0) << "Incoming coordinateCommit requests are now enabled"; + LOGV2(22438, "Incoming coordinateCommit requests are now enabled"); } else { - warning() << "Coordinator recovery failed and coordinateCommit requests will not be allowed" - << causedBy(status); + LOGV2_WARNING(22444, + "Coordinator recovery failed and coordinateCommit requests will not be " + "allowed{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } stdx::lock_guard<Latch> lk(_mutex); @@ -80,8 +83,11 @@ void TransactionCoordinatorCatalog::insert(OperationContext* opCtx, TxnNumber txnNumber, std::shared_ptr<TransactionCoordinator> coordinator, bool forStepUp) { - LOG(3) << "Inserting coordinator " << lsid.getId() << ':' << txnNumber - << " into in-memory catalog"; + LOGV2_DEBUG(22439, + 3, + "Inserting coordinator {lsid_getId}:{txnNumber} into in-memory catalog", + "lsid_getId"_attr = lsid.getId(), + "txnNumber"_attr = txnNumber); stdx::unique_lock<Latch> ul(_mutex); if (!forStepUp) { @@ -153,8 +159,11 @@ TransactionCoordinatorCatalog::getLatestOnSession(OperationContext* opCtx, } void TransactionCoordinatorCatalog::_remove(const LogicalSessionId& lsid, TxnNumber txnNumber) { - LOG(3) << "Removing coordinator " << lsid.getId() << ':' << txnNumber - << " from in-memory catalog"; + LOGV2_DEBUG(22440, + 3, + "Removing coordinator {lsid_getId}:{txnNumber} from in-memory catalog", + "lsid_getId"_attr = lsid.getId(), + "txnNumber"_attr = txnNumber); stdx::lock_guard<Latch> lk(_mutex); @@ -175,7 +184,7 @@ void TransactionCoordinatorCatalog::_remove(const LogicalSessionId& lsid, TxnNum } if (_coordinatorsBySession.empty()) { - LOG(3) << "Signaling last active coordinator removed"; + LOGV2_DEBUG(22441, 3, "Signaling last active coordinator removed"); _noActiveCoordinatorsCV.notify_all(); } } @@ -185,9 +194,11 @@ void TransactionCoordinatorCatalog::join() { while (!_noActiveCoordinatorsCV.wait_for( ul, stdx::chrono::seconds{5}, [this] { return _coordinatorsBySession.empty(); })) { - LOG(0) << "After 5 seconds of wait there are still " << _coordinatorsBySession.size() - << " sessions left with active coordinators which have not yet completed"; - LOG(0) << _toString(ul); + LOGV2(22442, + "After 5 seconds of wait there are still {coordinatorsBySession_size} sessions left " + "with active coordinators which have not yet completed", + "coordinatorsBySession_size"_attr = _coordinatorsBySession.size()); + LOGV2(22443, "{ul}", "ul"_attr = _toString(ul)); } } diff --git a/src/mongo/db/s/transaction_coordinator_futures_util.cpp b/src/mongo/db/s/transaction_coordinator_futures_util.cpp index 5f19b0eeb46..f243396228e 100644 --- a/src/mongo/db/s/transaction_coordinator_futures_util.cpp +++ b/src/mongo/db/s/transaction_coordinator_futures_util.cpp @@ -36,6 +36,7 @@ #include "mongo/client/remote_command_targeter.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/s/sharding_state.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/grid.h" #include "mongo/transport/service_entry_point.h" @@ -96,7 +97,7 @@ Future<executor::TaskExecutor::ResponseStatus> AsyncWorkScheduler::scheduleRemot ->grantInternalAuthorization(opCtx->getClient()); if (MONGO_unlikely(hangWhileTargetingLocalHost.shouldFail())) { - LOG(0) << "Hit hangWhileTargetingLocalHost failpoint"; + LOGV2(22449, "Hit hangWhileTargetingLocalHost failpoint"); hangWhileTargetingLocalHost.pauseWhileSet(opCtx); } @@ -232,7 +233,9 @@ Future<AsyncWorkScheduler::HostAndShard> AsyncWorkScheduler::_targetHostAsync( const auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, shardId)); if (MONGO_unlikely(hangWhileTargetingRemoteHost.shouldFail())) { - LOG(0) << "Hit hangWhileTargetingRemoteHost failpoint for shard " << shardId; + LOGV2(22450, + "Hit hangWhileTargetingRemoteHost failpoint for shard {shardId}", + "shardId"_attr = shardId); hangWhileTargetingRemoteHost.pauseWhileSet(opCtx); } diff --git a/src/mongo/db/s/transaction_coordinator_service.cpp b/src/mongo/db/s/transaction_coordinator_service.cpp index 3ac1212a468..131a79eef8a 100644 --- a/src/mongo/db/s/transaction_coordinator_service.cpp +++ b/src/mongo/db/s/transaction_coordinator_service.cpp @@ -37,6 +37,7 @@ #include "mongo/db/s/transaction_coordinator_document_gen.h" #include "mongo/db/transaction_participant_gen.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -184,8 +185,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx, replClientInfo.setLastOpToSystemLastOpTime(opCtx); const auto lastOpTime = replClientInfo.getLastOp(); - LOG(3) << "Waiting for OpTime " << lastOpTime - << " to become majority committed"; + LOGV2_DEBUG(22451, + 3, + "Waiting for OpTime {lastOpTime} to become majority committed", + "lastOpTime"_attr = lastOpTime); WriteConcernResult unusedWCResult; uassertStatusOK(waitForWriteConcern( @@ -198,8 +201,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx, auto coordinatorDocs = txn::readAllCoordinatorDocs(opCtx); - LOG(0) << "Need to resume coordinating commit for " << coordinatorDocs.size() - << " transactions"; + LOGV2(22452, + "Need to resume coordinating commit for {coordinatorDocs_size} " + "transactions", + "coordinatorDocs_size"_attr = coordinatorDocs.size()); const auto service = opCtx->getServiceContext(); const auto clockSource = service->getFastClockSource(); @@ -208,7 +213,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx, auto& scheduler = catalogAndScheduler->scheduler; for (const auto& doc : coordinatorDocs) { - LOG(3) << "Going to resume coordinating commit for " << doc.toBSON(); + LOGV2_DEBUG(22453, + 3, + "Going to resume coordinating commit for {doc}", + "doc"_attr = doc.toBSON()); const auto lsid = *doc.getId().getSessionId(); const auto txnNumber = *doc.getId().getTxnNumber(); @@ -274,7 +282,7 @@ void TransactionCoordinatorService::joinPreviousRound() { if (!_catalogAndSchedulerToCleanup) return; - LOG(0) << "Waiting for coordinator tasks from previous term to complete"; + LOGV2(22454, "Waiting for coordinator tasks from previous term to complete"); // Block until all coordinators scheduled the previous time the service was primary to have // drained. Because the scheduler was interrupted, it should be extremely rare for there to be diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp index 93083cb9739..3d6be9ff152 100644 --- a/src/mongo/db/s/transaction_coordinator_test.cpp +++ b/src/mongo/db/s/transaction_coordinator_test.cpp @@ -39,6 +39,7 @@ #include "mongo/db/s/transaction_coordinator_document_gen.h" #include "mongo/db/s/transaction_coordinator_metrics_observer.h" #include "mongo/db/s/transaction_coordinator_test_fixture.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" #include "mongo/util/log.h" @@ -87,7 +88,9 @@ void killClientOpCtx(ServiceContext* service, const std::string& clientName) { sleepmillis(50); } - error() << "Timed out trying to find and kill client opCtx with name: " << clientName; + LOGV2_ERROR(22462, + "Timed out trying to find and kill client opCtx with name: {clientName}", + "clientName"_attr = clientName); ASSERT_FALSE(true); } @@ -1513,7 +1516,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkMetrics(expectedMetrics); - log() << "Create the coordinator."; + LOGV2(22455, "Create the coordinator."); expectedStats.createTime = advanceClockSourceAndReturnNewNow(); expectedStats.totalDuration = Microseconds(0); @@ -1531,8 +1534,9 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Start two-phase commit (allow the coordinator to progress to writing the participant " - "list)."; + LOGV2(22456, + "Start two-phase commit (allow the coordinator to progress to writing the participant " + "list)."); expectedStats.writingParticipantListStartTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); @@ -1552,7 +1556,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Allow the coordinator to progress to waiting for votes."; + LOGV2(22457, "Allow the coordinator to progress to waiting for votes."); expectedStats.waitingForVotesStartTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); @@ -1573,7 +1577,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Allow the coordinator to progress to writing the decision."; + LOGV2(22458, "Allow the coordinator to progress to writing the decision."); expectedStats.writingDecisionStartTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); @@ -1599,7 +1603,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Allow the coordinator to progress to waiting for acks."; + LOGV2(22459, "Allow the coordinator to progress to waiting for acks."); expectedStats.waitingForDecisionAcksStartTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); @@ -1623,7 +1627,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Allow the coordinator to progress to deleting the coordinator doc."; + LOGV2(22460, "Allow the coordinator to progress to deleting the coordinator doc."); expectedStats.deletingCoordinatorDocStartTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); @@ -1649,7 +1653,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) { checkStats(stats, expectedStats); checkMetrics(expectedMetrics); - log() << "Allow the coordinator to complete."; + LOGV2(22461, "Allow the coordinator to complete."); expectedStats.endTime = advanceClockSourceAndReturnNewNow(); tickSource()->advance(Microseconds(100)); diff --git a/src/mongo/db/s/transaction_coordinator_util.cpp b/src/mongo/db/s/transaction_coordinator_util.cpp index 7d98befd9d2..f0968bc0644 100644 --- a/src/mongo/db/s/transaction_coordinator_util.cpp +++ b/src/mongo/db/s/transaction_coordinator_util.cpp @@ -43,6 +43,7 @@ #include "mongo/db/s/transaction_coordinator_futures_util.h" #include "mongo/db/s/transaction_coordinator_worker_curop_repository.h" #include "mongo/db/write_concern.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -105,10 +106,13 @@ repl::OpTime persistParticipantListBlocking(OperationContext* opCtx, const LogicalSessionId& lsid, TxnNumber txnNumber, const std::vector<ShardId>& participantList) { - LOG(3) << txnIdToString(lsid, txnNumber) << " Going to write participant list"; + LOGV2_DEBUG(22463, + 3, + "{txnIdToString_lsid_txnNumber} Going to write participant list", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber)); if (MONGO_unlikely(hangBeforeWritingParticipantList.shouldFail())) { - LOG(0) << "Hit hangBeforeWritingParticipantList failpoint"; + LOGV2(22464, "Hit hangBeforeWritingParticipantList failpoint"); hangBeforeWritingParticipantList.pauseWhileSet(opCtx); } @@ -167,7 +171,10 @@ repl::OpTime persistParticipantListBlocking(OperationContext* opCtx, // Throw any other error. uassertStatusOK(upsertStatus); - LOG(3) << txnIdToString(lsid, txnNumber) << " Wrote participant list"; + LOGV2_DEBUG(22465, + 3, + "{txnIdToString_lsid_txnNumber} Wrote participant list", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber)); return repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); } @@ -240,7 +247,7 @@ Future<PrepareVoteConsensus> sendPrepare(ServiceContext* service, opCtx, lsid, txnNumber, CoordinatorAction::kSendingPrepare); if (MONGO_unlikely(hangBeforeSendingPrepare.shouldFail())) { - LOG(0) << "Hit hangBeforeSendingPrepare failpoint"; + LOGV2(22466, "Hit hangBeforeSendingPrepare failpoint"); hangBeforeSendingPrepare.pauseWhileSet(opCtx); } }; @@ -289,11 +296,14 @@ repl::OpTime persistDecisionBlocking(OperationContext* opCtx, const std::vector<ShardId>& participantList, const txn::CoordinatorCommitDecision& decision) { const bool isCommit = decision.getDecision() == txn::CommitDecision::kCommit; - LOG(3) << txnIdToString(lsid, txnNumber) << " Going to write decision " - << (isCommit ? "commit" : "abort"); + LOGV2_DEBUG(22467, + 3, + "{txnIdToString_lsid_txnNumber} Going to write decision {isCommit_commit_abort}", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber), + "isCommit_commit_abort"_attr = (isCommit ? "commit" : "abort")); if (MONGO_unlikely(hangBeforeWritingDecision.shouldFail())) { - LOG(0) << "Hit hangBeforeWritingDecision failpoint"; + LOGV2(22468, "Hit hangBeforeWritingDecision failpoint"); hangBeforeWritingDecision.pauseWhileSet(opCtx); } @@ -357,8 +367,11 @@ repl::OpTime persistDecisionBlocking(OperationContext* opCtx, << doc); } - LOG(3) << txnIdToString(lsid, txnNumber) << " Wrote decision " - << (isCommit ? "commit" : "abort"); + LOGV2_DEBUG(22469, + 3, + "{txnIdToString_lsid_txnNumber} Wrote decision {isCommit_commit_abort}", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber), + "isCommit_commit_abort"_attr = (isCommit ? "commit" : "abort")); return repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); } @@ -402,7 +415,7 @@ Future<void> sendCommit(ServiceContext* service, opCtx, lsid, txnNumber, CoordinatorAction::kSendingCommit); if (MONGO_unlikely(hangBeforeSendingCommit.shouldFail())) { - LOG(0) << "Hit hangBeforeSendingCommit failpoint"; + LOGV2(22470, "Hit hangBeforeSendingCommit failpoint"); hangBeforeSendingCommit.pauseWhileSet(opCtx); } }; @@ -432,7 +445,7 @@ Future<void> sendAbort(ServiceContext* service, opCtx, lsid, txnNumber, CoordinatorAction::kSendingAbort); if (MONGO_unlikely(hangBeforeSendingAbort.shouldFail())) { - LOG(0) << "Hit hangBeforeSendingAbort failpoint"; + LOGV2(22471, "Hit hangBeforeSendingAbort failpoint"); hangBeforeSendingAbort.pauseWhileSet(opCtx); } }; @@ -449,10 +462,13 @@ namespace { void deleteCoordinatorDocBlocking(OperationContext* opCtx, const LogicalSessionId& lsid, TxnNumber txnNumber) { - LOG(3) << txnIdToString(lsid, txnNumber) << " Going to delete coordinator doc"; + LOGV2_DEBUG(22472, + 3, + "{txnIdToString_lsid_txnNumber} Going to delete coordinator doc", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber)); if (MONGO_unlikely(hangBeforeDeletingCoordinatorDoc.shouldFail())) { - LOG(0) << "Hit hangBeforeDeletingCoordinatorDoc failpoint"; + LOGV2(22473, "Hit hangBeforeDeletingCoordinatorDoc failpoint"); hangBeforeDeletingCoordinatorDoc.pauseWhileSet(opCtx); } @@ -504,10 +520,13 @@ void deleteCoordinatorDocBlocking(OperationContext* opCtx, << doc); } - LOG(3) << txnIdToString(lsid, txnNumber) << " Deleted coordinator doc"; + LOGV2_DEBUG(22474, + 3, + "{txnIdToString_lsid_txnNumber} Deleted coordinator doc", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber)); hangAfterDeletingCoordinatorDoc.execute([&](const BSONObj& data) { - LOG(0) << "Hit hangAfterDeletingCoordinatorDoc failpoint"; + LOGV2(22475, "Hit hangAfterDeletingCoordinatorDoc failpoint"); if (!data["useUninterruptibleSleep"].eoo()) { hangAfterDeletingCoordinatorDoc.pauseWhileSet(); } else { @@ -576,8 +595,14 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service, isLocalShard, commandObj = commandObj.getOwned(), operationContextFn] { - LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator going to send command " - << commandObj << " to " << (isLocalShard ? "local " : "") << "shard " << shardId; + LOGV2_DEBUG(22476, + 3, + "{txnIdToString_lsid_txnNumber} Coordinator going to send command " + "{commandObj} to {isLocalShard_local}shard {shardId}", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber), + "commandObj"_attr = commandObj, + "isLocalShard_local"_attr = (isLocalShard ? "local " : ""), + "shardId"_attr = shardId); return scheduler .scheduleRemoteCommand( @@ -605,16 +630,26 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service, << shardId << ", which is not an expected behavior. " "Interpreting the response as vote to abort"); - LOG(0) << txnIdToString(lsid, txnNumber) << " " << redact(abortStatus); + LOGV2(22477, + "{txnIdToString_lsid_txnNumber} {abortStatus}", + "txnIdToString_lsid_txnNumber"_attr = + txnIdToString(lsid, txnNumber), + "abortStatus"_attr = redact(abortStatus)); return PrepareResponse{ shardId, PrepareVote::kAbort, boost::none, abortStatus}; } - LOG(3) << txnIdToString(lsid, txnNumber) - << " Coordinator shard received a vote to commit from shard " - << shardId - << " with prepareTimestamp: " << prepareTimestampField.timestamp(); + LOGV2_DEBUG(22478, + 3, + "{txnIdToString_lsid_txnNumber} Coordinator shard received a " + "vote to commit from shard {shardId} with prepareTimestamp: " + "{prepareTimestampField_timestamp}", + "txnIdToString_lsid_txnNumber"_attr = + txnIdToString(lsid, txnNumber), + "shardId"_attr = shardId, + "prepareTimestampField_timestamp"_attr = + prepareTimestampField.timestamp()); return PrepareResponse{shardId, PrepareVote::kCommit, @@ -622,8 +657,15 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service, boost::none}; } - LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator shard received " - << status << " from shard " << shardId << " for " << commandObj; + LOGV2_DEBUG(22479, + 3, + "{txnIdToString_lsid_txnNumber} Coordinator shard received " + "{status} from shard {shardId} for {commandObj}", + "txnIdToString_lsid_txnNumber"_attr = + txnIdToString(lsid, txnNumber), + "status"_attr = status, + "shardId"_attr = shardId, + "commandObj"_attr = commandObj); if (ErrorCodes::isVoteAbortError(status.code())) { return PrepareResponse{ @@ -652,8 +694,11 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service, return std::move(f).onError<ErrorCodes::TransactionCoordinatorReachedAbortDecision>( [lsid, txnNumber, shardId](const Status& status) { - LOG(3) << txnIdToString(lsid, txnNumber) - << " Prepare stopped retrying due to retrying being cancelled"; + LOGV2_DEBUG(22480, + 3, + "{txnIdToString_lsid_txnNumber} Prepare stopped retrying due to retrying " + "being cancelled", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber)); return PrepareResponse{shardId, boost::none, boost::none, status}; }); } @@ -682,8 +727,14 @@ Future<void> sendDecisionToShard(ServiceContext* service, isLocalShard, operationContextFn, commandObj = commandObj.getOwned()] { - LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator going to send command " - << commandObj << " to " << (isLocalShard ? "local " : "") << "shard " << shardId; + LOGV2_DEBUG(22481, + 3, + "{txnIdToString_lsid_txnNumber} Coordinator going to send command " + "{commandObj} to {isLocalShard_local}shard {shardId}", + "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber), + "commandObj"_attr = commandObj, + "isLocalShard_local"_attr = (isLocalShard ? "local " : ""), + "shardId"_attr = shardId); return scheduler .scheduleRemoteCommand( @@ -699,9 +750,15 @@ Future<void> sendDecisionToShard(ServiceContext* service, status = wcStatus; } - LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator shard received " - << status << " in response to " << commandObj << " from shard " - << shardId; + LOGV2_DEBUG(22482, + 3, + "{txnIdToString_lsid_txnNumber} Coordinator shard received " + "{status} in response to {commandObj} from shard {shardId}", + "txnIdToString_lsid_txnNumber"_attr = + txnIdToString(lsid, txnNumber), + "status"_attr = status, + "commandObj"_attr = commandObj, + "shardId"_attr = shardId); if (ErrorCodes::isVoteAbortError(status.code())) { // Interpret voteAbort errors as an ack. diff --git a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp index 01bd1fed90a..6246e02d1ae 100644 --- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp +++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp @@ -39,6 +39,7 @@ #include "mongo/db/s/transaction_coordinator_service.h" #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/log.h" @@ -99,10 +100,12 @@ public: "prepareTransaction must be run within a transaction", txnParticipant); - LOG(3) - << "Participant shard received prepareTransaction for transaction with txnNumber " - << opCtx->getTxnNumber() << " on session " - << opCtx->getLogicalSessionId()->toBSON(); + LOGV2_DEBUG(22483, + 3, + "Participant shard received prepareTransaction for transaction with " + "txnNumber {opCtx_getTxnNumber} on session {opCtx_getLogicalSessionId}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON()); uassert(ErrorCodes::NoSuchTransaction, "Transaction isn't in progress", @@ -199,10 +202,14 @@ std::set<ShardId> validateParticipants(OperationContext* opCtx, } ss << ']'; - LOG(3) << "Coordinator shard received request to coordinate commit with " - "participant list " - << ss.str() << " for " << opCtx->getLogicalSessionId()->getId() << ':' - << opCtx->getTxnNumber(); + LOGV2_DEBUG( + 22484, + 3, + "Coordinator shard received request to coordinate commit with " + "participant list {ss_str} for {opCtx_getLogicalSessionId_getId}:{opCtx_getTxnNumber}", + "ss_str"_attr = ss.str(), + "opCtx_getLogicalSessionId_getId"_attr = opCtx->getLogicalSessionId()->getId(), + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber()); return participantsSet; } @@ -234,7 +241,7 @@ public: validateParticipants(opCtx, cmd.getParticipants())); if (MONGO_unlikely(hangAfterStartingCoordinateCommit.shouldFail())) { - LOG(0) << "Hit hangAfterStartingCoordinateCommit failpoint"; + LOGV2(22485, "Hit hangAfterStartingCoordinateCommit failpoint"); hangAfterStartingCoordinateCommit.pauseWhileSet(opCtx); } @@ -274,8 +281,13 @@ public: // No coordinator was found in memory. Recover the decision from the local participant. - LOG(3) << "Going to recover decision from local participant for " - << opCtx->getLogicalSessionId()->getId() << ':' << opCtx->getTxnNumber(); + LOGV2_DEBUG(22486, + 3, + "Going to recover decision from local participant for " + "{opCtx_getLogicalSessionId_getId}:{opCtx_getTxnNumber}", + "opCtx_getLogicalSessionId_getId"_attr = + opCtx->getLogicalSessionId()->getId(), + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber()); boost::optional<SharedSemiFuture<void>> participantExitPrepareFuture; { diff --git a/src/mongo/db/s/wait_for_majority_service.cpp b/src/mongo/db/s/wait_for_majority_service.cpp index 1864335150a..d2895908c49 100644 --- a/src/mongo/db/s/wait_for_majority_service.cpp +++ b/src/mongo/db/s/wait_for_majority_service.cpp @@ -39,6 +39,7 @@ #include "mongo/db/write_concern.h" #include "mongo/executor/network_interface_factory.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/logv2/log.h" #include "mongo/util/concurrency/thread_pool.h" #include "mongo/util/log.h" @@ -184,7 +185,7 @@ void WaitForMajorityService::_periodicallyWaitForMajority(ServiceContext* servic _opCtx->waitForConditionOrInterrupt( _hasNewOpTimeCV, lk, [&] { return !_queuedOpTimes.empty() || _inShutDown; }); } catch (const DBException& e) { - LOG(1) << "Unable to wait for new op time due to: " << e; + LOGV2_DEBUG(22487, 1, "Unable to wait for new op time due to: {e}", "e"_attr = e); } _opCtx = nullptr; diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index 4cf1a4164da..b1d4409f724 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -48,6 +48,7 @@ #include "mongo/db/server_options_helpers.h" #include "mongo/logger/log_component.h" #include "mongo/logger/message_event_utf8_encoder.h" +#include "mongo/logv2/log.h" #include "mongo/transport/message_compressor_registry.h" #include "mongo/util/cmdline_utils/censor_cmdline.h" #include "mongo/util/fail_point.h" @@ -114,7 +115,9 @@ Status setParsedOpts(const moe::Environment& params) { } // namespace void printCommandLineOpts() { - log() << "options: " << serverGlobalParams.parsedOpts << endl; + LOGV2(21951, + "options: {serverGlobalParams_parsedOpts}", + "serverGlobalParams_parsedOpts"_attr = serverGlobalParams.parsedOpts); } Status validateServerOptions(const moe::Environment& params) { diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 413a113e782..bd4165f2fe2 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -144,8 +144,11 @@ void generateLegacyQueryErrorResponse(const AssertionException& exception, "ns"_attr = queryMessage.ns); if (queryMessage.ntoskip || queryMessage.ntoreturn) { - log(LogComponent::kQuery) << " ntoskip:" << queryMessage.ntoskip - << " ntoreturn:" << queryMessage.ntoreturn; + LOGV2_OPTIONS(21952, + {logComponentV1toV2(LogComponent::kQuery)}, + " ntoskip:{queryMessage_ntoskip} ntoreturn:{queryMessage_ntoreturn}", + "queryMessage_ntoskip"_attr = queryMessage.ntoskip, + "queryMessage_ntoreturn"_attr = queryMessage.ntoreturn); } BSONObjBuilder err; @@ -160,8 +163,11 @@ void generateLegacyQueryErrorResponse(const AssertionException& exception, const bool isStaleConfig = exception.code() == ErrorCodes::StaleConfig; if (isStaleConfig) { - log(LogComponent::kQuery) << "stale version detected during query over " << queryMessage.ns - << " : " << errObj; + LOGV2_OPTIONS(21953, + {logComponentV1toV2(LogComponent::kQuery)}, + "stale version detected during query over {queryMessage_ns} : {errObj}", + "queryMessage_ns"_attr = queryMessage.ns, + "errObj"_attr = errObj); } BufBuilder bb; @@ -265,7 +271,8 @@ StatusWith<repl::ReadConcernArgs> _extractReadConcern(OperationContext* opCtx, // shard/config server. if (!readConcernArgs.isSpecified()) { // TODO: Disabled until after SERVER-44539, to avoid log spam. - // log() << "Missing readConcern on " << invocation->definition()->getName(); + // LOGV2(21954, "Missing readConcern on {invocation_definition_getName}", + // "invocation_definition_getName"_attr = invocation->definition()->getName()); } } else { // A member in a regular replica set. Since these servers receive client queries, in @@ -277,8 +284,13 @@ StatusWith<repl::ReadConcernArgs> _extractReadConcern(OperationContext* opCtx, .getDefaultReadConcern(opCtx); if (rcDefault) { readConcernArgs = std::move(*rcDefault); - LOG(2) << "Applying default readConcern on " - << invocation->definition()->getName() << " of " << *rcDefault; + LOGV2_DEBUG(21955, + 2, + "Applying default readConcern on {invocation_definition_getName} " + "of {rcDefault}", + "invocation_definition_getName"_attr = + invocation->definition()->getName(), + "rcDefault"_attr = *rcDefault); // Update the readConcernSupport, since the default RC was applied. readConcernSupport = invocation->supportsReadConcern(readConcernArgs.getLevel()); @@ -364,7 +376,7 @@ LogicalTime computeOperationTime(OperationContext* opCtx, LogicalTime startOpera invariant(isReplSet); if (startOperationTime == LogicalTime::kUninitialized) { - LOG(5) << "startOperationTime is uninitialized"; + LOGV2_DEBUG(21956, 5, "startOperationTime is uninitialized"); return LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp()); } @@ -413,8 +425,11 @@ void appendClusterAndOperationTime(OperationContext* opCtx, dassert(signedTime.getTime() >= operationTime); rpc::LogicalTimeMetadata(signedTime).writeToMetadata(metadataBob); - LOG(5) << "Appending operationTime to cmd response for authorized client: " - << operationTime; + LOGV2_DEBUG( + 21957, + 5, + "Appending operationTime to cmd response for authorized client: {operationTime}", + "operationTime"_attr = operationTime); operationTime.appendAsOperationTime(commandBodyFieldsBob); return; @@ -438,7 +453,10 @@ void appendClusterAndOperationTime(OperationContext* opCtx, dassert(signedTime.getTime() >= operationTime); rpc::LogicalTimeMetadata(signedTime).writeToMetadata(metadataBob); - LOG(5) << "Appending operationTime to cmd response: " << operationTime; + LOGV2_DEBUG(21958, + 5, + "Appending operationTime to cmd response: {operationTime}", + "operationTime"_attr = operationTime); operationTime.appendAsOperationTime(commandBodyFieldsBob); } @@ -483,9 +501,14 @@ void _abortUnpreparedOrStashPreparedTransaction( txnParticipant->abortTransaction(opCtx); } catch (...) { // It is illegal for this to throw so we catch and log this here for diagnosability. - severe() << "Caught exception during transaction " << opCtx->getTxnNumber() - << (isPrepared ? " stash " : " abort ") << opCtx->getLogicalSessionId()->toBSON() - << ": " << exceptionToStatus(); + LOGV2_FATAL(21974, + "Caught exception during transaction " + "{opCtx_getTxnNumber}{isPrepared_stash_abort}{opCtx_getLogicalSessionId}: " + "{exceptionToStatus}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "isPrepared_stash_abort"_attr = (isPrepared ? " stash " : " abort "), + "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON(), + "exceptionToStatus"_attr = exceptionToStatus()); std::terminate(); } } @@ -668,7 +691,8 @@ bool runCommandImpl(OperationContext* opCtx, serverGlobalParams.clusterRole == ClusterRole::ConfigServer) && !request.body.hasField(WriteConcernOptions::kWriteConcernField)) { // TODO: Disabled until after SERVER-44539, to avoid log spam. - // log() << "Missing writeConcern on " << command->getName(); + // LOGV2(21959, "Missing writeConcern on {command_getName}", "command_getName"_attr + // = command->getName()); } extractedWriteConcern.emplace( uassertStatusOK(extractWriteConcern(opCtx, request.body))); @@ -709,9 +733,10 @@ bool runCommandImpl(OperationContext* opCtx, if (MONGO_unlikely(failWithErrorCodeInRunCommand.shouldFail())) { auto scoped = failWithErrorCodeInRunCommand.scoped(); const auto errorCode = scoped.getData()["errorCode"].numberInt(); - log() << "failWithErrorCodeInRunCommand enabled - failing command with error " - "code: " - << errorCode; + LOGV2(21960, + "failWithErrorCodeInRunCommand enabled - failing command with error " + "code: {errorCode}", + "errorCode"_attr = errorCode); BSONObjBuilder errorBuilder; errorBuilder.append("ok", 0.0); errorBuilder.append("code", errorCode); @@ -951,7 +976,10 @@ void execCommandDatabase(OperationContext* opCtx, } if (command->adminOnly()) { - LOG(2) << "command: " << request.getCommandName(); + LOGV2_DEBUG(21961, + 2, + "command: {request_getCommandName}", + "request_getCommandName"_attr = request.getCommandName()); } if (command->maintenanceMode()) { @@ -1124,11 +1152,17 @@ void execCommandDatabase(OperationContext* opCtx, } appendClusterAndOperationTime(opCtx, &extraFieldsBuilder, &metadataBob, startOperationTime); - LOG(1) << "assertion while executing command '" << request.getCommandName() << "' " - << "on database '" << request.getDatabase() << "' " - << "with arguments '" - << redact(ServiceEntryPointCommon::getRedactedCopyForLogging(command, request.body)) - << "': " << redact(e.toString()); + LOGV2_DEBUG( + 21962, + 1, + "assertion while executing command '{request_getCommandName}' on database " + "'{request_getDatabase}' with arguments " + "'{ServiceEntryPointCommon_getRedactedCopyForLogging_command_request_body}': {e}", + "request_getCommandName"_attr = request.getCommandName(), + "request_getDatabase"_attr = request.getDatabase(), + "ServiceEntryPointCommon_getRedactedCopyForLogging_command_request_body"_attr = + redact(ServiceEntryPointCommon::getRedactedCopyForLogging(command, request.body)), + "e"_attr = redact(e.toString())); generateErrorResponse(opCtx, replyBuilder, e, metadataBob.obj(), extraFieldsBuilder.obj()); } @@ -1174,7 +1208,8 @@ DbResponse receivedCommands(OperationContext* opCtx, // Otherwise, reply with the parse error. This is useful for cases where parsing fails // due to user-supplied input, such as the document too deep error. Since we failed // during parsing, we can't log anything about the command. - LOG(1) << "assertion while parsing command: " << ex.toString(); + LOGV2_DEBUG( + 21963, 1, "assertion while parsing command: {ex}", "ex"_attr = ex.toString()); generateErrorResponse( opCtx, replyBuilder.get(), ex, metadataBob.obj(), extraFieldsBuilder.obj()); @@ -1194,12 +1229,18 @@ DbResponse receivedCommands(OperationContext* opCtx, globalCommandRegistry()->incrementUnknownCommands(); std::string msg = str::stream() << "no such command: '" << request.getCommandName() << "'"; - LOG(2) << msg; + LOGV2_DEBUG(21964, 2, "{msg}", "msg"_attr = msg); uasserted(ErrorCodes::CommandNotFound, str::stream() << msg); } - LOG(2) << "run command " << request.getDatabase() << ".$cmd" << ' ' - << redact(ServiceEntryPointCommon::getRedactedCopyForLogging(c, request.body)); + LOGV2_DEBUG( + 21965, + 2, + "run command {request_getDatabase}.$cmd " + "{ServiceEntryPointCommon_getRedactedCopyForLogging_c_request_body}", + "request_getDatabase"_attr = request.getDatabase(), + "ServiceEntryPointCommon_getRedactedCopyForLogging_c_request_body"_attr = + redact(ServiceEntryPointCommon::getRedactedCopyForLogging(c, request.body))); { // Try to set this as early as possible, as soon as we have figured out the command. @@ -1218,8 +1259,13 @@ DbResponse receivedCommands(OperationContext* opCtx, appendClusterAndOperationTime( opCtx, &extraFieldsBuilder, &metadataBob, LogicalTime::kUninitialized); - LOG(1) << "assertion while executing command '" << request.getCommandName() << "' " - << "on database '" << request.getDatabase() << "': " << ex.toString(); + LOGV2_DEBUG(21966, + 1, + "assertion while executing command '{request_getCommandName}' on database " + "'{request_getDatabase}': {ex}", + "request_getCommandName"_attr = request.getCommandName(), + "request_getDatabase"_attr = request.getDatabase(), + "ex"_attr = ex.toString()); generateErrorResponse( opCtx, replyBuilder.get(), ex, metadataBob.obj(), extraFieldsBuilder.obj()); @@ -1308,7 +1354,11 @@ void receivedKillCursors(OperationContext* opCtx, const Message& m) { int found = runOpKillCursors(opCtx, static_cast<size_t>(n), cursorArray); if (shouldLog(logger::LogSeverity::Debug(1)) || found != n) { - LOG(found == n ? 1 : 0) << "killcursors: found " << found << " of " << n; + LOGV2_DEBUG(21967, + logSeverityV1toV2(found == n ? 1 : 0).toInt(), + "killcursors: found {found} of {n}", + "found"_attr = found, + "n"_attr = n); } } @@ -1523,7 +1573,9 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx, slowMsOverride = 10; receivedKillCursors(opCtx, m); } else if (op != dbInsert && op != dbUpdate && op != dbDelete) { - log() << " operation isn't supported: " << static_cast<int>(op); + LOGV2(21968, + " operation isn't supported: {static_cast_int_op}", + "static_cast_int_op"_attr = static_cast<int>(op)); currentOp.done(); forceLog = true; } else { @@ -1549,8 +1601,11 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx, } } catch (const AssertionException& ue) { LastError::get(c).setLastError(ue.code(), ue.reason()); - LOG(3) << " Caught Assertion in " << networkOpToString(op) << ", continuing " - << redact(ue); + LOGV2_DEBUG(21969, + 3, + " Caught Assertion in {networkOpToString_op}, continuing {ue}", + "networkOpToString_op"_attr = networkOpToString(op), + "ue"_attr = redact(ue)); debug.errInfo = ue.toStatus(); } // A NotMaster error can be set either within receivedInsert/receivedUpdate/receivedDelete @@ -1580,15 +1635,15 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx, if (currentOp.shouldDBProfile(shouldSample)) { // Performance profiling is on if (opCtx->lockState()->isReadLocked()) { - LOG(1) << "note: not profiling because recursive read lock"; + LOGV2_DEBUG(21970, 1, "note: not profiling because recursive read lock"); } else if (c.isInDirectClient()) { - LOG(1) << "note: not profiling because we are in DBDirectClient"; + LOGV2_DEBUG(21971, 1, "note: not profiling because we are in DBDirectClient"); } else if (behaviors.lockedForWriting()) { // TODO SERVER-26825: Fix race condition where fsyncLock is acquired post // lockedForWriting() call but prior to profile collection lock acquisition. - LOG(1) << "note: not profiling because doing fsync+lock"; + LOGV2_DEBUG(21972, 1, "note: not profiling because doing fsync+lock"); } else if (storageGlobalParams.readOnly) { - LOG(1) << "note: not profiling because server is read-only"; + LOGV2_DEBUG(21973, 1, "note: not profiling because server is read-only"); } else { invariant(!opCtx->lockState()->inAWriteUnitOfWork()); profile(opCtx, op); diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index f365c4d4987..f2ad493211e 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -47,6 +47,7 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/service_entry_point_common.h" #include "mongo/logger/redaction.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/metadata/config_server_metadata.h" #include "mongo/rpc/metadata/sharding_metadata.h" @@ -84,11 +85,18 @@ public: if (ErrorCodes::isExceededTimeLimitError(rcStatus.code())) { const int debugLevel = serverGlobalParams.clusterRole == ClusterRole::ConfigServer ? 0 : 2; - LOG(debugLevel) << "Command on database " << request.getDatabase() - << " timed out waiting for read concern to be satisfied. Command: " - << redact(ServiceEntryPointCommon::getRedactedCopyForLogging( - invocation->definition(), request.body)) - << ". Info: " << redact(rcStatus); + LOGV2_DEBUG( + 21975, + logSeverityV1toV2(debugLevel).toInt(), + "Command on database {request_getDatabase} timed out waiting for read concern " + "to be satisfied. Command: " + "{ServiceEntryPointCommon_getRedactedCopyForLogging_invocation_definition_" + "request_body}. Info: {rcStatus}", + "request_getDatabase"_attr = request.getDatabase(), + "ServiceEntryPointCommon_getRedactedCopyForLogging_invocation_definition_request_body"_attr = + redact(ServiceEntryPointCommon::getRedactedCopyForLogging( + invocation->definition(), request.body)), + "rcStatus"_attr = redact(rcStatus)); } uassertStatusOK(rcStatus); diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp index 97fbff47f89..9f21653674b 100644 --- a/src/mongo/db/session_catalog.cpp +++ b/src/mongo/db/session_catalog.cpp @@ -36,6 +36,7 @@ #include <memory> #include "mongo/db/service_context.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -153,7 +154,10 @@ void SessionCatalog::scanSessions(const SessionKiller::Matcher& matcher, { stdx::lock_guard<Latch> lg(_mutex); - LOG(2) << "Beginning scanSessions. Scanning " << _sessions.size() << " sessions."; + LOGV2_DEBUG(21976, + 2, + "Beginning scanSessions. Scanning {sessions_size} sessions.", + "sessions_size"_attr = _sessions.size()); for (auto it = _sessions.begin(); it != _sessions.end(); ++it) { if (matcher.match(it->first)) { diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp index 9094e585b35..ca8f411c165 100644 --- a/src/mongo/db/session_catalog_mongod.cpp +++ b/src/mongo/db/session_catalog_mongod.cpp @@ -45,6 +45,7 @@ #include "mongo/db/session_txn_record_gen.h" #include "mongo/db/sessions_collection.h" #include "mongo/db/transaction_participant.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/util/concurrency/thread_pool.h" @@ -195,7 +196,7 @@ void abortInProgressTransactions(OperationContext* opCtx) { << DurableTxnState_serializer(DurableTxnStateEnum::kInProgress))); auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace, query); if (cursor->more()) { - LOG(3) << "Aborting in-progress transactions on stepup."; + LOGV2_DEBUG(21977, 3, "Aborting in-progress transactions on stepup."); } while (cursor->more()) { auto txnRecord = SessionTxnRecord::parse( @@ -205,8 +206,12 @@ void abortInProgressTransactions(OperationContext* opCtx) { opCtx->setInMultiDocumentTransaction(); MongoDOperationContextSessionWithoutRefresh ocs(opCtx); auto txnParticipant = TransactionParticipant::get(opCtx); - LOG(3) << "Aborting transaction sessionId: " << txnRecord.getSessionId().toBSON() - << " txnNumber " << txnRecord.getTxnNum(); + LOGV2_DEBUG(21978, + 3, + "Aborting transaction sessionId: {txnRecord_getSessionId} txnNumber " + "{txnRecord_getTxnNum}", + "txnRecord_getSessionId"_attr = txnRecord.getSessionId().toBSON(), + "txnRecord_getTxnNum"_attr = txnRecord.getTxnNum()); txnParticipant.abortTransaction(opCtx); } } @@ -248,8 +253,13 @@ void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) { newOpCtx->setLogicalSessionId(sessionId); MongoDOperationContextSession ocs(newOpCtx.get()); auto txnParticipant = TransactionParticipant::get(newOpCtx.get()); - LOG(3) << "Restoring locks of prepared transaction. SessionId: " << sessionId.getId() - << " TxnNumber: " << txnParticipant.getActiveTxnNumber(); + LOGV2_DEBUG(21979, + 3, + "Restoring locks of prepared transaction. SessionId: {sessionId_getId} " + "TxnNumber: {txnParticipant_getActiveTxnNumber}", + "sessionId_getId"_attr = sessionId.getId(), + "txnParticipant_getActiveTxnNumber"_attr = + txnParticipant.getActiveTxnNumber()); txnParticipant.refreshLocksForPreparedTransaction(newOpCtx.get(), false); } } diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp index 892686fb26b..4faa2afdcef 100644 --- a/src/mongo/db/sessions_collection_config_server.cpp +++ b/src/mongo/db/sessions_collection_config_server.cpp @@ -38,6 +38,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/operation_context.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_commands_helpers.h" @@ -98,8 +99,12 @@ void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* BSONObj() /* collation */); return; } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) { - log() << "Attempt " << tries << " to generate TTL index for " << nss - << " received StaleShardVersion error" << causedBy(ex); + LOGV2(21980, + "Attempt {tries} to generate TTL index for {nss} received StaleShardVersion " + "error{causedBy_ex}", + "tries"_attr = tries, + "nss"_attr = nss, + "causedBy_ex"_attr = causedBy(ex)); if (canRetry) { continue; } diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp index e8c534db10e..ebfd7cf605e 100644 --- a/src/mongo/db/sorter/sorter_test.cpp +++ b/src/mongo/db/sorter/sorter_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/sorter/sorter.h" @@ -44,6 +46,8 @@ #include "mongo/unittest/unittest.h" #include "mongo/util/str.h" +#include "mongo/logv2/log.h" +#include "mongo/util/log.h" #include <memory> namespace mongo { @@ -204,8 +208,10 @@ void _assertIteratorsEquivalent(It1 it1, It2 it2, int line) { it1->closeSource(); it2->closeSource(); } catch (...) { - mongo::unittest::log() << "Failure from line " << line << " on iteration " << iteration - << std::endl; + LOGV2(22047, + "Failure from line {line} on iteration {iteration}", + "line"_attr = line, + "iteration"_attr = iteration); it1->closeSource(); it2->closeSource(); throw; diff --git a/src/mongo/db/startup_warnings_common.cpp b/src/mongo/db/startup_warnings_common.cpp index 099df94ceac..e04df02e5b2 100644 --- a/src/mongo/db/startup_warnings_common.cpp +++ b/src/mongo/db/startup_warnings_common.cpp @@ -39,6 +39,7 @@ #include "mongo/client/authenticate.h" #include "mongo/config.h" #include "mongo/db/server_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/net/ssl_options.h" #include "mongo/util/processinfo.h" @@ -56,46 +57,61 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) { { auto&& vii = VersionInfoInterface::instance(); if ((vii.minorVersion() % 2) != 0) { - log() << startupWarningsLog; - log() << "** NOTE: This is a development version (" << vii.version() << ") of MongoDB." - << startupWarningsLog; - log() << "** Not recommended for production." << startupWarningsLog; + LOGV2_OPTIONS(22116, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22117, + {logv2::LogTag::kStartupWarnings}, + "** NOTE: This is a development version ({vii_version}) of MongoDB.", + "vii_version"_attr = vii.version()); + LOGV2_OPTIONS(22118, + {logv2::LogTag::kStartupWarnings}, + "** Not recommended for production."); warned = true; } } if (serverParams.authState == ServerGlobalParams::AuthState::kUndefined) { - log() << startupWarningsLog; - log() << "** WARNING: Access control is not enabled for the database." - << startupWarningsLog; - log() << "** Read and write access to data and configuration is " - "unrestricted." - << startupWarningsLog; + LOGV2_OPTIONS(22119, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22120, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Access control is not enabled for the database."); + LOGV2_OPTIONS(22121, + {logv2::LogTag::kStartupWarnings}, + "** Read and write access to data and configuration is " + "unrestricted."); warned = true; } const bool is32bit = sizeof(int*) == 4; if (is32bit) { - log() << startupWarningsLog; - log() << "** WARNING: This 32-bit MongoDB binary is deprecated" << startupWarningsLog; + LOGV2_OPTIONS(22122, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22123, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This 32-bit MongoDB binary is deprecated"); warned = true; } #ifdef MONGO_CONFIG_SSL if (sslGlobalParams.sslAllowInvalidCertificates) { - log() << "** WARNING: While invalid X509 certificates may be used to" << startupWarningsLog; - log() << "** connect to this server, they will not be considered" - << startupWarningsLog; - log() << "** permissible for authentication." << startupWarningsLog; - log() << startupWarningsLog; + LOGV2_OPTIONS(22124, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: While invalid X509 certificates may be used to"); + LOGV2_OPTIONS(22125, + {logv2::LogTag::kStartupWarnings}, + "** connect to this server, they will not be considered"); + LOGV2_OPTIONS(22126, + {logv2::LogTag::kStartupWarnings}, + "** permissible for authentication."); + LOGV2_OPTIONS(22127, {logv2::LogTag::kStartupWarnings}, ""); } if (sslGlobalParams.sslAllowInvalidHostnames) { - log() << "** WARNING: This server will not perform X.509 hostname validation" - << startupWarningsLog; - log() << "** This may allow your server to make or accept connections to" - << startupWarningsLog; - log() << "** untrusted parties" << startupWarningsLog; + LOGV2_OPTIONS(22128, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This server will not perform X.509 hostname validation"); + LOGV2_OPTIONS(22129, + {logv2::LogTag::kStartupWarnings}, + "** This may allow your server to make or accept connections to"); + LOGV2_OPTIONS(22130, {logv2::LogTag::kStartupWarnings}, "** untrusted parties"); } #endif @@ -108,13 +124,14 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) { sslGlobalParams.sslCertificateSelector.empty() && #endif sslGlobalParams.sslCAFile.empty()) { - log() << ""; - log() << "** WARNING: No client certificate validation can be performed since" - " no CA file has been provided"; + LOGV2(22131, ""); + LOGV2(22132, + "** WARNING: No client certificate validation can be performed since" + " no CA file has been provided"); #ifdef MONGO_CONFIG_SSL_CERTIFICATE_SELECTORS - log() << "** and no sslCertificateSelector has been specified."; + LOGV2(22133, "** and no sslCertificateSelector has been specified."); #endif - log() << "** Please specify an sslCAFile parameter."; + LOGV2(22134, "** Please specify an sslCAFile parameter."); } #if defined(_WIN32) && !defined(_WIN64) @@ -122,50 +139,68 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) { BOOL wow64Process; BOOL retWow64 = IsWow64Process(GetCurrentProcess(), &wow64Process); if (retWow64 && wow64Process) { - log() << "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating" - << startupWarningsLog; - log() << "** system. Switch to a 64-bit build of MongoDB to" << startupWarningsLog; - log() << "** support larger databases." << startupWarningsLog; + LOGV2_OPTIONS(22135, + {logv2::LogTag::kStartupWarnings}, + "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating"); + LOGV2_OPTIONS(22136, + {logv2::LogTag::kStartupWarnings}, + "** system. Switch to a 64-bit build of MongoDB to"); + LOGV2_OPTIONS( + 22137, {logv2::LogTag::kStartupWarnings}, "** support larger databases."); warned = true; } #endif #if !defined(_WIN32) if (getuid() == 0) { - log() << "** WARNING: You are running this process as the root user, " - << "which is not recommended." << startupWarningsLog; + LOGV2_OPTIONS( + 22138, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: You are running this process as the root user, which is not recommended."); warned = true; } #endif if (serverParams.bind_ips.empty()) { - log() << startupWarningsLog; - log() << "** WARNING: This server is bound to localhost." << startupWarningsLog; - log() << "** Remote systems will be unable to connect to this server. " - << startupWarningsLog; - log() << "** Start the server with --bind_ip <address> to specify which IP " - << startupWarningsLog; - log() << "** addresses it should serve responses from, or with --bind_ip_all to" - << startupWarningsLog; - log() << "** bind to all interfaces. If this behavior is desired, start the" - << startupWarningsLog; - log() << "** server with --bind_ip 127.0.0.1 to disable this warning." - << startupWarningsLog; + LOGV2_OPTIONS(22139, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22140, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: This server is bound to localhost."); + LOGV2_OPTIONS(22141, + {logv2::LogTag::kStartupWarnings}, + "** Remote systems will be unable to connect to this server. "); + LOGV2_OPTIONS(22142, + {logv2::LogTag::kStartupWarnings}, + "** Start the server with --bind_ip <address> to specify which IP "); + LOGV2_OPTIONS( + 22143, + {logv2::LogTag::kStartupWarnings}, + "** addresses it should serve responses from, or with --bind_ip_all to"); + LOGV2_OPTIONS(22144, + {logv2::LogTag::kStartupWarnings}, + "** bind to all interfaces. If this behavior is desired, start the"); + LOGV2_OPTIONS(22145, + {logv2::LogTag::kStartupWarnings}, + "** server with --bind_ip 127.0.0.1 to disable this warning."); warned = true; } if (auth::hasMultipleInternalAuthKeys()) { - log() << startupWarningsLog; - log() << "** WARNING: Multiple keys specified in security key file. If cluster key file" - << startupWarningsLog; - log() << " rollover is not in progress, only one key should be specified in" - << startupWarningsLog; - log() << " the key file" << startupWarningsLog; + LOGV2_OPTIONS(22146, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 22147, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Multiple keys specified in security key file. If cluster key file"); + LOGV2_OPTIONS( + 22148, + {logv2::LogTag::kStartupWarnings}, + " rollover is not in progress, only one key should be specified in"); + LOGV2_OPTIONS(22149, {logv2::LogTag::kStartupWarnings}, " the key file"); warned = true; } if (warned) { - log() << startupWarningsLog; + LOGV2_OPTIONS(22150, {logv2::LogTag::kStartupWarnings}, ""); } } } // namespace mongo diff --git a/src/mongo/db/startup_warnings_mongod.cpp b/src/mongo/db/startup_warnings_mongod.cpp index 29a452f687e..b7b8e5fc067 100644 --- a/src/mongo/db/startup_warnings_mongod.cpp +++ b/src/mongo/db/startup_warnings_mongod.cpp @@ -43,6 +43,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/startup_warnings_common.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" #include "mongo/util/str.h" @@ -141,32 +142,46 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, bool warned = false; if (sizeof(int*) == 4) { - log() << startupWarningsLog; - log() << "** NOTE: This is a 32 bit MongoDB binary." << startupWarningsLog; - log() << "** 32 bit builds are limited to less than 2GB of data " - << "(or less with --journal)." << startupWarningsLog; + LOGV2_OPTIONS(22151, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 22152, {logv2::LogTag::kStartupWarnings}, "** NOTE: This is a 32 bit MongoDB binary."); + LOGV2_OPTIONS(22153, + {logv2::LogTag::kStartupWarnings}, + "** 32 bit builds are limited to less than 2GB of data (or less with " + "--journal)."); if (!storageParams.dur) { - log() << "** Note that journaling defaults to off for 32 bit " - << "and is currently off." << startupWarningsLog; + LOGV2_OPTIONS( + 22154, + {logv2::LogTag::kStartupWarnings}, + "** Note that journaling defaults to off for 32 bit and is currently off."); } - log() << "** See http://dochub.mongodb.org/core/32bit" << startupWarningsLog; + LOGV2_OPTIONS(22155, + {logv2::LogTag::kStartupWarnings}, + "** See http://dochub.mongodb.org/core/32bit"); warned = true; } if (!ProcessInfo::blockCheckSupported()) { - log() << startupWarningsLog; - log() << "** NOTE: your operating system version does not support the method that " - << "MongoDB" << startupWarningsLog; - log() << "** uses to detect impending page faults." << startupWarningsLog; - log() << "** This may result in slower performance for certain use " - << "cases" << startupWarningsLog; + LOGV2_OPTIONS(22156, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 22157, + {logv2::LogTag::kStartupWarnings}, + "** NOTE: your operating system version does not support the method that MongoDB"); + LOGV2_OPTIONS(22158, + {logv2::LogTag::kStartupWarnings}, + "** uses to detect impending page faults."); + LOGV2_OPTIONS(22159, + {logv2::LogTag::kStartupWarnings}, + "** This may result in slower performance for certain use cases"); warned = true; } #ifdef __linux__ if (boost::filesystem::exists("/proc/vz") && !boost::filesystem::exists("/proc/bc")) { - log() << startupWarningsLog; - log() << "** WARNING: You are running in OpenVZ which can cause issues on versions " - << "of RHEL older than RHEL6." << startupWarningsLog; + LOGV2_OPTIONS(22160, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22161, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: You are running in OpenVZ which can cause issues on versions of " + "RHEL older than RHEL6."); warned = true; } @@ -174,10 +189,13 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, try { hasMultipleNumaNodes = boost::filesystem::exists("/sys/devices/system/node/node1"); } catch (boost::filesystem::filesystem_error& e) { - log() << startupWarningsLog; - log() << "** WARNING: Cannot detect if NUMA interleaving is enabled. " - << "Failed to probe \"" << e.path1().string() << "\": " << e.code().message() - << startupWarningsLog; + LOGV2_OPTIONS(22162, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22163, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Cannot detect if NUMA interleaving is enabled. Failed to probe " + "\"{e_path1_string}\": {e_code_message}", + "e_path1_string"_attr = e.path1().string(), + "e_code_message"_attr = e.code().message()); } if (hasMultipleNumaNodes) { // We are on a box with a NUMA enabled kernel and more than 1 numa node (they start at @@ -197,27 +215,38 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, std::string line; // we only need the first line std::getline(f, line); if (f.fail()) { - warning() << "failed to read from /proc/self/numa_maps: " << errnoWithDescription() - << startupWarningsLog; + LOGV2_WARNING_OPTIONS( + 22200, + {logv2::LogTag::kStartupWarnings}, + "failed to read from /proc/self/numa_maps: {errnoWithDescription}", + "errnoWithDescription"_attr = errnoWithDescription()); warned = true; } else { // skip over pointer std::string::size_type where = line.find(' '); if ((where == std::string::npos) || (++where == line.size())) { - log() << startupWarningsLog; - log() << "** WARNING: cannot parse numa_maps line: '" << line << "'" - << startupWarningsLog; + LOGV2_OPTIONS(22164, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22165, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: cannot parse numa_maps line: '{line}'", + "line"_attr = line); warned = true; } // if the text following the space doesn't begin with 'interleave', then // issue the warning. else if (line.find("interleave", where) != where) { - log() << startupWarningsLog; - log() << "** WARNING: You are running on a NUMA machine." << startupWarningsLog; - log() << "** We suggest launching mongod like this to avoid " - << "performance problems:" << startupWarningsLog; - log() << "** numactl --interleave=all mongod [other options]" - << startupWarningsLog; + LOGV2_OPTIONS(22166, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22167, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: You are running on a NUMA machine."); + LOGV2_OPTIONS(22168, + {logv2::LogTag::kStartupWarnings}, + "** We suggest launching mongod like this to avoid " + "performance problems:"); + LOGV2_OPTIONS( + 22169, + {logv2::LogTag::kStartupWarnings}, + "** numactl --interleave=all mongod [other options]"); warned = true; } } @@ -230,10 +259,14 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, f >> val; if (val == 2) { - log() << startupWarningsLog; - log() << "** WARNING: /proc/sys/vm/overcommit_memory is " << val << startupWarningsLog; - log() << "** Journaling works best with it set to 0 or 1" - << startupWarningsLog; + LOGV2_OPTIONS(22170, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22171, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: /proc/sys/vm/overcommit_memory is {val}", + "val"_attr = val); + LOGV2_OPTIONS(22172, + {logv2::LogTag::kStartupWarnings}, + "** Journaling works best with it set to 0 or 1"); } } @@ -243,11 +276,16 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, f >> val; if (val != 0) { - log() << startupWarningsLog; - log() << "** WARNING: /proc/sys/vm/zone_reclaim_mode is " << val << startupWarningsLog; - log() << "** We suggest setting it to 0" << startupWarningsLog; - log() << "** http://www.kernel.org/doc/Documentation/sysctl/vm.txt" - << startupWarningsLog; + LOGV2_OPTIONS(22173, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22174, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: /proc/sys/vm/zone_reclaim_mode is {val}", + "val"_attr = val); + LOGV2_OPTIONS( + 22175, {logv2::LogTag::kStartupWarnings}, "** We suggest setting it to 0"); + LOGV2_OPTIONS(22176, + {logv2::LogTag::kStartupWarnings}, + "** http://www.kernel.org/doc/Documentation/sysctl/vm.txt"); } } @@ -260,16 +298,24 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, // If we do not have hugepages enabled, we don't need to warn about its features shouldWarnAboutDefragAlways = true; - log() << startupWarningsLog; - log() << "** WARNING: " << kTransparentHugePagesDirectory << "/enabled is 'always'." - << startupWarningsLog; - log() << "** We suggest setting it to 'never'" << startupWarningsLog; + LOGV2_OPTIONS(22177, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22178, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: {kTransparentHugePagesDirectory}/enabled is 'always'.", + "kTransparentHugePagesDirectory"_attr = kTransparentHugePagesDirectory); + LOGV2_OPTIONS(22179, + {logv2::LogTag::kStartupWarnings}, + "** We suggest setting it to 'never'"); warned = true; } } else if (transparentHugePagesEnabledResult.getStatus().code() != ErrorCodes::NonExistentPath) { - warning() << startupWarningsLog; - warning() << transparentHugePagesEnabledResult.getStatus().reason() << startupWarningsLog; + LOGV2_WARNING_OPTIONS(22201, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_WARNING_OPTIONS(22202, + {logv2::LogTag::kStartupWarnings}, + "{transparentHugePagesEnabledResult_getStatus_reason}", + "transparentHugePagesEnabledResult_getStatus_reason"_attr = + transparentHugePagesEnabledResult.getStatus().reason()); warned = true; } @@ -278,15 +324,23 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, if (transparentHugePagesDefragResult.isOK()) { if (shouldWarnAboutDefragAlways && transparentHugePagesDefragResult.getValue() == "always") { - log() << startupWarningsLog; - log() << "** WARNING: " << kTransparentHugePagesDirectory << "/defrag is 'always'." - << startupWarningsLog; - log() << "** We suggest setting it to 'never'" << startupWarningsLog; + LOGV2_OPTIONS(22180, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22181, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: {kTransparentHugePagesDirectory}/defrag is 'always'.", + "kTransparentHugePagesDirectory"_attr = kTransparentHugePagesDirectory); + LOGV2_OPTIONS(22182, + {logv2::LogTag::kStartupWarnings}, + "** We suggest setting it to 'never'"); warned = true; } } else if (transparentHugePagesDefragResult.getStatus().code() != ErrorCodes::NonExistentPath) { - warning() << startupWarningsLog; - warning() << transparentHugePagesDefragResult.getStatus().reason() << startupWarningsLog; + LOGV2_WARNING_OPTIONS(22203, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_WARNING_OPTIONS(22204, + {logv2::LogTag::kStartupWarnings}, + "{transparentHugePagesDefragResult_getStatus_reason}", + "transparentHugePagesDefragResult_getStatus_reason"_attr = + transparentHugePagesDefragResult.getStatus().reason()); warned = true; } #endif // __linux__ @@ -298,14 +352,21 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, if (!getrlimit(RLIMIT_NOFILE, &rlnofile)) { if (rlnofile.rlim_cur < minNumFiles) { - log() << startupWarningsLog; - log() << "** WARNING: soft rlimits too low. Number of files is " << rlnofile.rlim_cur - << ", should be at least " << minNumFiles << startupWarningsLog; + LOGV2_OPTIONS(22183, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22184, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: soft rlimits too low. Number of files is " + "{rlnofile_rlim_cur}, should be at least {minNumFiles}", + "rlnofile_rlim_cur"_attr = rlnofile.rlim_cur, + "minNumFiles"_attr = minNumFiles); } } else { const auto errmsg = errnoWithDescription(); - log() << startupWarningsLog; - log() << "** WARNING: getrlimit failed. " << errmsg << startupWarningsLog; + LOGV2_OPTIONS(22185, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22186, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: getrlimit failed. {errmsg}", + "errmsg"_attr = errmsg); } // Solaris does not have RLIMIT_MEMLOCK, these are exposed via getrctl(2) instead @@ -317,15 +378,23 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, if (!getrlimit(RLIMIT_MEMLOCK, &rlmemlock)) { if ((rlmemlock.rlim_cur / ProcessInfo::getPageSize()) < minLockedPages) { - log() << startupWarningsLog; - log() << "** WARNING: soft rlimits too low. The locked memory size is " - << rlmemlock.rlim_cur << " bytes, it should be at least " - << minLockedPages * ProcessInfo::getPageSize() << " bytes" << startupWarningsLog; + LOGV2_OPTIONS(22187, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 22188, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: soft rlimits too low. The locked memory size is {rlmemlock_rlim_cur} " + "bytes, it should be at least {minLockedPages_ProcessInfo_getPageSize} bytes", + "rlmemlock_rlim_cur"_attr = rlmemlock.rlim_cur, + "minLockedPages_ProcessInfo_getPageSize"_attr = + minLockedPages * ProcessInfo::getPageSize()); } } else { const auto errmsg = errnoWithDescription(); - log() << startupWarningsLog; - log() << "** WARNING: getrlimit failed. " << errmsg << startupWarningsLog; + LOGV2_OPTIONS(22189, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22190, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: getrlimit failed. {errmsg}", + "errmsg"_attr = errmsg); } #endif #endif @@ -334,28 +403,36 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, ProcessInfo p; if (p.hasNumaEnabled()) { - log() << startupWarningsLog; - log() << "** WARNING: You are running on a NUMA machine." << startupWarningsLog; - log() << "** We suggest disabling NUMA in the machine BIOS " << startupWarningsLog; - log() << "** by enabling interleaving to avoid performance problems. " - << startupWarningsLog; - log() << "** See your BIOS documentation for more information." - << startupWarningsLog; + LOGV2_OPTIONS(22191, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22192, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: You are running on a NUMA machine."); + LOGV2_OPTIONS(22193, + {logv2::LogTag::kStartupWarnings}, + "** We suggest disabling NUMA in the machine BIOS "); + LOGV2_OPTIONS(22194, + {logv2::LogTag::kStartupWarnings}, + "** by enabling interleaving to avoid performance problems. "); + LOGV2_OPTIONS(22195, + {logv2::LogTag::kStartupWarnings}, + "** See your BIOS documentation for more information."); warned = true; } #endif // #ifdef _WIN32 if (storageParams.engine == "ephemeralForTest") { - log() << startupWarningsLog; - log() << "** NOTE: The ephemeralForTest storage engine is for testing only. " - << startupWarningsLog; - log() << "** Do not use in production." << startupWarningsLog; + LOGV2_OPTIONS(22196, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22197, + {logv2::LogTag::kStartupWarnings}, + "** NOTE: The ephemeralForTest storage engine is for testing only. "); + LOGV2_OPTIONS( + 22198, {logv2::LogTag::kStartupWarnings}, "** Do not use in production."); warned = true; } if (warned) { - log() << startupWarningsLog; + LOGV2_OPTIONS(22199, {logv2::LogTag::kStartupWarnings}, ""); } } } // namespace mongo diff --git a/src/mongo/db/stats/counters.cpp b/src/mongo/db/stats/counters.cpp index 8e4458db7a7..0e5d0595dcd 100644 --- a/src/mongo/db/stats/counters.cpp +++ b/src/mongo/db/stats/counters.cpp @@ -35,6 +35,7 @@ #include "mongo/client/authenticate.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -63,7 +64,7 @@ void OpCounters::gotOp(int op, bool isCommand) { case opReply: break; default: - log() << "OpCounters::gotOp unknown op: " << op << std::endl; + LOGV2(22205, "OpCounters::gotOp unknown op: {op}", "op"_attr = op); } } diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp index c6ed7ee93a5..a4f8c2f4681 100644 --- a/src/mongo/db/storage/durable_catalog_impl.cpp +++ b/src/mongo/db/storage/durable_catalog_impl.cpp @@ -49,6 +49,7 @@ #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/db/storage/storage_engine_interface.h" +#include "mongo/logv2/log.h" #include "mongo/platform/bits.h" #include "mongo/platform/random.h" #include "mongo/util/log.h" @@ -219,9 +220,14 @@ public: // Intentionally ignoring failure here. Since we've removed the metadata pointing to the // index, we should never see it again anyway. if (_engine->getStorageEngine()->supportsPendingDrops() && commitTimestamp) { - log() << "Deferring table drop for index '" << _indexName << "' on collection '" - << _indexNss << (_uuid ? " (" + _uuid->toString() + ")'" : "") << ". Ident: '" - << _ident << "', commit timestamp: '" << commitTimestamp << "'"; + LOGV2(22206, + "Deferring table drop for index '{indexName}' on collection " + "'{indexNss}{uuid_uuid}. Ident: '{ident}', commit timestamp: '{commitTimestamp}'", + "indexName"_attr = _indexName, + "indexNss"_attr = _indexNss, + "uuid_uuid"_attr = (_uuid ? " (" + _uuid->toString() + ")'" : ""), + "ident"_attr = _ident, + "commitTimestamp"_attr = commitTimestamp); _engine->addDropPendingIdent(*commitTimestamp, _indexNss, _ident); } else { auto kvEngine = _engine->getEngine(); @@ -345,7 +351,9 @@ DurableCatalogImpl::FeatureTracker::FeatureBits DurableCatalogImpl::FeatureTrack auto nonRepairableFeaturesStatus = bsonExtractTypedField( obj, kNonRepairableFeaturesFieldName, BSONType::NumberLong, &nonRepairableFeaturesElem); if (!nonRepairableFeaturesStatus.isOK()) { - error() << "error: exception extracting typed field with obj:" << redact(obj); + LOGV2_ERROR(22215, + "error: exception extracting typed field with obj:{obj}", + "obj"_attr = redact(obj)); fassert(40111, nonRepairableFeaturesStatus); } @@ -353,7 +361,9 @@ DurableCatalogImpl::FeatureTracker::FeatureBits DurableCatalogImpl::FeatureTrack auto repairableFeaturesStatus = bsonExtractTypedField( obj, kRepairableFeaturesFieldName, BSONType::NumberLong, &repairableFeaturesElem); if (!repairableFeaturesStatus.isOK()) { - error() << "error: exception extracting typed field with obj:" << redact(obj); + LOGV2_ERROR(22216, + "error: exception extracting typed field with obj:{obj}", + "obj"_attr = redact(obj)); fassert(40112, repairableFeaturesStatus); } @@ -539,7 +549,11 @@ StatusWith<DurableCatalog::Entry> DurableCatalogImpl::_addEntry(OperationContext _catalogIdToEntryMap[res.getValue()] = {res.getValue(), ident, nss}; opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, res.getValue())); - LOG(1) << "stored meta data for " << nss.ns() << " @ " << res.getValue(); + LOGV2_DEBUG(22207, + 1, + "stored meta data for {nss_ns} @ {res_getValue}", + "nss_ns"_attr = nss.ns(), + "res_getValue"_attr = res.getValue()); return {{res.getValue(), ident, nss}}; } @@ -552,7 +566,7 @@ std::string DurableCatalogImpl::getIndexIdent(OperationContext* opCtx, } BSONObj DurableCatalogImpl::_findEntry(OperationContext* opCtx, RecordId catalogId) const { - LOG(3) << "looking up metadata for: " << catalogId; + LOGV2_DEBUG(22208, 3, "looking up metadata for: {catalogId}", "catalogId"_attr = catalogId); RecordData data; if (!_rs->findRecord(opCtx, catalogId, &data)) { // since the in memory meta data isn't managed with mvcc @@ -567,11 +581,11 @@ BSONObj DurableCatalogImpl::_findEntry(OperationContext* opCtx, RecordId catalog BSONCollectionCatalogEntry::MetaData DurableCatalogImpl::getMetaData(OperationContext* opCtx, RecordId catalogId) const { BSONObj obj = _findEntry(opCtx, catalogId); - LOG(3) << " fetched CCE metadata: " << obj; + LOGV2_DEBUG(22209, 3, " fetched CCE metadata: {obj}", "obj"_attr = obj); BSONCollectionCatalogEntry::MetaData md; const BSONElement mdElement = obj["md"]; if (mdElement.isABSONObj()) { - LOG(3) << "returning metadata: " << mdElement; + LOGV2_DEBUG(22210, 3, "returning metadata: {mdElement}", "mdElement"_attr = mdElement); md.parse(mdElement.Obj()); } return md; @@ -632,7 +646,7 @@ void DurableCatalogImpl::putMetaData(OperationContext* opCtx, opCtx->recoveryUnit()->setMustBeTimestamped(); } - LOG(3) << "recording new metadata: " << obj; + LOGV2_DEBUG(22211, 3, "recording new metadata: {obj}", "obj"_attr = obj); Status status = _rs->updateRecord(opCtx, catalogId, obj.objdata(), obj.objsize()); fassert(28521, status); } @@ -693,7 +707,11 @@ Status DurableCatalogImpl::_removeEntry(OperationContext* opCtx, RecordId catalo opCtx->recoveryUnit()->registerChange( std::make_unique<RemoveIdentChange>(this, catalogId, it->second)); - LOG(1) << "deleting metadata for " << it->second.nss << " @ " << catalogId; + LOGV2_DEBUG(22212, + 1, + "deleting metadata for {it_second_nss} @ {catalogId}", + "it_second_nss"_attr = it->second.nss, + "catalogId"_attr = catalogId); _rs->deleteRecord(opCtx, catalogId); _catalogIdToEntryMap.erase(it); @@ -781,7 +799,11 @@ StatusWith<std::string> DurableCatalogImpl::newOrphanedIdent(OperationContext* o _catalogIdToEntryMap[res.getValue()] = Entry(res.getValue(), ident, ns); opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, res.getValue())); - LOG(1) << "stored meta data for orphaned collection " << ns << " @ " << res.getValue(); + LOGV2_DEBUG(22213, + 1, + "stored meta data for orphaned collection {ns} @ {res_getValue}", + "ns"_attr = ns, + "res_getValue"_attr = res.getValue()); return {ns.ns()}; } @@ -871,8 +893,12 @@ Status DurableCatalogImpl::dropCollection(OperationContext* opCtx, RecordId cata StorageEngineInterface* engine = catalog->_engine; auto storageEngine = engine->getStorageEngine(); if (storageEngine->supportsPendingDrops() && commitTimestamp) { - log() << "Deferring table drop for collection '" << entry.nss - << "'. Ident: " << entry.ident << ", commit timestamp: " << commitTimestamp; + LOGV2(22214, + "Deferring table drop for collection '{entry_nss}'. Ident: {entry_ident}, " + "commit timestamp: {commitTimestamp}", + "entry_nss"_attr = entry.nss, + "entry_ident"_attr = entry.ident, + "commitTimestamp"_attr = commitTimestamp); engine->addDropPendingIdent(*commitTimestamp, entry.nss, entry.ident); } else { // Intentionally ignoring failure here. Since we've removed the metadata pointing to diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp index a390b43664e..05f665e90de 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp @@ -34,6 +34,7 @@ #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h" #include "mongo/db/storage/sorted_data_interface.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -78,7 +79,10 @@ void EphemeralForTestRecoveryUnit::doAbortUnitOfWork() { for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend(); it != end; ++it) { auto change = *it; - LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change)); + LOGV2_DEBUG(22217, + 2, + "CUSTOM ROLLBACK {demangleName_typeid_change}", + "demangleName_typeid_change"_attr = demangleName(typeid(*change))); change->rollback(); } _changes.clear(); diff --git a/src/mongo/db/storage/flow_control.cpp b/src/mongo/db/storage/flow_control.cpp index 0552357f45c..4e0c957fda6 100644 --- a/src/mongo/db/storage/flow_control.cpp +++ b/src/mongo/db/storage/flow_control.cpp @@ -44,6 +44,7 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/server_options.h" #include "mongo/db/storage/flow_control_parameters_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/background.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -103,8 +104,11 @@ Timestamp getMedianAppliedTimestamp(const std::vector<repl::MemberData>& sortedM bool sustainerAdvanced(const std::vector<repl::MemberData>& prevMemberData, const std::vector<repl::MemberData>& currMemberData) { if (currMemberData.size() == 0 || currMemberData.size() != prevMemberData.size()) { - warning() << "Flow control detected a change in topology. PrevMemberSize: " - << prevMemberData.size() << " CurrMemberSize: " << currMemberData.size(); + LOGV2_WARNING(22223, + "Flow control detected a change in topology. PrevMemberSize: " + "{prevMemberData_size} CurrMemberSize: {currMemberData_size}", + "prevMemberData_size"_attr = prevMemberData.size(), + "currMemberData_size"_attr = currMemberData.size()); return false; } @@ -112,8 +116,11 @@ bool sustainerAdvanced(const std::vector<repl::MemberData>& prevMemberData, auto prevSustainerAppliedTs = getMedianAppliedTimestamp(prevMemberData); if (currSustainerAppliedTs < prevSustainerAppliedTs) { - warning() << "Flow control's sustainer time decreased. PrevSustainer: " - << prevSustainerAppliedTs << " CurrSustainer: " << currSustainerAppliedTs; + LOGV2_WARNING(22224, + "Flow control's sustainer time decreased. PrevSustainer: " + "{prevSustainerAppliedTs} CurrSustainer: {currSustainerAppliedTs}", + "prevSustainerAppliedTs"_attr = prevSustainerAppliedTs, + "currSustainerAppliedTs"_attr = currSustainerAppliedTs); return false; } @@ -240,9 +247,13 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>& const std::int64_t sustainerAppliedCount = _approximateOpsBetween(prevSustainerAppliedTs, currSustainerAppliedTs); - LOG(DEBUG_LOG_LEVEL) << " PrevApplied: " << prevSustainerAppliedTs - << " CurrApplied: " << currSustainerAppliedTs - << " NumSustainerApplied: " << sustainerAppliedCount; + LOGV2_DEBUG(22218, + logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(), + " PrevApplied: {prevSustainerAppliedTs} CurrApplied: {currSustainerAppliedTs} " + "NumSustainerApplied: {sustainerAppliedCount}", + "prevSustainerAppliedTs"_attr = prevSustainerAppliedTs, + "currSustainerAppliedTs"_attr = currSustainerAppliedTs, + "sustainerAppliedCount"_attr = sustainerAppliedCount); if (sustainerAppliedCount > 0) { _lastTimeSustainerAdvanced = Date_t::now(); } else { @@ -250,8 +261,9 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>& const auto now = Date_t::now(); if (warnThresholdSeconds > 0 && now - _lastTimeSustainerAdvanced >= Seconds(warnThresholdSeconds)) { - warning() << "Flow control is engaged and the sustainer point is not moving. Please " - "check the health of all secondaries."; + LOGV2_WARNING(22225, + "Flow control is engaged and the sustainer point is not moving. Please " + "check the health of all secondaries."); // Log once every `warnThresholdSeconds` seconds. _lastTimeSustainerAdvanced = now; @@ -285,9 +297,17 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>& // an environment where secondaries consistently process operations slower than the primary. double sustainerAppliedPenalty = sustainerAppliedCount * reduce * gFlowControlFudgeFactor.load(); - LOG(DEBUG_LOG_LEVEL) << "Sustainer: " << sustainerAppliedCount << " LagMillis: " << lagMillis - << " Threshold lag: " << thresholdLagMillis << " Exponent: " << exponent - << " Reduce: " << reduce << " Penalty: " << sustainerAppliedPenalty; + LOGV2_DEBUG(22219, + logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(), + "Sustainer: {sustainerAppliedCount} LagMillis: {lagMillis} Threshold lag: " + "{thresholdLagMillis} Exponent: {exponent} Reduce: {reduce} Penalty: " + "{sustainerAppliedPenalty}", + "sustainerAppliedCount"_attr = sustainerAppliedCount, + "lagMillis"_attr = lagMillis, + "thresholdLagMillis"_attr = thresholdLagMillis, + "exponent"_attr = exponent, + "reduce"_attr = reduce, + "sustainerAppliedPenalty"_attr = sustainerAppliedPenalty); return multiplyWithOverflowCheck(locksPerOp, sustainerAppliedPenalty, _kMaxTickets); } @@ -375,19 +395,29 @@ int FlowControl::getNumTickets() { ret = std::max(ret, gFlowControlMinTicketsPerSecond.load()); - LOG(DEBUG_LOG_LEVEL) << "Are lagged? " << (_isLagged.load() ? "true" : "false") - << " Curr lag millis: " - << getLagMillis(myLastApplied.wallTime, lastCommitted.wallTime) - << " OpsLagged: " - << _approximateOpsBetween(lastCommitted.opTime.getTimestamp(), - myLastApplied.opTime.getTimestamp()) - << " Granting: " << ret - << " Last granted: " << _lastTargetTicketsPermitted.load() - << " Last sustainer applied: " << _lastSustainerAppliedCount.load() - << " Acquisitions since last check: " << locksUsedLastPeriod - << " Locks per op: " << _lastLocksPerOp.load() - << " Count of lagged periods: " << _isLaggedCount.load() - << " Total duration of lagged periods: " << _isLaggedTimeMicros.load(); + LOGV2_DEBUG( + 22220, + logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(), + "Are lagged? {isLagged_load_true_false} Curr lag millis: " + "{getLagMillis_myLastApplied_wallTime_lastCommitted_wallTime} OpsLagged: " + "{approximateOpsBetween_lastCommitted_opTime_getTimestamp_myLastApplied_opTime_" + "getTimestamp} Granting: {ret} Last granted: {lastTargetTicketsPermitted_load} Last " + "sustainer applied: {lastSustainerAppliedCount_load} Acquisitions since last check: " + "{locksUsedLastPeriod} Locks per op: {lastLocksPerOp_load} Count of lagged periods: " + "{isLaggedCount_load} Total duration of lagged periods: {isLaggedTimeMicros_load}", + "isLagged_load_true_false"_attr = (_isLagged.load() ? "true" : "false"), + "getLagMillis_myLastApplied_wallTime_lastCommitted_wallTime"_attr = + getLagMillis(myLastApplied.wallTime, lastCommitted.wallTime), + "approximateOpsBetween_lastCommitted_opTime_getTimestamp_myLastApplied_opTime_getTimestamp"_attr = + _approximateOpsBetween(lastCommitted.opTime.getTimestamp(), + myLastApplied.opTime.getTimestamp()), + "ret"_attr = ret, + "lastTargetTicketsPermitted_load"_attr = _lastTargetTicketsPermitted.load(), + "lastSustainerAppliedCount_load"_attr = _lastSustainerAppliedCount.load(), + "locksUsedLastPeriod"_attr = locksUsedLastPeriod, + "lastLocksPerOp_load"_attr = _lastLocksPerOp.load(), + "isLaggedCount_load"_attr = _isLaggedCount.load(), + "isLaggedTimeMicros_load"_attr = _isLaggedTimeMicros.load()); _lastTargetTicketsPermitted.store(ret); @@ -449,8 +479,13 @@ void FlowControl::sample(Timestamp timestamp, std::uint64_t opsApplied) { _lastSample = _numOpsSinceStartup; const auto lockAcquisitions = stats.get(resourceIdGlobal, LockMode::MODE_IX).numAcquisitions; - LOG(DEBUG_LOG_LEVEL) << "Sampling. Time: " << timestamp << " Applied: " << _numOpsSinceStartup - << " LockAcquisitions: " << lockAcquisitions; + LOGV2_DEBUG(22221, + logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(), + "Sampling. Time: {timestamp} Applied: {numOpsSinceStartup} LockAcquisitions: " + "{lockAcquisitions}", + "timestamp"_attr = timestamp, + "numOpsSinceStartup"_attr = _numOpsSinceStartup, + "lockAcquisitions"_attr = lockAcquisitions); if (_sampledOpsApplied.size() < static_cast<std::deque<Sample>::size_type>(gFlowControlMaxSamples)) { @@ -479,7 +514,10 @@ void FlowControl::_trimSamples(const Timestamp trimTo) { ++numTrimmed; } - LOG(DEBUG_LOG_LEVEL) << "Trimmed samples. Num: " << numTrimmed; + LOGV2_DEBUG(22222, + logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(), + "Trimmed samples. Num: {numTrimmed}", + "numTrimmed"_attr = numTrimmed); } int64_t FlowControl::_getLocksUsedLastPeriod() { diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index db6ceb39e29..f9489633c6b 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -48,6 +48,7 @@ #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/config.h" #include "mongo/db/storage/key_string.h" +#include "mongo/logv2/log.h" #include "mongo/platform/decimal128.h" #include "mongo/stdx/future.h" #include "mongo/unittest/death_test.h" @@ -97,8 +98,11 @@ public: version = KeyString::Version::V1; base->run(); } catch (...) { - log() << "exception while testing KeyStringBuilder version " - << mongo::KeyString::keyStringVersionToString(version); + LOGV2(22226, + "exception while testing KeyStringBuilder version " + "{mongo_KeyString_keyStringVersionToString_version}", + "mongo_KeyString_keyStringVersionToString_version"_attr = + mongo::KeyString::keyStringVersionToString(version)); throw; } } @@ -351,8 +355,12 @@ TEST_F(KeyStringBuilderTest, ActualBytesDouble) { BSONObj a = BSON("" << 5.5); KeyString::Builder ks(version, a, ALL_ASCENDING); - log() << keyStringVersionToString(version) << " size: " << ks.getSize() << " hex [" - << toHex(ks.getBuffer(), ks.getSize()) << "]"; + LOGV2(22227, + "{keyStringVersionToString_version} size: {ks_getSize} hex " + "[{toHex_ks_getBuffer_ks_getSize}]", + "keyStringVersionToString_version"_attr = keyStringVersionToString(version), + "ks_getSize"_attr = ks.getSize(), + "toHex_ks_getBuffer_ks_getSize"_attr = toHex(ks.getBuffer(), ks.getSize())); ASSERT_EQUALS(10U, ks.getSize()); @@ -484,7 +492,7 @@ TEST_F(KeyStringBuilderTest, NumbersNearInt32Max) { TEST_F(KeyStringBuilderTest, DecimalNumbers) { if (version == KeyString::Version::V0) { - log() << "not testing DecimalNumbers for KeyStringBuilder V0"; + LOGV2(22228, "not testing DecimalNumbers for KeyStringBuilder V0"); return; } @@ -1172,7 +1180,7 @@ void testPermutation(KeyString::Version version, BSONObj orderObj = orderings[k]; Ordering ordering = Ordering::make(orderObj); if (debug) - log() << "ordering: " << orderObj; + LOGV2(22229, "ordering: {orderObj}", "orderObj"_attr = orderObj); std::vector<BSONObj> elements = elementsOrig; BSONObjComparator bsonCmp(orderObj, @@ -1183,7 +1191,7 @@ void testPermutation(KeyString::Version version, for (size_t i = 0; i < elements.size(); i++) { const BSONObj& o1 = elements[i]; if (debug) - log() << "\to1: " << o1; + LOGV2(22230, "\to1: {o1}", "o1"_attr = o1); ROUNDTRIP_ORDER(version, o1, ordering); KeyString::Builder k1(version, o1, ordering); @@ -1191,7 +1199,7 @@ void testPermutation(KeyString::Version version, if (i + 1 < elements.size()) { const BSONObj& o2 = elements[i + 1]; if (debug) - log() << "\t\t o2: " << o2; + LOGV2(22231, "\t\t o2: {o2}", "o2"_attr = o2); KeyString::Builder k2(version, o2, ordering); int bsonCmp = o1.woCompare(o2, ordering); @@ -1225,7 +1233,7 @@ std::mt19937_64 seedGen(rd()); // To be used by perf test for seeding, so that the entire test is repeatable in case of error. unsigned newSeed() { unsigned int seed = seedGen(); // Replace by the reported number to repeat test execution. - log() << "Initializing random number generator using seed " << seed; + LOGV2(22232, "Initializing random number generator using seed {seed}", "seed"_attr = seed); return seed; }; @@ -1237,8 +1245,10 @@ std::vector<BSONObj> thinElements(std::vector<BSONObj> elements, if (elements.size() <= maxElements) return elements; - log() << "only keeping " << maxElements << " of " << elements.size() - << " elements using random selection"; + LOGV2(22233, + "only keeping {maxElements} of {elements_size} elements using random selection", + "maxElements"_attr = maxElements, + "elements_size"_attr = elements.size()); std::shuffle(elements.begin(), elements.end(), gen); elements.resize(maxElements); return elements; @@ -1284,7 +1294,10 @@ TEST_F(KeyStringBuilderTest, AllPerm2Compare) { } } - log() << "AllPerm2Compare " << keyStringVersionToString(version) << " size:" << elements.size(); + LOGV2(22234, + "AllPerm2Compare {keyStringVersionToString_version} size:{elements_size}", + "keyStringVersionToString_version"_attr = keyStringVersionToString(version), + "elements_size"_attr = elements.size()); for (size_t i = 0; i < elements.size(); i++) { const BSONObj& o = elements[i]; @@ -1443,7 +1456,10 @@ TEST_F(KeyStringBuilderTest, NumberOrderLots) { if (a.compare(b) != compareNumbers(numbers[i].firstElement(), numbers[j].firstElement())) { - log() << numbers[i] << " " << numbers[j]; + LOGV2(22235, + "{numbers_i} {numbers_j}", + "numbers_i"_attr = numbers[i], + "numbers_j"_attr = numbers[j]); } ASSERT_EQUALS(a.compare(b), @@ -1755,10 +1771,17 @@ void perfTest(KeyString::Version version, const Numbers& numbers) { auto minmax = std::minmax_element( numbers.begin(), numbers.end(), SimpleBSONObjComparator::kInstance.makeLessThan()); - log() << 1E3 * micros / static_cast<double>(iters * numbers.size()) << " ns per " - << mongo::KeyString::keyStringVersionToString(version) << " roundtrip" - << (kDebugBuild ? " (DEBUG BUILD!)" : "") << " min " << (*minmax.first)[""] << ", max" - << (*minmax.second)[""]; + LOGV2(22236, + "{_1E3_micros_static_cast_double_iters_numbers_size} ns per " + "{mongo_KeyString_keyStringVersionToString_version} roundtrip{kDebugBuild_DEBUG_BUILD} " + "min {minmax_first}, max{minmax_second}", + "_1E3_micros_static_cast_double_iters_numbers_size"_attr = + 1E3 * micros / static_cast<double>(iters * numbers.size()), + "mongo_KeyString_keyStringVersionToString_version"_attr = + mongo::KeyString::keyStringVersionToString(version), + "kDebugBuild_DEBUG_BUILD"_attr = (kDebugBuild ? " (DEBUG BUILD!)" : ""), + "minmax_first"_attr = (*minmax.first)[""], + "minmax_second"_attr = (*minmax.second)[""]); } } // namespace diff --git a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp index a68cbfe58f1..4e8927b2017 100644 --- a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp +++ b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp @@ -37,6 +37,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/storage/write_unit_of_work.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -57,9 +58,12 @@ void KVDropPendingIdentReaper::addDropPendingIdent(const Timestamp& dropTimestam info.ident = ident.toString(); _dropPendingIdents.insert(std::make_pair(dropTimestamp, info)); } else { - severe() << "Failed to add drop-pending ident " << ident << " (" << nss << ")" - << " with drop timestamp " << dropTimestamp - << ": duplicate timestamp and ident pair."; + LOGV2_FATAL(22238, + "Failed to add drop-pending ident {ident} ({nss}) with drop timestamp " + "{dropTimestamp}: duplicate timestamp and ident pair.", + "ident"_attr = ident, + "nss"_attr = nss, + "dropTimestamp"_attr = dropTimestamp); fassertFailedNoTrace(51023); } } @@ -109,13 +113,22 @@ void KVDropPendingIdentReaper::dropIdentsOlderThan(OperationContext* opCtx, cons const auto& identInfo = timestampAndIdentInfo.second; const auto& nss = identInfo.nss; const auto& ident = identInfo.ident; - log() << "Completing drop for ident " << ident << " (ns: " << nss - << ") with drop timestamp " << dropTimestamp; + LOGV2( + 22237, + "Completing drop for ident {ident} (ns: {nss}) with drop timestamp {dropTimestamp}", + "ident"_attr = ident, + "nss"_attr = nss, + "dropTimestamp"_attr = dropTimestamp); WriteUnitOfWork wuow(opCtx); auto status = _engine->dropIdent(opCtx, opCtx->recoveryUnit(), ident); if (!status.isOK()) { - severe() << "Failed to remove drop-pending ident " << ident << "(ns: " << nss - << ") with drop timestamp " << dropTimestamp << ": " << status; + LOGV2_FATAL(22239, + "Failed to remove drop-pending ident {ident}(ns: {nss}) with drop " + "timestamp {dropTimestamp}: {status}", + "ident"_attr = ident, + "nss"_attr = nss, + "dropTimestamp"_attr = dropTimestamp, + "status"_attr = status); fassertFailedNoTrace(51022); } wuow.commit(); diff --git a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp index a418badd579..88792e3709b 100644 --- a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp +++ b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp @@ -47,6 +47,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/record_store.h" #include "mongo/logger/logstream_builder.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" @@ -56,7 +57,7 @@ namespace mongo { bool OplogCapMaintainerThread::_deleteExcessDocuments() { if (!getGlobalServiceContext()->getStorageEngine()) { - LOG(2) << "OplogCapMaintainerThread: no global storage engine yet"; + LOGV2_DEBUG(22240, 2, "OplogCapMaintainerThread: no global storage engine yet"); return false; } @@ -81,7 +82,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() { auto databaseHolder = DatabaseHolder::get(opCtx.get()); auto db = databaseHolder->getDb(opCtx.get(), oplogNss.db()); if (!db) { - LOG(2) << "no local database yet"; + LOGV2_DEBUG(22241, 2, "no local database yet"); return false; } // We need to hold the database lock while getting the collection. Otherwise a @@ -90,7 +91,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() { Collection* collection = CollectionCatalog::get(opCtx.get()) .lookupCollectionByNamespace(opCtx.get(), oplogNss); if (!collection) { - LOG(2) << "no collection " << oplogNss; + LOGV2_DEBUG(22242, 2, "no collection {oplogNss}", "oplogNss"_attr = oplogNss); return false; } rs = collection->getRecordStore(); @@ -102,7 +103,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() { } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { return false; } catch (const std::exception& e) { - severe() << "error in OplogCapMaintainerThread: " << e.what(); + LOGV2_FATAL(22243, "error in OplogCapMaintainerThread: {e_what}", "e_what"_attr = e.what()); fassertFailedNoTrace(!"error in OplogCapMaintainerThread"); } catch (...) { fassertFailedNoTrace(!"unknown error in OplogCapMaintainerThread"); diff --git a/src/mongo/db/storage/recovery_unit.cpp b/src/mongo/db/storage/recovery_unit.cpp index 3d167d7a9c3..35d605a5cdc 100644 --- a/src/mongo/db/storage/recovery_unit.cpp +++ b/src/mongo/db/storage/recovery_unit.cpp @@ -32,6 +32,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/storage/recovery_unit.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -74,7 +75,10 @@ void RecoveryUnit::commitRegisteredChanges(boost::optional<Timestamp> commitTime for (auto& change : _changes) { try { // Log at higher level because commits occur far more frequently than rollbacks. - LOG(3) << "CUSTOM COMMIT " << redact(demangleName(typeid(*change))); + LOGV2_DEBUG(22244, + 3, + "CUSTOM COMMIT {demangleName_typeid_change}", + "demangleName_typeid_change"_attr = redact(demangleName(typeid(*change)))); change->commit(commitTimestamp); } catch (...) { std::terminate(); @@ -90,7 +94,10 @@ void RecoveryUnit::abortRegisteredChanges() { it != end; ++it) { Change* change = it->get(); - LOG(2) << "CUSTOM ROLLBACK " << redact(demangleName(typeid(*change))); + LOGV2_DEBUG(22245, + 2, + "CUSTOM ROLLBACK {demangleName_typeid_change}", + "demangleName_typeid_change"_attr = redact(demangleName(typeid(*change)))); change->rollback(); } _changes.clear(); diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp index 2a4091b1f4e..1cbe9cc86ec 100644 --- a/src/mongo/db/storage/storage_engine_impl.cpp +++ b/src/mongo/db/storage/storage_engine_impl.cpp @@ -50,6 +50,7 @@ #include "mongo/db/storage/storage_repair_observer.h" #include "mongo/db/storage/two_phase_index_build_knobs_gen.h" #include "mongo/db/unclean_shutdown.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/unordered_map.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -90,11 +91,13 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) { auto repairObserver = StorageRepairObserver::get(getGlobalServiceContext()); invariant(repairObserver->isIncomplete()); - log() << "Repairing catalog metadata"; + LOGV2(22246, "Repairing catalog metadata"); Status status = _engine->repairIdent(opCtx, catalogInfo); if (status.code() == ErrorCodes::DataModifiedByRepair) { - warning() << "Catalog data modified by repair: " << status.reason(); + LOGV2_WARNING(22264, + "Catalog data modified by repair: {status_reason}", + "status_reason"_attr = status.reason()); repairObserver->invalidatingModification(str::stream() << "DurableCatalog repaired: " << status.reason()); } else { @@ -159,12 +162,14 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) { if (statusWithNs.isOK()) { wuow.commit(); auto orphanCollNs = statusWithNs.getValue(); - log() << "Successfully created an entry in the catalog for the orphaned " - "collection: " - << orphanCollNs; - warning() << orphanCollNs - << " does not have the _id index. Please manually " - "build the index."; + LOGV2(22247, + "Successfully created an entry in the catalog for the orphaned " + "collection: {orphanCollNs}", + "orphanCollNs"_attr = orphanCollNs); + LOGV2_WARNING(22265, + "{orphanCollNs} does not have the _id index. Please manually " + "build the index.", + "orphanCollNs"_attr = orphanCollNs); StorageRepairObserver::get(getGlobalServiceContext()) ->benignModification(str::stream() << "Orphan collection created: " @@ -173,10 +178,14 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) { } else { // Log an error message if we cannot create the entry. // reconcileCatalogAndIdents() will later drop this ident. - error() << "Cannot create an entry in the catalog for the orphaned " - "collection ident: " - << ident << " due to " << statusWithNs.getStatus().reason(); - error() << "Restarting the server will remove this ident."; + LOGV2_ERROR( + 22268, + "Cannot create an entry in the catalog for the orphaned " + "collection ident: {ident} due to {statusWithNs_getStatus_reason}", + "ident"_attr = ident, + "statusWithNs_getStatus_reason"_attr = + statusWithNs.getStatus().reason()); + LOGV2_ERROR(22269, "Restarting the server will remove this ident."); } } } @@ -201,8 +210,11 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) { auto status = _recoverOrphanedCollection(opCtx, entry.catalogId, entry.nss, collectionIdent); if (!status.isOK()) { - warning() << "Failed to recover orphaned data file for collection '" - << entry.nss << "': " << status; + LOGV2_WARNING(22266, + "Failed to recover orphaned data file for collection " + "'{entry_nss}': {status}", + "entry_nss"_attr = entry.nss, + "status"_attr = status); WriteUnitOfWork wuow(opCtx); fassert(50716, _catalog->_removeEntry(opCtx, entry.catalogId)); @@ -223,7 +235,7 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) { maxSeenPrefix = std::max(maxSeenPrefix, maxPrefixForCollection); if (entry.nss.isOrphanCollection()) { - log() << "Orphaned collection found: " << entry.nss; + LOGV2(22248, "Orphaned collection found: {entry_nss}", "entry_nss"_attr = entry.nss); } } @@ -284,9 +296,11 @@ Status StorageEngineImpl::_recoverOrphanedCollection(OperationContext* opCtx, if (!_options.forRepair) { return {ErrorCodes::IllegalOperation, "Orphan recovery only supported in repair"}; } - log() << "Storage engine is missing collection '" << collectionName - << "' from its metadata. Attempting to locate and recover the data for " - << collectionIdent; + LOGV2(22249, + "Storage engine is missing collection '{collectionName}' from its metadata. Attempting " + "to locate and recover the data for {collectionIdent}", + "collectionName"_attr = collectionName, + "collectionIdent"_attr = collectionIdent); WriteUnitOfWork wuow(opCtx); const auto metadata = _catalog->getMetaData(opCtx, catalogId); @@ -376,12 +390,14 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn // These idents have to be retained as long as the corresponding drops are not part of a // checkpoint. if (dropPendingIdents.find(it) != dropPendingIdents.cend()) { - log() << "Not removing ident for uncheckpointed collection or index drop: " << it; + LOGV2(22250, + "Not removing ident for uncheckpointed collection or index drop: {it}", + "it"_attr = it); continue; } const auto& toRemove = it; - log() << "Dropping unknown ident: " << toRemove; + LOGV2(22251, "Dropping unknown ident: {toRemove}", "toRemove"_attr = toRemove); WriteUnitOfWork wuow(opCtx); fassert(40591, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), toRemove)); wuow.commit(); @@ -427,11 +443,14 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn indexMetaData.multikeyPaths.end(), [](auto& pathSet) { return pathSet.size() > 0; }); if (!indexMetaData.multikey && hasMultiKeyPaths) { - warning() << "The 'multikey' field for index " << indexName << " on collection " - << coll << " was false with non-empty 'multikeyPaths'. This indicates " - << "corruption of the catalog. Consider either dropping and recreating " - << "the index, or rerunning with the --repair option. See " - << "http://dochub.mongodb.org/core/repair for more information."; + LOGV2_WARNING(22267, + "The 'multikey' field for index {indexName} on collection {coll} was " + "false with non-empty 'multikeyPaths'. This indicates corruption of " + "the catalog. Consider either dropping and recreating the index, or " + "rerunning with the --repair option. See " + "http://dochub.mongodb.org/core/repair for more information.", + "indexName"_attr = indexName, + "coll"_attr = coll); } const bool foundIdent = engineIdents.find(indexIdent) != engineIdents.end(); @@ -440,8 +459,11 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn // majority of nodes. The code will rebuild the index, despite potentially // encountering another `dropIndex` command. if (indexMetaData.ready && !foundIdent) { - log() << "Expected index data is missing, rebuilding. Collection: " << coll - << " Index: " << indexName; + LOGV2(22252, + "Expected index data is missing, rebuilding. Collection: {coll} Index: " + "{indexName}", + "coll"_attr = coll, + "indexName"_attr = indexName); ret.indexesToRebuild.push_back({entry.catalogId, coll, indexName}); continue; } @@ -456,8 +478,13 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn invariant(collUUID); auto buildUUID = *indexMetaData.buildUUID; - log() << "Found index from unfinished build. Collection: " << coll << " (" - << *collUUID << "), index: " << indexName << ", build UUID: " << buildUUID; + LOGV2(22253, + "Found index from unfinished build. Collection: {coll} ({collUUID}), index: " + "{indexName}, build UUID: {buildUUID}", + "coll"_attr = coll, + "collUUID"_attr = *collUUID, + "indexName"_attr = indexName, + "buildUUID"_attr = buildUUID); // Insert in the map if a build has not already been registered. auto existingIt = ret.indexBuildsToRestart.find(buildUUID); @@ -476,17 +503,21 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn // will return the index to be rebuilt. if (indexMetaData.isBackgroundSecondaryBuild && (!foundIdent || !indexMetaData.ready)) { if (!serverGlobalParams.indexBuildRetry) { - log() << "Dropping an unfinished index because --noIndexBuildRetry is set. " - "Collection: " - << coll << " Index: " << indexName; + LOGV2(22254, + "Dropping an unfinished index because --noIndexBuildRetry is set. " + "Collection: {coll} Index: {indexName}", + "coll"_attr = coll, + "indexName"_attr = indexName); fassert(51197, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), indexIdent)); indexesToDrop.push_back(indexName); continue; } - log() << "Expected background index build did not complete, rebuilding. " - "Collection: " - << coll << " Index: " << indexName; + LOGV2(22255, + "Expected background index build did not complete, rebuilding. " + "Collection: {coll} Index: {indexName}", + "coll"_attr = coll, + "indexName"_attr = indexName); ret.indexesToRebuild.push_back({entry.catalogId, coll, indexName}); continue; } @@ -498,8 +529,10 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn // index when it replays the oplog. In these cases the index entry in the catalog // should be dropped. if (!indexMetaData.ready && !indexMetaData.isBackgroundSecondaryBuild) { - log() << "Dropping unfinished index. Collection: " << coll - << " Index: " << indexName; + LOGV2(22256, + "Dropping unfinished index. Collection: {coll} Index: {indexName}", + "coll"_attr = coll, + "indexName"_attr = indexName); // Ensure the `ident` is dropped while we have the `indexIdent` value. fassert(50713, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), indexIdent)); indexesToDrop.push_back(indexName); @@ -520,7 +553,7 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn } for (auto&& temp : internalIdentsToDrop) { - log() << "Dropping internal ident: " << temp; + LOGV2(22257, "Dropping internal ident: {temp}", "temp"_attr = temp); WriteUnitOfWork wuow(opCtx); fassert(51067, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), temp)); wuow.commit(); @@ -730,7 +763,10 @@ std::unique_ptr<TemporaryRecordStore> StorageEngineImpl::makeTemporaryRecordStor OperationContext* opCtx) { std::unique_ptr<RecordStore> rs = _engine->makeTemporaryRecordStore(opCtx, _catalog->newInternalIdent()); - LOG(1) << "created temporary record store: " << rs->getIdent(); + LOGV2_DEBUG(22258, + 1, + "created temporary record store: {rs_getIdent}", + "rs_getIdent"_attr = rs->getIdent()); return std::make_unique<TemporaryKVRecordStore>(getEngine(), std::move(rs)); } @@ -799,7 +835,9 @@ StatusWith<Timestamp> StorageEngineImpl::recoverToStableTimestamp(OperationConte catalog::openCatalog(opCtx, state); - log() << "recoverToStableTimestamp successful. Stable Timestamp: " << swTimestamp.getValue(); + LOGV2(22259, + "recoverToStableTimestamp successful. Stable Timestamp: {swTimestamp_getValue}", + "swTimestamp_getValue"_attr = swTimestamp.getValue()); return {swTimestamp.getValue()}; } @@ -907,8 +945,9 @@ void StorageEngineImpl::_onMinOfCheckpointAndOldestTimestampChanged(const Timest // No drop-pending idents present if getEarliestDropTimestamp() returns boost::none. if (auto earliestDropTimestamp = _dropPendingIdentReaper.getEarliestDropTimestamp()) { if (timestamp > *earliestDropTimestamp) { - log() << "Removing drop-pending idents with drop timestamps before timestamp " - << timestamp; + LOGV2(22260, + "Removing drop-pending idents with drop timestamps before timestamp {timestamp}", + "timestamp"_attr = timestamp); auto opCtx = cc().getOperationContext(); invariant(opCtx); @@ -930,7 +969,7 @@ StorageEngineImpl::TimestampMonitor::TimestampMonitor(KVEngine* engine, Periodic } StorageEngineImpl::TimestampMonitor::~TimestampMonitor() { - log() << "Timestamp monitor shutting down"; + LOGV2(22261, "Timestamp monitor shutting down"); stdx::lock_guard<Latch> lock(_monitorMutex); invariant(_listeners.empty()); } @@ -938,7 +977,7 @@ StorageEngineImpl::TimestampMonitor::~TimestampMonitor() { void StorageEngineImpl::TimestampMonitor::startup() { invariant(!_running); - log() << "Timestamp monitor starting"; + LOGV2(22262, "Timestamp monitor starting"); PeriodicRunner::PeriodicJob job( "TimestampMonitor", [&](Client* client) { @@ -998,7 +1037,10 @@ void StorageEngineImpl::TimestampMonitor::startup() { } } catch (const ExceptionFor<ErrorCodes::InterruptedAtShutdown>& ex) { // If we're interrupted at shutdown, it's fine to give up on future notifications - log() << "Timestamp monitor is stopping due to: " + ex.reason(); + LOGV2(22263, + "{Timestamp_monitor_is_stopping_due_to_ex_reason}", + "Timestamp_monitor_is_stopping_due_to_ex_reason"_attr = + "Timestamp monitor is stopping due to: " + ex.reason()); return; } }, diff --git a/src/mongo/db/storage/storage_engine_init.cpp b/src/mongo/db/storage/storage_engine_init.cpp index c2fe7559438..ab3e8e9b032 100644 --- a/src/mongo/db/storage/storage_engine_init.cpp +++ b/src/mongo/db/storage/storage_engine_init.cpp @@ -45,6 +45,7 @@ #include "mongo/db/storage/storage_options.h" #include "mongo/db/storage/storage_repair_observer.h" #include "mongo/db/unclean_shutdown.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -78,10 +79,11 @@ void initializeStorageEngine(ServiceContext* service, const StorageEngineInitFla if (storageGlobalParams.repair) { repairObserver->onRepairStarted(); } else if (repairObserver->isIncomplete()) { - severe() - << "An incomplete repair has been detected! This is likely because a repair " - "operation unexpectedly failed before completing. MongoDB will not start up " - "again without --repair."; + LOGV2_FATAL( + 22272, + "An incomplete repair has been detected! This is likely because a repair " + "operation unexpectedly failed before completing. MongoDB will not start up " + "again without --repair."); fassertFailedNoTrace(50922); } } @@ -104,9 +106,13 @@ void initializeStorageEngine(ServiceContext* service, const StorageEngineInitFla } } else { // Otherwise set the active storage engine as the contents of the metadata file. - log() << "Detected data files in " << dbpath << " created by the '" - << *existingStorageEngine << "' storage engine, so setting the active" - << " storage engine to '" << *existingStorageEngine << "'."; + LOGV2( + 22270, + "Detected data files in {dbpath} created by the '{existingStorageEngine}' storage " + "engine, so setting the active storage engine to '{existingStorageEngine2}'.", + "dbpath"_attr = dbpath, + "existingStorageEngine"_attr = *existingStorageEngine, + "existingStorageEngine2"_attr = *existingStorageEngine); storageGlobalParams.engine = *existingStorageEngine; } } @@ -205,11 +211,14 @@ void createLockFile(ServiceContext* service) { if (wasUnclean) { if (storageGlobalParams.readOnly) { - severe() << "Attempted to open dbpath in readOnly mode, but the server was " - "previously not shut down cleanly."; + LOGV2_FATAL(22273, + "Attempted to open dbpath in readOnly mode, but the server was " + "previously not shut down cleanly."); fassertFailedNoTrace(34416); } - warning() << "Detected unclean shutdown - " << lockFile->getFilespec() << " is not empty."; + LOGV2_WARNING(22271, + "Detected unclean shutdown - {lockFile_getFilespec} is not empty.", + "lockFile_getFilespec"_attr = lockFile->getFilespec()); startingAfterUncleanShutdown(service) = true; } } diff --git a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp index c0398eddec3..aba21904fa5 100644 --- a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp +++ b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp @@ -42,6 +42,7 @@ #include <sys/types.h> #include <unistd.h> +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -56,14 +57,16 @@ void flushMyDirectory(const boost::filesystem::path& file) { // so make a warning. need a better solution longer term. // massert(40389, str::stream() << "Couldn't find parent dir for file: " << file.string(),); if (!file.has_branch_path()) { - log() << "warning flushMyDirectory couldn't find parent dir for file: " << file.string(); + LOGV2(22274, + "warning flushMyDirectory couldn't find parent dir for file: {file_string}", + "file_string"_attr = file.string()); return; } boost::filesystem::path dir = file.branch_path(); // parent_path in new boosts - LOG(1) << "flushing directory " << dir.string(); + LOGV2_DEBUG(22275, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string()); int fd = ::open(dir.string().c_str(), O_RDONLY); // DO NOT THROW OR ASSERT BEFORE CLOSING massert(40387, @@ -74,12 +77,17 @@ void flushMyDirectory(const boost::filesystem::path& file) { int e = errno; if (e == EINVAL) { // indicates filesystem does not support synchronization if (!_warnedAboutFilesystem) { - log() << "\tWARNING: This file system is not supported. For further information" - << " see:" << startupWarningsLog; - log() << "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems" - << startupWarningsLog; - log() << "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated " - << "this warning." << startupWarningsLog; + LOGV2_OPTIONS( + 22276, + {logv2::LogTag::kStartupWarnings}, + "\tWARNING: This file system is not supported. For further information see:"); + LOGV2_OPTIONS(22277, + {logv2::LogTag::kStartupWarnings}, + "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems"); + LOGV2_OPTIONS(22278, + {logv2::LogTag::kStartupWarnings}, + "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated " + "this warning."); _warnedAboutFilesystem = true; } } else { @@ -225,13 +233,15 @@ void StorageEngineLockFile::clearPidAndUnlock() { if (!_lockFileHandle->isValid()) { return; } - log() << "shutdown: removing fs lock..."; + LOGV2(22279, "shutdown: removing fs lock..."); // This ought to be an unlink(), but Eliot says the last // time that was attempted, there was a race condition // with StorageEngineLockFile::open(). if (::ftruncate(_lockFileHandle->_fd, 0)) { int errorcode = errno; - log() << "couldn't remove fs lock " << errnoWithDescription(errorcode); + LOGV2(22280, + "couldn't remove fs lock {errnoWithDescription_errorcode}", + "errnoWithDescription_errorcode"_attr = errnoWithDescription(errorcode)); } close(); } diff --git a/src/mongo/db/storage/storage_engine_lock_file_windows.cpp b/src/mongo/db/storage/storage_engine_lock_file_windows.cpp index 4055318d1d8..e6a152b4262 100644 --- a/src/mongo/db/storage/storage_engine_lock_file_windows.cpp +++ b/src/mongo/db/storage/storage_engine_lock_file_windows.cpp @@ -38,6 +38,7 @@ #include <ostream> #include <sstream> +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" #include "mongo/util/text.h" @@ -184,13 +185,13 @@ void StorageEngineLockFile::clearPidAndUnlock() { if (!_lockFileHandle->isValid()) { return; } - log() << "shutdown: removing fs lock..."; + LOGV2(22281, "shutdown: removing fs lock..."); // This ought to be an unlink(), but Eliot says the last // time that was attempted, there was a race condition // with StorageEngineLockFile::open(). Status status = _truncateFile(_lockFileHandle->_handle); if (!status.isOK()) { - log() << "couldn't remove fs lock " << status.toString(); + LOGV2(22282, "couldn't remove fs lock {status}", "status"_attr = status.toString()); } CloseHandle(_lockFileHandle->_handle); _lockFileHandle->clear(); diff --git a/src/mongo/db/storage/storage_engine_metadata.cpp b/src/mongo/db/storage/storage_engine_metadata.cpp index ecf401f3ee9..f02288a1edd 100644 --- a/src/mongo/db/storage/storage_engine_metadata.cpp +++ b/src/mongo/db/storage/storage_engine_metadata.cpp @@ -51,6 +51,7 @@ #include "mongo/base/data_type_validated.h" #include "mongo/db/bson/dotted_path_support.h" #include "mongo/db/jsobj.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/object_check.h" #include "mongo/util/assert_util.h" #include "mongo/util/file.h" @@ -85,7 +86,9 @@ std::unique_ptr<StorageEngineMetadata> StorageEngineMetadata::forPath(const std: metadata.reset(new StorageEngineMetadata(dbpath)); Status status = metadata->read(); if (!status.isOK()) { - error() << "Unable to read the storage engine metadata file: " << status; + LOGV2_ERROR(22288, + "Unable to read the storage engine metadata file: {status}", + "status"_attr = status); fassertFailedNoTrace(28661); } } @@ -219,14 +222,16 @@ void flushMyDirectory(const boost::filesystem::path& file) { // so make a warning. need a better solution longer term. // massert(13652, str::stream() << "Couldn't find parent dir for file: " << file.string(),); if (!file.has_branch_path()) { - log() << "warning flushMyDirectory couldn't find parent dir for file: " << file.string(); + LOGV2(22283, + "warning flushMyDirectory couldn't find parent dir for file: {file_string}", + "file_string"_attr = file.string()); return; } boost::filesystem::path dir = file.branch_path(); // parent_path in new boosts - LOG(1) << "flushing directory " << dir.string(); + LOGV2_DEBUG(22284, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string()); int fd = ::open(dir.string().c_str(), O_RDONLY); // DO NOT THROW OR ASSERT BEFORE CLOSING massert(13650, @@ -237,12 +242,17 @@ void flushMyDirectory(const boost::filesystem::path& file) { int e = errno; if (e == EINVAL) { // indicates filesystem does not support synchronization if (!_warnedAboutFilesystem) { - log() << "\tWARNING: This file system is not supported. For further information" - << " see:" << startupWarningsLog; - log() << "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems" - << startupWarningsLog; - log() << "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated " - << "this warning." << startupWarningsLog; + LOGV2_OPTIONS( + 22285, + {logv2::LogTag::kStartupWarnings}, + "\tWARNING: This file system is not supported. For further information see:"); + LOGV2_OPTIONS(22286, + {logv2::LogTag::kStartupWarnings}, + "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems"); + LOGV2_OPTIONS(22287, + {logv2::LogTag::kStartupWarnings}, + "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated " + "this warning."); _warnedAboutFilesystem = true; } } else { diff --git a/src/mongo/db/storage/storage_file_util.cpp b/src/mongo/db/storage/storage_file_util.cpp index dd47a85642d..2a457ccf3a5 100644 --- a/src/mongo/db/storage/storage_file_util.cpp +++ b/src/mongo/db/storage/storage_file_util.cpp @@ -42,6 +42,7 @@ #include <boost/filesystem/path.hpp> +#include "mongo/logv2/log.h" #include "mongo/util/file.h" #include "mongo/util/log.h" @@ -67,7 +68,7 @@ Status fsyncParentDirectory(const boost::filesystem::path& file) { boost::filesystem::path dir = file.parent_path(); - LOG(1) << "flushing directory " << dir.string(); + LOGV2_DEBUG(22289, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string()); int fd = ::open(dir.string().c_str(), O_RDONLY); if (fd < 0) { @@ -78,7 +79,8 @@ Status fsyncParentDirectory(const boost::filesystem::path& file) { if (fsync(fd) != 0) { int e = errno; if (e == EINVAL) { - warning() << "Could not fsync directory because this file system is not supported."; + LOGV2_WARNING(22290, + "Could not fsync directory because this file system is not supported."); } else { close(fd); return {ErrorCodes::OperationFailed, diff --git a/src/mongo/db/storage/storage_repair_observer_test.cpp b/src/mongo/db/storage/storage_repair_observer_test.cpp index b9bb17e818f..fa653febf9b 100644 --- a/src/mongo/db/storage/storage_repair_observer_test.cpp +++ b/src/mongo/db/storage/storage_repair_observer_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include <boost/filesystem.hpp> @@ -37,8 +39,10 @@ #include "mongo/db/repl/replication_coordinator_mock.h" #include "mongo/db/service_context_d_test_fixture.h" #include "mongo/db/storage/storage_repair_observer.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/log.h" namespace mongo { namespace { @@ -107,9 +111,11 @@ public: } if (repairObserver->isDone() && repairObserver->isDataInvalidated()) { - unittest::log() << "Modifications: "; + LOGV2(22291, "Modifications: "); for (const auto& mod : repairObserver->getModifications()) { - unittest::log() << " " << mod.getDescription(); + LOGV2(22292, + " {mod_getDescription}", + "mod_getDescription"_attr = mod.getDescription()); } } } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp index 7e708bfded2..d4b4a497bb9 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp @@ -33,6 +33,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace moe = mongo::optionenvironment; @@ -49,15 +50,22 @@ Status WiredTigerGlobalOptions::store(const moe::Environment& params) { } if (!wiredTigerGlobalOptions.engineConfig.empty()) { - log() << "Engine custom option: " << wiredTigerGlobalOptions.engineConfig; + LOGV2(22293, + "Engine custom option: {wiredTigerGlobalOptions_engineConfig}", + "wiredTigerGlobalOptions_engineConfig"_attr = wiredTigerGlobalOptions.engineConfig); } if (!wiredTigerGlobalOptions.collectionConfig.empty()) { - log() << "Collection custom option: " << wiredTigerGlobalOptions.collectionConfig; + LOGV2(22294, + "Collection custom option: {wiredTigerGlobalOptions_collectionConfig}", + "wiredTigerGlobalOptions_collectionConfig"_attr = + wiredTigerGlobalOptions.collectionConfig); } if (!wiredTigerGlobalOptions.indexConfig.empty()) { - log() << "Index custom option: " << wiredTigerGlobalOptions.indexConfig; + LOGV2(22295, + "Index custom option: {wiredTigerGlobalOptions_indexConfig}", + "wiredTigerGlobalOptions_indexConfig"_attr = wiredTigerGlobalOptions.indexConfig); } return Status::OK(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp index ec034eccc34..da0e63a957a 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp @@ -51,6 +51,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_server_status.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" @@ -67,7 +68,7 @@ public: virtual StorageEngine* create(const StorageGlobalParams& params, const StorageEngineLockFile* lockFile) const { if (lockFile && lockFile->createdByUncleanShutdown()) { - warning() << "Recovering data from the last clean checkpoint."; + LOGV2_WARNING(22302, "Recovering data from the last clean checkpoint."); } #if defined(__linux__) @@ -79,13 +80,16 @@ public: int ret = statfs(params.dbpath.c_str(), &fs_stats); if (ret == 0 && fs_stats.f_type == EXT4_SUPER_MAGIC) { - log() << startupWarningsLog; - log() << "** WARNING: Using the XFS filesystem is strongly recommended with the " - "WiredTiger storage engine" - << startupWarningsLog; - log() << "** See " - "http://dochub.mongodb.org/core/prodnotes-filesystem" - << startupWarningsLog; + LOGV2_OPTIONS(22296, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS( + 22297, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Using the XFS filesystem is strongly recommended with the " + "WiredTiger storage engine"); + LOGV2_OPTIONS(22298, + {logv2::LogTag::kStartupWarnings}, + "** See " + "http://dochub.mongodb.org/core/prodnotes-filesystem"); } } #endif @@ -95,13 +99,17 @@ public: ProcessInfo p; if (p.supported()) { if (cacheMB > memoryThresholdPercentage * p.getMemSizeMB()) { - log() << startupWarningsLog; - log() << "** WARNING: The configured WiredTiger cache size is more than " - << memoryThresholdPercentage * 100 << "% of available RAM." - << startupWarningsLog; - log() << "** See " - "http://dochub.mongodb.org/core/faq-memory-diagnostics-wt" - << startupWarningsLog; + LOGV2_OPTIONS(22299, {logv2::LogTag::kStartupWarnings}, ""); + LOGV2_OPTIONS(22300, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: The configured WiredTiger cache size is more than " + "{memoryThresholdPercentage_100}% of available RAM.", + "memoryThresholdPercentage_100"_attr = + memoryThresholdPercentage * 100); + LOGV2_OPTIONS(22301, + {logv2::LogTag::kStartupWarnings}, + "** See " + "http://dochub.mongodb.org/core/faq-memory-diagnostics-wt"); } } const bool ephemeral = false; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 5e220754e7e..2d39e7336a3 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -83,6 +83,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h" +#include "mongo/logv2/log.h" #include "mongo/platform/atomic_word.h" #include "mongo/util/background.h" #include "mongo/util/concurrency/idle_thread_block.h" @@ -197,7 +198,7 @@ public: virtual void run() { ThreadClient tc(name(), getGlobalServiceContext()); - LOG(1) << "starting " << name() << " thread"; + LOGV2_DEBUG(22303, 1, "starting {name} thread", "name"_attr = name()); while (!_shuttingDown.load()) { { @@ -210,7 +211,7 @@ public: _sessionCache->closeExpiredIdleSessions(gWiredTigerSessionCloseIdleTimeSecs.load() * 1000); } - LOG(1) << "stopping " << name() << " thread"; + LOGV2_DEBUG(22304, 1, "stopping {name} thread", "name"_attr = name()); } void shutdown() { @@ -245,7 +246,7 @@ public: virtual void run() { ThreadClient tc(name(), getGlobalServiceContext()); - LOG(1) << "starting " << name() << " thread"; + LOGV2_DEBUG(22305, 1, "starting {name} thread", "name"_attr = name()); // Initialize the thread's opCtx. _uniqueCtx.emplace(tc->makeOperationContext()); @@ -296,7 +297,7 @@ public: _flushJournalNow = false; if (_shuttingDown) { - LOG(1) << "stopping " << name() << " thread"; + LOGV2_DEBUG(22306, 1, "stopping {name} thread", "name"_attr = name()); _nextSharedPromise->setError( Status(ErrorCodes::ShutdownInProgress, "The storage catalog is being closed.")); stdx::lock_guard<Latch> lk(_opCtxMutex); @@ -447,7 +448,7 @@ public: virtual void run() { ThreadClient tc(name(), getGlobalServiceContext()); - LOG(1) << "starting " << name() << " thread"; + LOGV2_DEBUG(22307, 1, "starting {name} thread", "name"_attr = name()); while (!_shuttingDown.load()) { auto opCtx = tc->makeOperationContext(); @@ -540,16 +541,19 @@ public: const auto secondsElapsed = durationCount<Seconds>(Date_t::now() - startTime); if (secondsElapsed >= 30) { - LOG(1) << "Checkpoint took " << secondsElapsed << " seconds to complete."; + LOGV2_DEBUG(22308, + 1, + "Checkpoint took {secondsElapsed} seconds to complete.", + "secondsElapsed"_attr = secondsElapsed); } } catch (const WriteConflictException&) { // Temporary: remove this after WT-3483 - warning() << "Checkpoint encountered a write conflict exception."; + LOGV2_WARNING(22346, "Checkpoint encountered a write conflict exception."); } catch (const AssertionException& exc) { invariant(ErrorCodes::isShutdownError(exc.code()), exc.what()); } } - LOG(1) << "stopping " << name() << " thread"; + LOGV2_DEBUG(22309, 1, "stopping {name} thread", "name"_attr = name()); } /** @@ -575,8 +579,12 @@ public: invariant(!_hasTriggeredFirstStableCheckpoint); if (prevStable < initialData && currStable >= initialData) { _hasTriggeredFirstStableCheckpoint = true; - log() << "Triggering the first stable checkpoint. Initial Data: " << initialData - << " PrevStable: " << prevStable << " CurrStable: " << currStable; + LOGV2(22310, + "Triggering the first stable checkpoint. Initial Data: {initialData} PrevStable: " + "{prevStable} CurrStable: {currStable}", + "initialData"_attr = initialData, + "prevStable"_attr = prevStable, + "currStable"_attr = currStable); stdx::unique_lock<Latch> lock(_mutex); _condvar.notify_one(); } @@ -727,8 +735,14 @@ StatusWith<StorageEngine::BackupInformation> getBackupInformationFromBackupCurso while ((wtRet = dupCursor->next(dupCursor)) == 0) { uint64_t offset, size, type; invariantWTOK(dupCursor->get_key(dupCursor, &offset, &size, &type)); - LOG(2) << "Block to copy for incremental backup: filename: " << filePath.string() - << ", offset: " << offset << ", size: " << size << ", type: " << type; + LOGV2_DEBUG(22311, + 2, + "Block to copy for incremental backup: filename: {filePath_string}, " + "offset: {offset}, size: {size}, type: {type}", + "filePath_string"_attr = filePath.string(), + "offset"_attr = offset, + "size"_attr = size, + "type"_attr = type); backupInformation.at(filePath.string()).blocksToCopy.push_back({offset, size}); } @@ -779,7 +793,10 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, try { boost::filesystem::create_directory(journalPath); } catch (std::exception& e) { - log() << "error creating journal dir " << journalPath.string() << ' ' << e.what(); + LOGV2(22312, + "error creating journal dir {journalPath_string} {e_what}", + "journalPath_string"_attr = journalPath.string(), + "e_what"_attr = e.what()); throw; } } @@ -841,8 +858,9 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, // the normal path without the journal. if (boost::filesystem::exists(journalPath)) { string config = ss.str(); - log() << "Detected WT journal files. Running recovery from last checkpoint."; - log() << "journal to nojournal transition config: " << config; + LOGV2(22313, "Detected WT journal files. Running recovery from last checkpoint."); + LOGV2( + 22314, "journal to nojournal transition config: {config}", "config"_attr = config); int ret = wiredtiger_open( path.c_str(), _eventHandler.getWtEventHandler(), config.c_str(), &_conn); if (ret == EINVAL) { @@ -856,7 +874,10 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, try { boost::filesystem::remove_all(journalPath); } catch (std::exception& e) { - error() << "error removing journal dir " << journalPath.string() << ' ' << e.what(); + LOGV2_ERROR(22355, + "error removing journal dir {journalPath_string} {e_what}", + "journalPath_string"_attr = journalPath.string(), + "e_what"_attr = e.what()); throw; } } @@ -865,7 +886,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, } string config = ss.str(); - log() << "wiredtiger_open config: " << config; + LOGV2(22315, "wiredtiger_open config: {config}", "config"_attr = config); _openWiredTiger(path, config); _eventHandler.setStartupSuccessful(); _wtOpenConfig = config; @@ -907,7 +928,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, _sizeStorerUri = _uri("sizeStorer"); WiredTigerSession session(_conn); if (!_readOnly && repair && _hasUri(session.getSession(), _sizeStorerUri)) { - log() << "Repairing size cache"; + LOGV2(22316, "Repairing size cache"); auto status = _salvageIfNeeded(_sizeStorerUri.c_str()); if (status.code() != ErrorCodes::DataModifiedByRepair) @@ -998,28 +1019,30 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str return; } - warning() << "Failed to start up WiredTiger under any compatibility version."; + LOGV2_WARNING(22347, "Failed to start up WiredTiger under any compatibility version."); if (ret == EINVAL) { fassertFailedNoTrace(28561); } if (ret == WT_TRY_SALVAGE) { - warning() << "WiredTiger metadata corruption detected"; + LOGV2_WARNING(22348, "WiredTiger metadata corruption detected"); if (!_inRepairMode) { - severe() << kWTRepairMsg; + LOGV2_FATAL(22362, "{kWTRepairMsg}", "kWTRepairMsg"_attr = kWTRepairMsg); fassertFailedNoTrace(50944); } } - severe() << "Reason: " << wtRCToStatus(ret).reason(); + LOGV2_FATAL(22363, + "Reason: {wtRCToStatus_ret_reason}", + "wtRCToStatus_ret_reason"_attr = wtRCToStatus(ret).reason()); if (!_inRepairMode) { fassertFailedNoTrace(28595); } // Always attempt to salvage metadata regardless of error code when in repair mode. - warning() << "Attempting to salvage WiredTiger metadata"; + LOGV2_WARNING(22349, "Attempting to salvage WiredTiger metadata"); configStr = wtOpenConfig + ",salvage=true"; ret = wiredtiger_open(path.c_str(), wtEventHandler, configStr.c_str(), &_conn); if (!ret) { @@ -1028,12 +1051,15 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str return; } - severe() << "Failed to salvage WiredTiger metadata: " + wtRCToStatus(ret).reason(); + LOGV2_FATAL(22364, + "{Failed_to_salvage_WiredTiger_metadata_wtRCToStatus_ret_reason}", + "Failed_to_salvage_WiredTiger_metadata_wtRCToStatus_ret_reason"_attr = + "Failed to salvage WiredTiger metadata: " + wtRCToStatus(ret).reason()); fassertFailedNoTrace(50947); } void WiredTigerKVEngine::cleanShutdown() { - log() << "WiredTigerKVEngine shutting down"; + LOGV2(22317, "WiredTigerKVEngine shutting down"); if (!_readOnly) syncSizeInfo(true); if (!_conn) { @@ -1042,19 +1068,19 @@ void WiredTigerKVEngine::cleanShutdown() { // these must be the last things we do before _conn->close(); if (_sessionSweeper) { - log() << "Shutting down session sweeper thread"; + LOGV2(22318, "Shutting down session sweeper thread"); _sessionSweeper->shutdown(); - log() << "Finished shutting down session sweeper thread"; + LOGV2(22319, "Finished shutting down session sweeper thread"); } if (_journalFlusher) { - log() << "Shutting down journal flusher thread"; + LOGV2(22320, "Shutting down journal flusher thread"); _journalFlusher->shutdown(); - log() << "Finished shutting down journal flusher thread"; + LOGV2(22321, "Finished shutting down journal flusher thread"); } if (_checkpointThread) { - log() << "Shutting down checkpoint thread"; + LOGV2(22322, "Shutting down checkpoint thread"); _checkpointThread->shutdown(); - log() << "Finished shutting down checkpoint thread"; + LOGV2(22323, "Finished shutting down checkpoint thread"); } LOG_FOR_RECOVERY(2) << "Shutdown timestamps. StableTimestamp: " << _stableTimestamp.load() << " Initial data timestamp: " << _initialDataTimestamp.load(); @@ -1080,12 +1106,15 @@ void WiredTigerKVEngine::cleanShutdown() { } if (_fileVersion.shouldDowngrade(_readOnly, _inRepairMode, !_recoveryTimestamp.isNull())) { - log() << "Downgrading WiredTiger datafiles."; + LOGV2(22324, "Downgrading WiredTiger datafiles."); invariantWTOK(_conn->close(_conn, closeConfig.c_str())); invariantWTOK(wiredtiger_open( _path.c_str(), _eventHandler.getWtEventHandler(), _wtOpenConfig.c_str(), &_conn)); - LOG(1) << "Downgrade compatibility configuration: " << _fileVersion.getDowngradeString(); + LOGV2_DEBUG(22325, + 1, + "Downgrade compatibility configuration: {fileVersion_getDowngradeString}", + "fileVersion_getDowngradeString"_attr = _fileVersion.getDowngradeString()); invariantWTOK(_conn->reconfigure(_conn, _fileVersion.getDowngradeString().c_str())); } @@ -1098,9 +1127,11 @@ void WiredTigerKVEngine::cleanShutdown() { if (stableTimestamp >= initialDataTimestamp) { invariantWTOK(_conn->close(_conn, closeConfig.c_str())); } else { - log() << "Skipping checkpoint during clean shutdown because stableTimestamp (" - << stableTimestamp << ") is less than the initialDataTimestamp (" - << initialDataTimestamp << ")"; + LOGV2(22326, + "Skipping checkpoint during clean shutdown because stableTimestamp " + "({stableTimestamp}) is less than the initialDataTimestamp ({initialDataTimestamp})", + "stableTimestamp"_attr = stableTimestamp, + "initialDataTimestamp"_attr = initialDataTimestamp); quickExit(EXIT_SUCCESS); } _conn = nullptr; @@ -1140,7 +1171,7 @@ Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) { int rc = (session->verify)(session, uri, nullptr); if (rc == 0) { - log() << "Verify succeeded on uri " << uri << ". Not salvaging."; + LOGV2(22327, "Verify succeeded on uri {uri}. Not salvaging.", "uri"_attr = uri); return Status::OK(); } @@ -1148,28 +1179,34 @@ Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) { // SERVER-16457: verify and salvage are occasionally failing with EBUSY. For now we // lie and return OK to avoid breaking tests. This block should go away when that ticket // is resolved. - error() - << "Verify on " << uri << " failed with EBUSY. " - << "This means the collection was being accessed. No repair is necessary unless other " - "errors are reported."; + LOGV2_ERROR(22356, + "Verify on {uri} failed with EBUSY. This means the collection was being " + "accessed. No repair is necessary unless other " + "errors are reported.", + "uri"_attr = uri); return Status::OK(); } if (rc == ENOENT) { - warning() << "Data file is missing for " << uri - << ". Attempting to drop and re-create the collection."; + LOGV2_WARNING( + 22350, + "Data file is missing for {uri}. Attempting to drop and re-create the collection.", + "uri"_attr = uri); return _rebuildIdent(session, uri); } - log() << "Verify failed on uri " << uri << ". Running a salvage operation."; + LOGV2(22328, "Verify failed on uri {uri}. Running a salvage operation.", "uri"_attr = uri); auto status = wtRCToStatus(session->salvage(session, uri, nullptr), "Salvage failed:"); if (status.isOK()) { return {ErrorCodes::DataModifiedByRepair, str::stream() << "Salvaged data for " << uri}; } - warning() << "Salvage failed for uri " << uri << ": " << status.reason() - << ". The file will be moved out of the way and a new ident will be created."; + LOGV2_WARNING(22351, + "Salvage failed for uri {uri}: {status_reason}. The file will be moved out of " + "the way and a new ident will be created.", + "uri"_attr = uri, + "status_reason"_attr = status.reason()); // If the data is unsalvageable, we should completely rebuild the ident. return _rebuildIdent(session, uri); @@ -1184,8 +1221,10 @@ Status WiredTigerKVEngine::_rebuildIdent(WT_SESSION* session, const char* uri) { auto filePath = getDataFilePathForIdent(identName); if (filePath) { const boost::filesystem::path corruptFile(filePath->string() + ".corrupt"); - warning() << "Moving data file " << filePath->string() << " to backup as " - << corruptFile.string(); + LOGV2_WARNING(22352, + "Moving data file {filePath_string} to backup as {corruptFile_string}", + "filePath_string"_attr = filePath->string(), + "corruptFile_string"_attr = corruptFile.string()); auto status = fsyncRename(filePath.get(), corruptFile); if (!status.isOK()) { @@ -1193,34 +1232,37 @@ Status WiredTigerKVEngine::_rebuildIdent(WT_SESSION* session, const char* uri) { } } - warning() << "Rebuilding ident " << identName; + LOGV2_WARNING(22353, "Rebuilding ident {identName}", "identName"_attr = identName); // This is safe to call after moving the file because it only reads from the metadata, and not // the data file itself. auto swMetadata = WiredTigerUtil::getMetadataCreate(session, uri); if (!swMetadata.isOK()) { - error() << "Failed to get metadata for " << uri; + LOGV2_ERROR(22357, "Failed to get metadata for {uri}", "uri"_attr = uri); return swMetadata.getStatus(); } int rc = session->drop(session, uri, nullptr); if (rc != 0) { - error() << "Failed to drop " << uri; + LOGV2_ERROR(22358, "Failed to drop {uri}", "uri"_attr = uri); return wtRCToStatus(rc); } rc = session->create(session, uri, swMetadata.getValue().c_str()); if (rc != 0) { - error() << "Failed to create " << uri << " with config: " << swMetadata.getValue(); + LOGV2_ERROR(22359, + "Failed to create {uri} with config: {swMetadata_getValue}", + "uri"_attr = uri, + "swMetadata_getValue"_attr = swMetadata.getValue()); return wtRCToStatus(rc); } - log() << "Successfully re-created " << uri << "."; + LOGV2(22329, "Successfully re-created {uri}.", "uri"_attr = uri); return {ErrorCodes::DataModifiedByRepair, str::stream() << "Re-created empty data file for " << uri}; } void WiredTigerKVEngine::flushAllFiles(OperationContext* opCtx, bool callerHoldsReadLock) { - LOG(1) << "WiredTigerKVEngine::flushAllFiles"; + LOGV2_DEBUG(22330, 1, "WiredTigerKVEngine::flushAllFiles"); if (_ephemeral) { return; } @@ -1285,7 +1327,7 @@ Status WiredTigerKVEngine::disableIncrementalBackup(OperationContext* opCtx) { int wtRet = session->open_cursor(session, "backup:", nullptr, "incremental=(force_stop=true)", &cursor); if (wtRet != 0) { - error() << "Could not open a backup cursor to disable incremental backups"; + LOGV2_ERROR(22360, "Could not open a backup cursor to disable incremental backups"); return wtRCToStatus(wtRet); } @@ -1448,8 +1490,12 @@ Status WiredTigerKVEngine::createGroupedRecordStore(OperationContext* opCtx, string uri = _uri(ident); WT_SESSION* s = session.getSession(); - LOG(2) << "WiredTigerKVEngine::createRecordStore ns: " << ns << " uri: " << uri - << " config: " << config; + LOGV2_DEBUG(22331, + 2, + "WiredTigerKVEngine::createRecordStore ns: {ns} uri: {uri} config: {config}", + "ns"_attr = ns, + "uri"_attr = uri, + "config"_attr = config); return wtRCToStatus(s->create(s, uri.c_str(), config.c_str())); } @@ -1477,21 +1523,30 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx, boost::filesystem::path tmpFile{*identFilePath}; tmpFile += ".tmp"; - log() << "Renaming data file " + identFilePath->string() + " to temporary file " + - tmpFile.string(); + LOGV2(22332, + "{Renaming_data_file_identFilePath_string_to_temporary_file_tmpFile_string}", + "Renaming_data_file_identFilePath_string_to_temporary_file_tmpFile_string"_attr = + "Renaming data file " + identFilePath->string() + " to temporary file " + + tmpFile.string()); auto status = fsyncRename(identFilePath.get(), tmpFile); if (!status.isOK()) { return status; } - log() << "Creating new RecordStore for collection " << nss << " with UUID: " << options.uuid; + LOGV2(22333, + "Creating new RecordStore for collection {nss} with UUID: {options_uuid}", + "nss"_attr = nss, + "options_uuid"_attr = options.uuid); status = createGroupedRecordStore(opCtx, nss.ns(), ident, options, KVPrefix::kNotPrefixed); if (!status.isOK()) { return status; } - log() << "Moving orphaned data file back as " + identFilePath->string(); + LOGV2(22334, + "{Moving_orphaned_data_file_back_as_identFilePath_string}", + "Moving_orphaned_data_file_back_as_identFilePath_string"_attr = + "Moving orphaned data file back as " + identFilePath->string()); boost::filesystem::remove(*identFilePath, ec); if (ec) { @@ -1507,7 +1562,9 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx, return status; } - log() << "Salvaging ident " + ident; + LOGV2(22335, + "{Salvaging_ident_ident}", + "Salvaging_ident_ident"_attr = "Salvaging ident " + ident); WiredTigerSession sessionWrapper(_conn); WT_SESSION* session = sessionWrapper.getSession(); @@ -1517,7 +1574,9 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx, return {ErrorCodes::DataModifiedByRepair, str::stream() << "Salvaged data for ident " << ident}; } - warning() << "Could not salvage data. Rebuilding ident: " << status.reason(); + LOGV2_WARNING(22354, + "Could not salvage data. Rebuilding ident: {status_reason}", + "status_reason"_attr = status.reason()); // If the data is unsalvageable, we should completely rebuild the ident. return _rebuildIdent(session, _uri(ident).c_str()); @@ -1609,8 +1668,13 @@ Status WiredTigerKVEngine::createGroupedSortedDataInterface(OperationContext* op std::string config = result.getValue(); - LOG(2) << "WiredTigerKVEngine::createSortedDataInterface ns: " << collection->ns() - << " ident: " << ident << " config: " << config; + LOGV2_DEBUG(22336, + 2, + "WiredTigerKVEngine::createSortedDataInterface ns: {collection_ns} ident: {ident} " + "config: {config}", + "collection_ns"_attr = collection->ns(), + "ident"_attr = ident, + "config"_attr = config); return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config)); } @@ -1639,8 +1703,11 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(Operat std::string uri = _uri(ident); WT_SESSION* session = wtSession.getSession(); - LOG(2) << "WiredTigerKVEngine::createTemporaryRecordStore uri: " << uri - << " config: " << config; + LOGV2_DEBUG(22337, + 2, + "WiredTigerKVEngine::createTemporaryRecordStore uri: {uri} config: {config}", + "uri"_attr = uri, + "config"_attr = config); uassertStatusOK(wtRCToStatus(session->create(session, uri.c_str(), config.c_str()))); WiredTigerRecordStore::Params params; @@ -1677,7 +1744,7 @@ Status WiredTigerKVEngine::dropIdent(OperationContext* opCtx, RecoveryUnit* ru, int ret = session.getSession()->drop( session.getSession(), uri.c_str(), "force,checkpoint_wait=false"); - LOG(1) << "WT drop of " << uri << " res " << ret; + LOGV2_DEBUG(22338, 1, "WT drop of {uri} res {ret}", "uri"_attr = uri, "ret"_attr = ret); if (ret == 0) { // yay, it worked @@ -1759,7 +1826,11 @@ void WiredTigerKVEngine::dropSomeQueuedIdents() { if (tenPercentQueue > 10) numToDelete = tenPercentQueue; - LOG(1) << "WT Queue is: " << numInQueue << " attempting to drop: " << numToDelete << " tables"; + LOGV2_DEBUG(22339, + 1, + "WT Queue is: {numInQueue} attempting to drop: {numToDelete} tables", + "numInQueue"_attr = numInQueue, + "numToDelete"_attr = numToDelete); for (int i = 0; i < numToDelete; i++) { string uri; { @@ -1771,7 +1842,8 @@ void WiredTigerKVEngine::dropSomeQueuedIdents() { } int ret = session.getSession()->drop( session.getSession(), uri.c_str(), "force,checkpoint_wait=false"); - LOG(1) << "WT queued drop of " << uri << " res " << ret; + LOGV2_DEBUG( + 22340, 1, "WT queued drop of {uri} res {ret}", "uri"_attr = uri, "ret"_attr = ret); if (ret == EBUSY) { stdx::lock_guard<Latch> lk(_identToDropMutex); @@ -1865,11 +1937,14 @@ void WiredTigerKVEngine::_ensureIdentPath(StringData ident) { boost::filesystem::path subdir = _path; subdir /= dir.toString(); if (!boost::filesystem::exists(subdir)) { - LOG(1) << "creating subdirectory: " << dir; + LOGV2_DEBUG(22341, 1, "creating subdirectory: {dir}", "dir"_attr = dir); try { boost::filesystem::create_directory(subdir); } catch (const std::exception& e) { - error() << "error creating path " << subdir.string() << ' ' << e.what(); + LOGV2_ERROR(22361, + "error creating path {subdir_string} {e_what}", + "subdir_string"_attr = subdir.string(), + "e_what"_attr = e.what()); throw; } } @@ -1970,14 +2045,20 @@ void WiredTigerKVEngine::setOldestTimestamp(Timestamp newOldestTimestamp, bool f newOldestTimestamp.asULL()); invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString.c_str())); _oldestTimestamp.store(newOldestTimestamp.asULL()); - LOG(2) << "oldest_timestamp and commit_timestamp force set to " << newOldestTimestamp; + LOGV2_DEBUG(22342, + 2, + "oldest_timestamp and commit_timestamp force set to {newOldestTimestamp}", + "newOldestTimestamp"_attr = newOldestTimestamp); } else { auto oldestTSConfigString = "oldest_timestamp={:x}"_format(newOldestTimestamp.asULL()); invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString.c_str())); // set_timestamp above ignores backwards in time if 'force' is not set. if (_oldestTimestamp.load() < newOldestTimestamp.asULL()) _oldestTimestamp.store(newOldestTimestamp.asULL()); - LOG(2) << "oldest_timestamp set to " << newOldestTimestamp; + LOGV2_DEBUG(22343, + 2, + "oldest_timestamp set to {newOldestTimestamp}", + "newOldestTimestamp"_attr = newOldestTimestamp); } } @@ -2012,7 +2093,10 @@ Timestamp WiredTigerKVEngine::_calculateHistoryLagFromStableTimestamp(Timestamp } void WiredTigerKVEngine::setInitialDataTimestamp(Timestamp initialDataTimestamp) { - LOG(2) << "Setting initial data timestamp. Value: " << initialDataTimestamp; + LOGV2_DEBUG(22344, + 2, + "Setting initial data timestamp. Value: {initialDataTimestamp}", + "initialDataTimestamp"_attr = initialDataTimestamp); _initialDataTimestamp.store(initialDataTimestamp.asULL()); } @@ -2038,7 +2122,7 @@ bool WiredTigerKVEngine::_canRecoverToStableTimestamp() const { StatusWith<Timestamp> WiredTigerKVEngine::recoverToStableTimestamp(OperationContext* opCtx) { if (!supportsRecoverToStableTimestamp()) { - severe() << "WiredTiger is configured to not support recover to a stable timestamp"; + LOGV2_FATAL(22365, "WiredTiger is configured to not support recover to a stable timestamp"); fassertFailed(50665); } @@ -2111,7 +2195,8 @@ Timestamp WiredTigerKVEngine::getOldestOpenReadTimestamp() const { boost::optional<Timestamp> WiredTigerKVEngine::getRecoveryTimestamp() const { if (!supportsRecoveryTimestamp()) { - severe() << "WiredTiger is configured to not support providing a recovery timestamp"; + LOGV2_FATAL(22366, + "WiredTiger is configured to not support providing a recovery timestamp"); fassertFailed(50745); } @@ -2157,7 +2242,10 @@ StatusWith<Timestamp> WiredTigerKVEngine::getOplogNeededForRollback() const { if (status.isOK()) { oldestActiveTransactionTimestamp.swap(status.getValue()); } else { - LOG(1) << "getting oldest active transaction timestamp: " << status.getStatus(); + LOGV2_DEBUG(22345, + 1, + "getting oldest active transaction timestamp: {status_getStatus}", + "status_getStatus"_attr = status.getStatus()); return status.getStatus(); } } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp index 2f818dce98a..0879d6e8a1e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp @@ -27,6 +27,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/storage/kv/kv_engine_test_harness.h" @@ -45,9 +47,11 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/logger/logger.h" +#include "mongo/logv2/log.h" #include "mongo/unittest/temp_dir.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" +#include "mongo/util/log.h" #include "mongo/util/log_global_settings.h" namespace mongo { @@ -294,8 +298,12 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) { sleepmillis(100); } - unittest::log() << "Expected the pinned oplog to advance. Expected value: " << newPinned - << " Published value: " << _engine->getOplogNeededForCrashRecovery(); + LOGV2(22367, + "Expected the pinned oplog to advance. Expected value: {newPinned} Published value: " + "{engine_getOplogNeededForCrashRecovery}", + "newPinned"_attr = newPinned, + "engine_getOplogNeededForCrashRecovery"_attr = + _engine->getOplogNeededForCrashRecovery()); FAIL(""); }; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp index faae62bad5e..dd4369428fc 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp @@ -37,6 +37,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/log.h" @@ -66,7 +67,10 @@ void WiredTigerOplogManager::start(OperationContext* opCtx, // rollback before servicing oplog reads. auto oplogVisibility = Timestamp(lastRecord->id.repr()); setOplogReadTimestamp(oplogVisibility); - LOG(1) << "Setting oplog visibility at startup. Val: " << oplogVisibility; + LOGV2_DEBUG(22368, + 1, + "Setting oplog visibility at startup. Val: {oplogVisibility}", + "oplogVisibility"_attr = oplogVisibility); } else { // Avoid setting oplog visibility to 0. That means "everything is visible". setOplogReadTimestamp(Timestamp(kMinimumTimestamp)); @@ -112,7 +116,7 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible( oplogRecordStore->getCursor(opCtx, false /* false = reverse cursor */); auto lastRecord = cursor->next(); if (!lastRecord) { - LOG(2) << "Trying to query an empty oplog"; + LOGV2_DEBUG(22369, 2, "Trying to query an empty oplog"); opCtx->recoveryUnit()->abandonSnapshot(); return; } @@ -130,9 +134,15 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible( opCtx->waitForConditionOrInterrupt(_opsBecameVisibleCV, lk, [&] { auto newLatestVisibleTimestamp = getOplogReadTimestamp(); if (newLatestVisibleTimestamp < currentLatestVisibleTimestamp) { - LOG(1) << "Oplog latest visible timestamp went backwards. newLatestVisibleTimestamp: " - << Timestamp(newLatestVisibleTimestamp) << " currentLatestVisibleTimestamp: " - << Timestamp(currentLatestVisibleTimestamp); + LOGV2_DEBUG(22370, + 1, + "Oplog latest visible timestamp went backwards. newLatestVisibleTimestamp: " + "{Timestamp_newLatestVisibleTimestamp} currentLatestVisibleTimestamp: " + "{Timestamp_currentLatestVisibleTimestamp}", + "Timestamp_newLatestVisibleTimestamp"_attr = + Timestamp(newLatestVisibleTimestamp), + "Timestamp_currentLatestVisibleTimestamp"_attr = + Timestamp(currentLatestVisibleTimestamp)); // If the visibility went backwards, this means a rollback occurred. // Thus, we are finished waiting. return true; @@ -140,8 +150,13 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible( currentLatestVisibleTimestamp = newLatestVisibleTimestamp; RecordId latestVisible = RecordId(currentLatestVisibleTimestamp); if (latestVisible < waitingFor) { - LOG(2) << "Operation is waiting for " << Timestamp(waitingFor.repr()) - << "; latestVisible is " << Timestamp(currentLatestVisibleTimestamp); + LOGV2_DEBUG(22371, + 2, + "Operation is waiting for {Timestamp_waitingFor_repr}; latestVisible is " + "{Timestamp_currentLatestVisibleTimestamp}", + "Timestamp_waitingFor_repr"_attr = Timestamp(waitingFor.repr()), + "Timestamp_currentLatestVisibleTimestamp"_attr = + Timestamp(currentLatestVisibleTimestamp)); } return latestVisible >= waitingFor; }); @@ -212,7 +227,7 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses } if (_shuttingDown) { - log() << "Oplog journal thread loop shutting down"; + LOGV2(22372, "Oplog journal thread loop shutting down"); return; } invariant(_opsWaitingForJournal); @@ -225,7 +240,10 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses // where we commit data file changes separately from oplog changes, so ignore // a non-incrementing timestamp. if (newTimestamp <= _oplogReadTimestamp.load()) { - LOG(2) << "No new oplog entries were made visible: " << Timestamp(newTimestamp); + LOGV2_DEBUG(22373, + 2, + "No new oplog entries were made visible: {Timestamp_newTimestamp}", + "Timestamp_newTimestamp"_attr = Timestamp(newTimestamp)); continue; } @@ -260,7 +278,10 @@ void WiredTigerOplogManager::setOplogReadTimestamp(Timestamp ts) { void WiredTigerOplogManager::_setOplogReadTimestamp(WithLock, uint64_t newTimestamp) { _oplogReadTimestamp.store(newTimestamp); _opsBecameVisibleCV.notify_all(); - LOG(2) << "Setting new oplogReadTimestamp: " << Timestamp(newTimestamp); + LOGV2_DEBUG(22374, + 2, + "Setting new oplogReadTimestamp: {Timestamp_newTimestamp}", + "Timestamp_newTimestamp"_attr = Timestamp(newTimestamp)); } uint64_t WiredTigerOplogManager::fetchAllDurableValue(WT_CONNECTION* conn) { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp index d2a25c55a4f..44a90b320da 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp @@ -32,6 +32,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h" #include "mongo/logger/parse_log_component_settings.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -50,7 +51,9 @@ Status applyMaxCacheOverflowSizeGBParameter(WiredTigerMaxCacheOverflowSizeGBPara const auto valueMB = static_cast<size_t>(1024 * value); - log() << "Reconfiguring WiredTiger max cache overflow size with value: \"" << valueMB << "MB\'"; + LOGV2(22375, + "Reconfiguring WiredTiger max cache overflow size with value: \"{valueMB}MB\'", + "valueMB"_attr = valueMB); invariant(param._data.second); int ret = param._data.second->reconfigure( @@ -58,7 +61,7 @@ Status applyMaxCacheOverflowSizeGBParameter(WiredTigerMaxCacheOverflowSizeGBPara if (ret != 0) { string result = (str::stream() << "WiredTiger reconfiguration failed with error code (" << ret << "): " << wiredtiger_strerror(ret)); - error() << result; + LOGV2_ERROR(22377, "{result}", "result"_attr = result); return Status(ErrorCodes::BadValue, result); } @@ -85,14 +88,16 @@ Status WiredTigerEngineRuntimeConfigParameter::setFromString(const std::string& << pos)); } - log() << "Reconfiguring WiredTiger storage engine with config string: \"" << str << "\""; + LOGV2(22376, + "Reconfiguring WiredTiger storage engine with config string: \"{str}\"", + "str"_attr = str); invariant(_data.second); int ret = _data.second->reconfigure(str.c_str()); if (ret != 0) { string result = (str::stream() << "WiredTiger reconfiguration failed with error code (" << ret << "): " << wiredtiger_strerror(ret)); - error() << result; + LOGV2_ERROR(22378, "{result}", "result"_attr = result); return Status(ErrorCodes::BadValue, result); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp index c5533e62edd..ddd979a5510 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp @@ -33,6 +33,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -46,12 +47,15 @@ MONGO_FAIL_POINT_DEFINE(WTSkipPrepareConflictRetries); MONGO_FAIL_POINT_DEFINE(WTPrintPrepareConflictLog); void wiredTigerPrepareConflictLog(int attempts) { - LOG(1) << "Caught WT_PREPARE_CONFLICT, attempt " << attempts - << ". Waiting for unit of work to commit or abort."; + LOGV2_DEBUG(22379, + 1, + "Caught WT_PREPARE_CONFLICT, attempt {attempts}. Waiting for unit of work to " + "commit or abort.", + "attempts"_attr = attempts); } void wiredTigerPrepareConflictFailPointLog() { - log() << "WTPrintPrepareConflictLog fail point enabled."; + LOGV2(22380, "WTPrintPrepareConflictLog fail point enabled."); } } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index a409680879a..235cb8f057e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -61,6 +61,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/fail_point.h" @@ -261,7 +262,10 @@ void WiredTigerRecordStore::OplogStones::createNewStoneIfNeeded(RecordId lastRec return; } - LOG(2) << "create new oplogStone, current stones:" << _stones.size(); + LOGV2_DEBUG(22381, + 2, + "create new oplogStone, current stones:{stones_size}", + "stones_size"_attr = _stones.size()); OplogStones::Stone stone = {_currentRecords.swap(0), _currentBytes.swap(0), lastRecord}; _stones.push_back(stone); @@ -325,14 +329,19 @@ void WiredTigerRecordStore::OplogStones::_calculateStones(OperationContext* opCt const std::uint64_t startWaitTime = curTimeMicros64(); ON_BLOCK_EXIT([&] { auto waitTime = curTimeMicros64() - startWaitTime; - log() << "WiredTiger record store oplog processing took " << waitTime / 1000 << "ms"; + LOGV2(22382, + "WiredTiger record store oplog processing took {waitTime_1000}ms", + "waitTime_1000"_attr = waitTime / 1000); _totalTimeProcessing.fetchAndAdd(waitTime); }); long long numRecords = _rs->numRecords(opCtx); long long dataSize = _rs->dataSize(opCtx); - log() << "The size storer reports that the oplog contains " << numRecords - << " records totaling to " << dataSize << " bytes"; + LOGV2(22383, + "The size storer reports that the oplog contains {numRecords} records totaling to " + "{dataSize} bytes", + "numRecords"_attr = numRecords, + "dataSize"_attr = dataSize); // Don't calculate stones if this is a new collection. This is to prevent standalones from // attempting to get a forward scanning oplog cursor on an explicit create of the oplog @@ -366,7 +375,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStones(OperationContext* opCt void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationContext* opCtx) { _processBySampling.store(false); // process by scanning - log() << "Scanning the oplog to determine where to place markers for truncation"; + LOGV2(22384, "Scanning the oplog to determine where to place markers for truncation"); long long numRecords = 0; long long dataSize = 0; @@ -376,8 +385,11 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationCon _currentRecords.addAndFetch(1); int64_t newCurrentBytes = _currentBytes.addAndFetch(record->data.size()); if (newCurrentBytes >= _minBytesPerStone) { - LOG(1) << "Placing a marker at optime " - << Timestamp(record->id.repr()).toStringPretty(); + LOGV2_DEBUG(22385, + 1, + "Placing a marker at optime {Timestamp_record_id_repr_Pretty}", + "Timestamp_record_id_repr_Pretty"_attr = + Timestamp(record->id.repr()).toStringPretty()); OplogStones::Stone stone = {_currentRecords.swap(0), _currentBytes.swap(0), record->id}; _stones.push_back(stone); @@ -393,7 +405,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationCon void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationContext* opCtx, int64_t estRecordsPerStone, int64_t estBytesPerStone) { - log() << "Sampling the oplog to determine where to place markers for truncation"; + LOGV2(22386, "Sampling the oplog to determine where to place markers for truncation"); _processBySampling.store(true); // process by sampling Timestamp earliestOpTime; Timestamp latestOpTime; @@ -405,7 +417,8 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon if (!record) { // This shouldn't really happen unless the size storer values are far off from reality. // The collection is probably empty, but fall back to scanning the oplog just in case. - log() << "Failed to determine the earliest optime, falling back to scanning the oplog"; + LOGV2(22387, + "Failed to determine the earliest optime, falling back to scanning the oplog"); _calculateStonesByScanning(opCtx); return; } @@ -419,22 +432,29 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon if (!record) { // This shouldn't really happen unless the size storer values are far off from reality. // The collection is probably empty, but fall back to scanning the oplog just in case. - log() << "Failed to determine the latest optime, falling back to scanning the oplog"; + LOGV2(22388, + "Failed to determine the latest optime, falling back to scanning the oplog"); _calculateStonesByScanning(opCtx); return; } latestOpTime = Timestamp(record->id.repr()); } - log() << "Sampling from the oplog between " << earliestOpTime.toStringPretty() << " and " - << latestOpTime.toStringPretty() << " to determine where to place markers for truncation"; + LOGV2(22389, + "Sampling from the oplog between {earliestOpTime_Pretty} and {latestOpTime_Pretty} to " + "determine where to place markers for truncation", + "earliestOpTime_Pretty"_attr = earliestOpTime.toStringPretty(), + "latestOpTime_Pretty"_attr = latestOpTime.toStringPretty()); int64_t wholeStones = _rs->numRecords(opCtx) / estRecordsPerStone; int64_t numSamples = kRandomSamplesPerStone * _rs->numRecords(opCtx) / estRecordsPerStone; - log() << "Taking " << numSamples << " samples and assuming that each section of oplog contains" - << " approximately " << estRecordsPerStone << " records totaling to " << estBytesPerStone - << " bytes"; + LOGV2(22390, + "Taking {numSamples} samples and assuming that each section of oplog contains " + "approximately {estRecordsPerStone} records totaling to {estBytesPerStone} bytes", + "numSamples"_attr = numSamples, + "estRecordsPerStone"_attr = estRecordsPerStone, + "estBytesPerStone"_attr = estBytesPerStone); // Inform the random cursor of the number of samples we intend to take. This allows it to // account for skew in the tree shape. @@ -455,7 +475,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon if (!record) { // This shouldn't really happen unless the size storer values are far off from reality. // The collection is probably empty, but fall back to scanning the oplog just in case. - log() << "Failed to get enough random samples, falling back to scanning the oplog"; + LOGV2(22391, "Failed to get enough random samples, falling back to scanning the oplog"); _calculateStonesByScanning(opCtx); return; } @@ -464,13 +484,15 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon const auto now = Date_t::now(); if (samplingLogIntervalSeconds > 0 && now - lastProgressLog >= Seconds(samplingLogIntervalSeconds)) { - log() << "Oplog sampling progress: " << (i + 1) << " of " << numSamples - << " samples taken"; + LOGV2(22392, + "Oplog sampling progress: {i_1} of {numSamples} samples taken", + "i_1"_attr = (i + 1), + "numSamples"_attr = numSamples); lastProgressLog = now; } } std::sort(oplogEstimates.begin(), oplogEstimates.end()); - log() << "Oplog sampling complete"; + LOGV2(22393, "Oplog sampling complete"); for (int i = 1; i <= wholeStones; ++i) { // Use every (kRandomSamplesPerStone)th sample, starting with the @@ -478,7 +500,10 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon int sampleIndex = kRandomSamplesPerStone * i - 1; RecordId lastRecord = oplogEstimates[sampleIndex]; - log() << "Placing a marker at optime " << Timestamp(lastRecord.repr()).toStringPretty(); + LOGV2(22394, + "Placing a marker at optime {Timestamp_lastRecord_repr_Pretty}", + "Timestamp_lastRecord_repr_Pretty"_attr = + Timestamp(lastRecord.repr()).toStringPretty()); OplogStones::Stone stone = {estRecordsPerStone, estBytesPerStone, lastRecord}; _stones.push_back(stone); } @@ -755,9 +780,12 @@ WiredTigerRecordStore::~WiredTigerRecordStore() { } if (!isTemp()) { - LOG(1) << "~WiredTigerRecordStore for: " << ns(); + LOGV2_DEBUG(22395, 1, "~WiredTigerRecordStore for: {ns}", "ns"_attr = ns()); } else { - LOG(1) << "~WiredTigerRecordStore for temporary ident: " << getIdent(); + LOGV2_DEBUG(22396, + 1, + "~WiredTigerRecordStore for temporary ident: {getIdent}", + "getIdent"_attr = getIdent()); } if (_oplogStones) { @@ -1174,7 +1202,7 @@ int64_t WiredTigerRecordStore::_cappedDeleteAsNeeded_inlock(OperationContext* op if (ret == ENOENT || ret == WT_NOTFOUND) { // TODO we should remove this case once SERVER-17141 is resolved - log() << "Soft failure truncating capped collection. Will try again later."; + LOGV2(22397, "Soft failure truncating capped collection. Will try again later."); docsRemoved = 0; } else { invariantWTOK(ret); @@ -1188,7 +1216,7 @@ int64_t WiredTigerRecordStore::_cappedDeleteAsNeeded_inlock(OperationContext* op } catch (const WriteConflictException&) { opCtx->releaseRecoveryUnit(); opCtx->setRecoveryUnit(std::unique_ptr<RecoveryUnit>(realRecoveryUnit), realRUstate); - log() << "got conflict truncating capped, ignoring"; + LOGV2(22398, "got conflict truncating capped, ignoring"); return 0; } catch (...) { opCtx->releaseRecoveryUnit(); @@ -1243,9 +1271,15 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT return; } - LOG(1) << "Truncating the oplog between " << _oplogStones->firstRecord << " and " - << stone->lastRecord << " to remove approximately " << stone->records - << " records totaling to " << stone->bytes << " bytes"; + LOGV2_DEBUG( + 22399, + 1, + "Truncating the oplog between {oplogStones_firstRecord} and {stone_lastRecord} to " + "remove approximately {stone_records} records totaling to {stone_bytes} bytes", + "oplogStones_firstRecord"_attr = _oplogStones->firstRecord, + "stone_lastRecord"_attr = stone->lastRecord, + "stone_records"_attr = stone->records, + "stone_bytes"_attr = stone->bytes); WiredTigerRecoveryUnit* ru = WiredTigerRecoveryUnit::get(opCtx); WT_SESSION* session = ru->getSession()->getSession(); @@ -1261,8 +1295,12 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT invariantWTOK(ret); RecordId firstRecord = getKey(cursor); if (firstRecord < _oplogStones->firstRecord || firstRecord > stone->lastRecord) { - warning() << "First oplog record " << firstRecord << " is not in truncation range (" - << _oplogStones->firstRecord << ", " << stone->lastRecord << ")"; + LOGV2_WARNING(22407, + "First oplog record {firstRecord} is not in truncation range " + "({oplogStones_firstRecord}, {stone_lastRecord})", + "firstRecord"_attr = firstRecord, + "oplogStones_firstRecord"_attr = _oplogStones->firstRecord, + "stone_lastRecord"_attr = stone->lastRecord); } setKey(cursor, stone->lastRecord); @@ -1279,18 +1317,24 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT _oplogStones->firstRecord = stone->lastRecord; _cappedFirstRecord = stone->lastRecord; } catch (const WriteConflictException&) { - LOG(1) << "Caught WriteConflictException while truncating oplog entries, retrying"; + LOGV2_DEBUG( + 22400, 1, "Caught WriteConflictException while truncating oplog entries, retrying"); } } - LOG(1) << "Finished truncating the oplog, it now contains approximately " - << _sizeInfo->numRecords.load() << " records totaling to " << _sizeInfo->dataSize.load() - << " bytes"; + LOGV2_DEBUG(22401, + 1, + "Finished truncating the oplog, it now contains approximately " + "{sizeInfo_numRecords_load} records totaling to {sizeInfo_dataSize_load} bytes", + "sizeInfo_numRecords_load"_attr = _sizeInfo->numRecords.load(), + "sizeInfo_dataSize_load"_attr = _sizeInfo->dataSize.load()); auto elapsedMicros = timer.micros(); auto elapsedMillis = elapsedMicros / 1000; _totalTimeTruncating.fetchAndAdd(elapsedMicros); _truncateCount.fetchAndAdd(1); - log() << "WiredTiger record store oplog truncation finished in: " << elapsedMillis << "ms"; + LOGV2(22402, + "WiredTiger record store oplog truncation finished in: {elapsedMillis}ms", + "elapsedMillis"_attr = elapsedMillis); } Status WiredTigerRecordStore::insertRecords(OperationContext* opCtx, @@ -1353,7 +1397,7 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx, ts = timestamps[i]; } if (!ts.isNull()) { - LOG(4) << "inserting record with timestamp " << ts; + LOGV2_DEBUG(22403, 4, "inserting record with timestamp {ts}", "ts"_attr = ts); fassert(39001, opCtx->recoveryUnit()->setTimestamp(ts)); } setKey(c, record.id); @@ -1617,7 +1661,7 @@ void WiredTigerRecordStore::validate(OperationContext* opCtx, << "This is a transient issue as the collection was actively " "in use by other operations."; - warning() << msg; + LOGV2_WARNING(22408, "{msg}", "msg"_attr = msg); results->warnings.push_back(msg); return; } @@ -1625,7 +1669,7 @@ void WiredTigerRecordStore::validate(OperationContext* opCtx, std::string msg = str::stream() << "verify() returned " << wiredtiger_strerror(err) << ". " << "This indicates structural damage. " << "Not examining individual documents."; - error() << msg; + LOGV2_ERROR(22409, "{msg}", "msg"_attr = msg); results->errors.push_back(msg); results->valid = false; } @@ -1778,7 +1822,10 @@ public: NumRecordsChange(WiredTigerRecordStore* rs, int64_t diff) : _rs(rs), _diff(diff) {} virtual void commit(boost::optional<Timestamp>) {} virtual void rollback() { - LOG(3) << "WiredTigerRecordStore: rolling back NumRecordsChange " << -_diff; + LOGV2_DEBUG(22404, + 3, + "WiredTigerRecordStore: rolling back NumRecordsChange {diff}", + "diff"_attr = -_diff); _rs->_sizeInfo->numRecords.fetchAndAdd(-_diff); } @@ -1912,7 +1959,7 @@ void WiredTigerRecordStore::cappedTruncateAfter(OperationContext* opCtx, } _kvEngine->getOplogManager()->setOplogReadTimestamp(truncTs); - LOG(1) << "truncation new read timestamp: " << truncTs; + LOGV2_DEBUG(22405, 1, "truncation new read timestamp: {truncTs}", "truncTs"_attr = truncTs); } if (_oplogStones) { @@ -1992,9 +2039,11 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::next() { } if (_forward && _lastReturnedId >= id) { - log() << "WTCursor::next -- c->next_key ( " << id - << ") was not greater than _lastReturnedId (" << _lastReturnedId - << ") which is a bug."; + LOGV2(22406, + "WTCursor::next -- c->next_key ( {id}) was not greater than _lastReturnedId " + "({lastReturnedId}) which is a bug.", + "id"_attr = id, + "lastReturnedId"_attr = _lastReturnedId); // Crash when test commands are enabled. invariant(!getTestCommandsEnabled()); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp index 8d1fe8821ff..604297cdf48 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp @@ -40,6 +40,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/hex.h" #include "mongo/util/log.h" @@ -221,7 +222,10 @@ void WiredTigerRecoveryUnit::prepareUnitOfWork() { auto session = getSession(); WT_SESSION* s = session->getSession(); - LOG(1) << "preparing transaction at time: " << _prepareTimestamp; + LOGV2_DEBUG(22410, + 1, + "preparing transaction at time: {prepareTimestamp}", + "prepareTimestamp"_attr = _prepareTimestamp); const std::string conf = "prepare_timestamp=" + integerToHex(_prepareTimestamp.asULL()); // Prepare the transaction. @@ -280,7 +284,9 @@ void WiredTigerRecoveryUnit::assertInActiveTxn() const { if (_isActive()) { return; } - severe() << "Recovery unit is not active. Current state: " << toString(_getState()); + LOGV2_FATAL(22417, + "Recovery unit is not active. Current state: {getState}", + "getState"_attr = toString(_getState())); fassertFailed(28575); } @@ -333,9 +339,12 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) { // `serverGlobalParams.slowMs` can be set to values <= 0. In those cases, give logging a // break. if (transactionTime >= std::max(1, serverGlobalParams.slowMS)) { - LOG(kSlowTransactionSeverity) - << "Slow WT transaction. Lifetime of SnapshotId " << getSnapshotId().toNumber() - << " was " << transactionTime << "ms"; + LOGV2_DEBUG(22411, + logSeverityV1toV2(kSlowTransactionSeverity).toInt(), + "Slow WT transaction. Lifetime of SnapshotId {getSnapshotId_toNumber} was " + "{transactionTime}ms", + "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber(), + "transactionTime"_attr = transactionTime); } } @@ -360,11 +369,17 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) { } wtRet = s->commit_transaction(s, conf.str().c_str()); - LOG(3) << "WT commit_transaction for snapshot id " << getSnapshotId().toNumber(); + LOGV2_DEBUG(22412, + 3, + "WT commit_transaction for snapshot id {getSnapshotId_toNumber}", + "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber()); } else { wtRet = s->rollback_transaction(s, nullptr); invariant(!wtRet); - LOG(3) << "WT rollback_transaction for snapshot id " << getSnapshotId().toNumber(); + LOGV2_DEBUG(22413, + 3, + "WT rollback_transaction for snapshot id {getSnapshotId_toNumber}", + "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber()); } if (_isTimestamped) { @@ -543,7 +558,10 @@ void WiredTigerRecoveryUnit::_txnOpen() { } } - LOG(3) << "WT begin_transaction for snapshot id " << getSnapshotId().toNumber(); + LOGV2_DEBUG(22414, + 3, + "WT begin_transaction for snapshot id {getSnapshotId_toNumber}", + "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber()); } Timestamp WiredTigerRecoveryUnit::_beginTransactionAtAllDurableTimestamp(WT_SESSION* session) { @@ -619,7 +637,10 @@ Timestamp WiredTigerRecoveryUnit::_getTransactionReadTimestamp(WT_SESSION* sessi Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) { _ensureSession(); - LOG(3) << "WT set timestamp of future write operations to " << timestamp; + LOGV2_DEBUG(22415, + 3, + "WT set timestamp of future write operations to {timestamp}", + "timestamp"_attr = timestamp); WT_SESSION* session = _session->getSession(); invariant(_inUnitOfWork(), toString(_getState())); invariant(_prepareTimestamp.isNull()); @@ -746,8 +767,12 @@ void WiredTigerRecoveryUnit::setRoundUpPreparedTimestamps(bool value) { void WiredTigerRecoveryUnit::setTimestampReadSource(ReadSource readSource, boost::optional<Timestamp> provided) { - LOG(3) << "setting timestamp read source: " << static_cast<int>(readSource) - << ", provided timestamp: " << ((provided) ? provided->toString() : "none"); + LOGV2_DEBUG(22416, + 3, + "setting timestamp read source: {static_cast_int_readSource}, provided timestamp: " + "{provided_provided_none}", + "static_cast_int_readSource"_attr = static_cast<int>(readSource), + "provided_provided_none"_attr = ((provided) ? provided->toString() : "none")); invariant(!_isActive() || _timestampReadSource == readSource, str::stream() << "Current state: " << toString(_getState()) diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp index d02e5aeb59f..208b426853c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp @@ -43,6 +43,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/thread.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -104,8 +105,10 @@ void _openCursor(WT_SESSION* session, uasserted(ErrorCodes::CursorNotFound, cursorErrMsg); } - error() << cursorErrMsg; - error() << "This may be due to data corruption. " << kWTRepairMsg; + LOGV2_ERROR(22421, "{cursorErrMsg}", "cursorErrMsg"_attr = cursorErrMsg); + LOGV2_ERROR(22422, + "This may be due to data corruption. {kWTRepairMsg}", + "kWTRepairMsg"_attr = kWTRepairMsg); fassertFailedNoTrace(50882); } @@ -294,7 +297,7 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, _journalListener->onDurable(token.get()); } } - LOG(4) << "created checkpoint (forced)"; + LOGV2_DEBUG(22418, 4, "created checkpoint (forced)"); return; } @@ -330,12 +333,12 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, // Use the journal when available, or a checkpoint otherwise. if (_engine && _engine->isDurable()) { invariantWTOK(_waitUntilDurableSession->log_flush(_waitUntilDurableSession, "sync=on")); - LOG(4) << "flushed journal"; + LOGV2_DEBUG(22419, 4, "flushed journal"); } else { auto checkpointLock = _engine->getCheckpointLock(opCtx); _engine->clearIndividuallyCheckpointedIndexesList(); invariantWTOK(_waitUntilDurableSession->checkpoint(_waitUntilDurableSession, nullptr)); - LOG(4) << "created checkpoint"; + LOGV2_DEBUG(22420, 4, "created checkpoint"); } if (token) { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp index e0847eb0444..64a79fbc05c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp @@ -42,6 +42,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -82,9 +83,15 @@ void WiredTigerSizeStorer::store(StringData uri, std::shared_ptr<SizeInfo> sizeI entry->_dirty.store(false); entry = sizeInfo; entry->_dirty.store(true); - LOG(2) << "WiredTigerSizeStorer::store Marking " << uri - << " dirty, numRecords: " << sizeInfo->numRecords.load() - << ", dataSize: " << sizeInfo->dataSize.load() << ", use_count: " << entry.use_count(); + LOGV2_DEBUG( + 22423, + 2, + "WiredTigerSizeStorer::store Marking {uri} dirty, numRecords: {sizeInfo_numRecords_load}, " + "dataSize: {sizeInfo_dataSize_load}, use_count: {entry_use_count}", + "uri"_attr = uri, + "sizeInfo_numRecords_load"_attr = sizeInfo->numRecords.load(), + "sizeInfo_dataSize_load"_attr = sizeInfo->dataSize.load(), + "entry_use_count"_attr = entry.use_count()); } std::shared_ptr<WiredTigerSizeStorer::SizeInfo> WiredTigerSizeStorer::load(StringData uri) const { @@ -115,7 +122,11 @@ std::shared_ptr<WiredTigerSizeStorer::SizeInfo> WiredTigerSizeStorer::load(Strin invariantWTOK(_cursor->get_value(_cursor, &value)); BSONObj data(reinterpret_cast<const char*>(value.data)); - LOG(2) << "WiredTigerSizeStorer::load " << uri << " -> " << redact(data); + LOGV2_DEBUG(22424, + 2, + "WiredTigerSizeStorer::load {uri} -> {data}", + "uri"_attr = uri, + "data"_attr = redact(data)); return std::make_shared<SizeInfo>(data["numRecords"].safeNumberLong(), data["dataSize"].safeNumberLong()); } @@ -157,7 +168,11 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) { << sizeInfo.dataSize.load()); auto& uri = it->first; - LOG(2) << "WiredTigerSizeStorer::flush " << uri << " -> " << redact(data); + LOGV2_DEBUG(22425, + 2, + "WiredTigerSizeStorer::flush {uri} -> {data}", + "uri"_attr = uri, + "data"_attr = redact(data)); WiredTigerItem key(uri.c_str(), uri.size()); WiredTigerItem value(data.objdata(), data.objsize()); _cursor->set_key(_cursor, key.Get()); @@ -170,6 +185,6 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) { } auto micros = t.micros(); - LOG(2) << "WiredTigerSizeStorer flush took " << micros << " µs"; + LOGV2_DEBUG(22426, 2, "WiredTigerSizeStorer flush took {micros} µs", "micros"_attr = micros); } } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp index dd7c6ce52b5..d7598300171 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp @@ -37,6 +37,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h" #include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/log.h" namespace mongo { @@ -101,7 +102,10 @@ Timestamp WiredTigerSnapshotManager::beginTransactionOnLocalSnapshot( stdx::lock_guard<Latch> lock(_localSnapshotMutex); invariant(_localSnapshot); - LOG(3) << "begin_transaction on local snapshot " << _localSnapshot.get().toString(); + LOGV2_DEBUG(22427, + 3, + "begin_transaction on local snapshot {localSnapshot_get}", + "localSnapshot_get"_attr = _localSnapshot.get().toString()); auto status = txnOpen.setReadSnapshot(_localSnapshot.get()); fassert(50775, status); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index cdb40992c26..8b72cbf94a0 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -42,6 +42,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" @@ -144,7 +145,7 @@ StatusWith<std::string> WiredTigerUtil::getMetadataCreate(OperationContext* opCt cursor = session->getCachedCursor( "metadata:create", WiredTigerSession::kMetadataCreateTableId, NULL); } catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) { - error() << ex; + LOGV2_ERROR(22433, "{ex}", "ex"_attr = ex); fassertFailedNoTrace(51257); } invariant(cursor); @@ -171,7 +172,7 @@ StatusWith<std::string> WiredTigerUtil::getMetadata(OperationContext* opCtx, Str try { cursor = session->getCachedCursor("metadata:", WiredTigerSession::kMetadataTableId, NULL); } catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) { - error() << ex; + LOGV2_ERROR(22434, "{ex}", "ex"_attr = ex); fassertFailedNoTrace(31293); } invariant(cursor); @@ -291,9 +292,14 @@ StatusWith<int64_t> WiredTigerUtil::checkApplicationMetadataFormatVersion(Operat << " has unsupported format version: " << version << "."); } - LOG(2) << "WiredTigerUtil::checkApplicationMetadataFormatVersion " - << " uri: " << uri << " ok range " << minimumVersion << " -> " << maximumVersion - << " current: " << version; + LOGV2_DEBUG(22428, + 2, + "WiredTigerUtil::checkApplicationMetadataFormatVersion uri: {uri} ok range " + "{minimumVersion} -> {maximumVersion} current: {version}", + "uri"_attr = uri, + "minimumVersion"_attr = minimumVersion, + "maximumVersion"_attr = maximumVersion, + "version"_attr = version); return version; } @@ -394,8 +400,10 @@ size_t WiredTigerUtil::getCacheSizeMB(double requestedCacheSizeGB) { cacheSizeMB = 1024 * requestedCacheSizeGB; } if (cacheSizeMB > kMaxSizeCacheMB) { - log() << "Requested cache size: " << cacheSizeMB << "MB exceeds max; setting to " - << kMaxSizeCacheMB << "MB"; + LOGV2(22429, + "Requested cache size: {cacheSizeMB}MB exceeds max; setting to {kMaxSizeCacheMB}MB", + "cacheSizeMB"_attr = cacheSizeMB, + "kMaxSizeCacheMB"_attr = kMaxSizeCacheMB); cacheSizeMB = kMaxSizeCacheMB; } return static_cast<size_t>(cacheSizeMB); @@ -418,8 +426,11 @@ int mdb_handle_error_with_startup_suppression(WT_EVENT_HANDLER* handler, return 0; } } - error() << "WiredTiger error (" << errorCode << ") " << redact(message) - << " Raw: " << message; + LOGV2_ERROR(22435, + "WiredTiger error ({errorCode}) {message} Raw: {message2}", + "errorCode"_attr = errorCode, + "message"_attr = redact(message), + "message2"_attr = message); // Don't abort on WT_PANIC when repairing, as the error will be handled at a higher layer. if (storageGlobalParams.repair) { @@ -437,7 +448,10 @@ int mdb_handle_error(WT_EVENT_HANDLER* handler, int errorCode, const char* message) { try { - error() << "WiredTiger error (" << errorCode << ") " << redact(message); + LOGV2_ERROR(22436, + "WiredTiger error ({errorCode}) {message}", + "errorCode"_attr = errorCode, + "message"_attr = redact(message)); // Don't abort on WT_PANIC when repairing, as the error will be handled at a higher layer. if (storageGlobalParams.repair) { @@ -452,7 +466,7 @@ int mdb_handle_error(WT_EVENT_HANDLER* handler, int mdb_handle_message(WT_EVENT_HANDLER* handler, WT_SESSION* session, const char* message) { try { - log() << "WiredTiger message " << redact(message); + LOGV2(22430, "WiredTiger message {message}", "message"_attr = redact(message)); } catch (...) { std::terminate(); } @@ -464,7 +478,10 @@ int mdb_handle_progress(WT_EVENT_HANDLER* handler, const char* operation, uint64_t progress) { try { - log() << "WiredTiger progress " << redact(operation) << " " << progress; + LOGV2(22431, + "WiredTiger progress {operation} {progress}", + "operation"_attr = redact(operation), + "progress"_attr = progress); } catch (...) { std::terminate(); } @@ -603,12 +620,21 @@ Status WiredTigerUtil::setTableLogging(WT_SESSION* session, const std::string& u return Status::OK(); } - LOG(1) << "Changing table logging settings. Uri: " << uri << " Enable? " << on; + LOGV2_DEBUG(22432, + 1, + "Changing table logging settings. Uri: {uri} Enable? {on}", + "uri"_attr = uri, + "on"_attr = on); int ret = session->alter(session, uri.c_str(), setting.c_str()); if (ret) { - severe() << "Failed to update log setting. Uri: " << uri << " Enable? " << on - << " Ret: " << ret << " MD: " << redact(existingMetadata) - << " Msg: " << session->strerror(session, ret); + LOGV2_FATAL(22437, + "Failed to update log setting. Uri: {uri} Enable? {on} Ret: {ret} MD: " + "{existingMetadata} Msg: {session_strerror_session_ret}", + "uri"_attr = uri, + "on"_attr = on, + "ret"_attr = ret, + "existingMetadata"_attr = redact(existingMetadata), + "session_strerror_session_ret"_attr = session->strerror(session, ret)); fassertFailed(50756); } diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp index dfafa0e46a1..45fa2c2c457 100644 --- a/src/mongo/db/system_index.cpp +++ b/src/mongo/db/system_index.cpp @@ -46,6 +46,7 @@ #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/jsobj.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -106,15 +107,21 @@ void generateSystemIndexForExistingCollection(OperationContext* opCtx, opCtx, spec.toBSON(), serverGlobalParams.featureCompatibility); BSONObj indexSpec = fassert(40452, indexSpecStatus); - log() << "No authorization index detected on " << ns - << " collection. Attempting to recover by creating an index with spec: " << indexSpec; + LOGV2(22488, + "No authorization index detected on {ns} collection. Attempting to recover by " + "creating an index with spec: {indexSpec}", + "ns"_attr = ns, + "indexSpec"_attr = indexSpec); auto indexConstraints = IndexBuildsManager::IndexConstraints::kEnforce; auto fromMigrate = false; IndexBuildsCoordinator::get(opCtx)->createIndexes( opCtx, collectionUUID, {indexSpec}, indexConstraints, fromMigrate); } catch (const DBException& e) { - severe() << "Failed to regenerate index for " << ns << ". Exception: " << e.what(); + LOGV2_FATAL(22490, + "Failed to regenerate index for {ns}. Exception: {e_what}", + "ns"_attr = ns, + "e_what"_attr = e.what()); throw; } } @@ -124,7 +131,8 @@ void generateSystemIndexForExistingCollection(OperationContext* opCtx, Status verifySystemIndexes(OperationContext* opCtx) { // Do not try and generate any system indexes in read only mode. if (storageGlobalParams.readOnly) { - warning() << "Running in queryable backup mode. Unable to create authorization indexes"; + LOGV2_WARNING(22489, + "Running in queryable backup mode. Unable to create authorization indexes"); return Status::OK(); } diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index 3c9dfa78395..3cea8461baa 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -63,6 +63,7 @@ #include "mongo/db/stats/fill_locker_info.h" #include "mongo/db/transaction_history_iterator.h" #include "mongo/db/transaction_participant_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" #include "mongo/util/log_with_sampling.h" @@ -97,11 +98,16 @@ void fassertOnRepeatedExecution(const LogicalSessionId& lsid, StmtId stmtId, const repl::OpTime& firstOpTime, const repl::OpTime& secondOpTime) { - severe() << "Statement id " << stmtId << " from transaction [ " << lsid.toBSON() << ":" - << txnNumber << " ] was committed once with opTime " << firstOpTime - << " and a second time with opTime " << secondOpTime - << ". This indicates possible data corruption or server bug and the process will be " - "terminated."; + LOGV2_FATAL(22524, + "Statement id {stmtId} from transaction [ {lsid}:{txnNumber} ] was committed once " + "with opTime {firstOpTime} and a second time with opTime {secondOpTime}. This " + "indicates possible data corruption or server bug and the process will be " + "terminated.", + "stmtId"_attr = stmtId, + "lsid"_attr = lsid.toBSON(), + "txnNumber"_attr = txnNumber, + "firstOpTime"_attr = firstOpTime, + "secondOpTime"_attr = secondOpTime); fassertFailed(40526); } @@ -654,9 +660,9 @@ TransactionParticipant::OplogSlotReserver::OplogSlotReserver(OperationContext* o TransactionParticipant::OplogSlotReserver::~OplogSlotReserver() { if (MONGO_unlikely(hangBeforeReleasingTransactionOplogHole.shouldFail())) { - log() - << "transaction - hangBeforeReleasingTransactionOplogHole fail point enabled. Blocking " - "until fail point is disabled."; + LOGV2(22520, + "transaction - hangBeforeReleasingTransactionOplogHole fail point enabled. Blocking " + "until fail point is disabled."); hangBeforeReleasingTransactionOplogHole.pauseWhileSet(); } @@ -1071,9 +1077,12 @@ Timestamp TransactionParticipant::Participant::prepareTransaction( } catch (...) { // It is illegal for aborting a prepared transaction to fail for any reason, so we crash // instead. - severe() << "Caught exception during abort of prepared transaction " - << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": " - << exceptionToStatus(); + LOGV2_FATAL(22525, + "Caught exception during abort of prepared transaction " + "{opCtx_getTxnNumber} on {sessionId}: {exceptionToStatus}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "sessionId"_attr = _sessionId().toBSON(), + "exceptionToStatus"_attr = exceptionToStatus()); std::terminate(); } }); @@ -1135,9 +1144,11 @@ Timestamp TransactionParticipant::Participant::prepareTransaction( if (MONGO_unlikely(hangAfterReservingPrepareTimestamp.shouldFail())) { // This log output is used in js tests so please leave it. - log() << "transaction - hangAfterReservingPrepareTimestamp fail point " - "enabled. Blocking until fail point is disabled. Prepare OpTime: " - << prepareOplogSlot; + LOGV2(22521, + "transaction - hangAfterReservingPrepareTimestamp fail point " + "enabled. Blocking until fail point is disabled. Prepare OpTime: " + "{prepareOplogSlot}", + "prepareOplogSlot"_attr = prepareOplogSlot); hangAfterReservingPrepareTimestamp.pauseWhileSet(); } } @@ -1163,8 +1174,9 @@ Timestamp TransactionParticipant::Participant::prepareTransaction( } if (MONGO_unlikely(hangAfterSettingPrepareStartTime.shouldFail())) { - log() << "transaction - hangAfterSettingPrepareStartTime fail point enabled. Blocking " - "until fail point is disabled."; + LOGV2(22522, + "transaction - hangAfterSettingPrepareStartTime fail point enabled. Blocking " + "until fail point is disabled."); hangAfterSettingPrepareStartTime.pauseWhileSet(); } @@ -1390,9 +1402,12 @@ void TransactionParticipant::Participant::commitPreparedTransaction( } catch (...) { // It is illegal for committing a prepared transaction to fail for any reason, other than an // invalid command, so we crash instead. - severe() << "Caught exception during commit of prepared transaction " - << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": " - << exceptionToStatus(); + LOGV2_FATAL(22526, + "Caught exception during commit of prepared transaction {opCtx_getTxnNumber} " + "on {sessionId}: {exceptionToStatus}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "sessionId"_attr = _sessionId().toBSON(), + "exceptionToStatus"_attr = exceptionToStatus()); std::terminate(); } } @@ -1518,10 +1533,12 @@ void TransactionParticipant::Participant::_abortActiveTransaction( } catch (...) { // It is illegal for aborting a transaction that must write an abort oplog entry to fail // after aborting the storage transaction, so we crash instead. - severe() - << "Caught exception during abort of transaction that must write abort oplog entry " - << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": " - << exceptionToStatus(); + LOGV2_FATAL(22527, + "Caught exception during abort of transaction that must write abort oplog " + "entry {opCtx_getTxnNumber} on {sessionId}: {exceptionToStatus}", + "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(), + "sessionId"_attr = _sessionId().toBSON(), + "exceptionToStatus"_attr = exceptionToStatus()); std::terminate(); } } else { @@ -1901,9 +1918,13 @@ void TransactionParticipant::Participant::_logSlowTransaction( opDuration, Milliseconds(serverGlobalParams.slowMS)) .first) { - log(logger::LogComponent::kTransaction) - << "transaction " - << _transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs); + LOGV2_OPTIONS( + 22523, + {logComponentV1toV2(logger::LogComponent::kTransaction)}, + "transaction " + "{transactionInfoForLog_opCtx_lockStats_terminationCause_readConcernArgs}", + "transactionInfoForLog_opCtx_lockStats_terminationCause_readConcernArgs"_attr = + _transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs)); } } } diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index be0ca3fd9c2..d3668ab3dd6 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -54,6 +54,7 @@ #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/ttl_collection_cache.h" #include "mongo/db/ttl_gen.h" +#include "mongo/logv2/log.h" #include "mongo/util/background.h" #include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/exit.h" @@ -96,26 +97,29 @@ public: sleepsecs(ttlMonitorSleepSecs.load()); } - LOG(3) << "thread awake"; + LOGV2_DEBUG(22528, 3, "thread awake"); if (!ttlMonitorEnabled.load()) { - LOG(1) << "disabled"; + LOGV2_DEBUG(22529, 1, "disabled"); continue; } if (lockedForWriting()) { // Note: this is not perfect as you can go into fsync+lock between this and actually // doing the delete later. - LOG(3) << "locked for writing"; + LOGV2_DEBUG(22530, 3, "locked for writing"); continue; } try { doTTLPass(); } catch (const WriteConflictException&) { - LOG(1) << "got WriteConflictException"; + LOGV2_DEBUG(22531, 1, "got WriteConflictException"); } catch (const ExceptionForCat<ErrorCategory::Interruption>& interruption) { - LOG(1) << "TTLMonitor was interrupted: " << interruption; + LOGV2_DEBUG(22532, + 1, + "TTLMonitor was interrupted: {interruption}", + "interruption"_attr = interruption); } } } @@ -181,11 +185,16 @@ private: try { doTTLForIndex(&opCtx, it.first, it.second); } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - warning() << "TTLMonitor was interrupted, waiting " << ttlMonitorSleepSecs.load() - << " seconds before doing another pass"; + LOGV2_WARNING(22537, + "TTLMonitor was interrupted, waiting {ttlMonitorSleepSecs_load} " + "seconds before doing another pass", + "ttlMonitorSleepSecs_load"_attr = ttlMonitorSleepSecs.load()); return; } catch (const DBException& dbex) { - error() << "Error processing ttl index: " << it.second << " -- " << dbex.toString(); + LOGV2_ERROR(22538, + "Error processing ttl index: {it_second} -- {dbex}", + "it_second"_attr = it.second, + "dbex"_attr = dbex.toString()); // Continue on to the next index. continue; } @@ -201,23 +210,33 @@ private: return; } if (!userAllowedWriteNS(collectionNSS).isOK()) { - error() << "namespace '" << collectionNSS - << "' doesn't allow deletes, skipping ttl job for: " << idx; + LOGV2_ERROR( + 22539, + "namespace '{collectionNSS}' doesn't allow deletes, skipping ttl job for: {idx}", + "collectionNSS"_attr = collectionNSS, + "idx"_attr = idx); return; } const BSONObj key = idx["key"].Obj(); const StringData name = idx["name"].valueStringData(); if (key.nFields() != 1) { - error() << "key for ttl index can only have 1 field, skipping ttl job for: " << idx; + LOGV2_ERROR(22540, + "key for ttl index can only have 1 field, skipping ttl job for: {idx}", + "idx"_attr = idx); return; } - LOG(1) << "ns: " << collectionNSS << " key: " << key << " name: " << name; + LOGV2_DEBUG(22533, + 1, + "ns: {collectionNSS} key: {key} name: {name}", + "collectionNSS"_attr = collectionNSS, + "key"_attr = key, + "name"_attr = name); AutoGetCollection autoGetCollection(opCtx, collectionNSS, MODE_IX); if (MONGO_unlikely(hangTTLMonitorWithLock.shouldFail())) { - log() << "Hanging due to hangTTLMonitorWithLock fail point"; + LOGV2(22534, "Hanging due to hangTTLMonitorWithLock fail point"); hangTTLMonitorWithLock.pauseWhileSet(opCtx); } @@ -234,8 +253,11 @@ private: const IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(opCtx, name); if (!desc) { - LOG(1) << "index not found (index build in progress? index dropped?), skipping " - << "ttl job for: " << idx; + LOGV2_DEBUG(22535, + 1, + "index not found (index build in progress? index dropped?), skipping ttl " + "job for: {idx}", + "idx"_attr = idx); return; } @@ -244,15 +266,21 @@ private: idx = desc->infoObj(); if (IndexType::INDEX_BTREE != IndexNames::nameToType(desc->getAccessMethodName())) { - error() << "special index can't be used as a ttl index, skipping ttl job for: " << idx; + LOGV2_ERROR(22541, + "special index can't be used as a ttl index, skipping ttl job for: {idx}", + "idx"_attr = idx); return; } BSONElement secondsExpireElt = idx[secondsExpireField]; if (!secondsExpireElt.isNumber()) { - error() << "ttl indexes require the " << secondsExpireField << " field to be " - << "numeric but received a type of " << typeName(secondsExpireElt.type()) - << ", skipping ttl job for: " << idx; + LOGV2_ERROR( + 22542, + "ttl indexes require the {secondsExpireField} field to be numeric but received a " + "type of {typeName_secondsExpireElt_type}, skipping ttl job for: {idx}", + "secondsExpireField"_attr = secondsExpireField, + "typeName_secondsExpireElt_type"_attr = typeName(secondsExpireElt.type()), + "idx"_attr = idx); return; } @@ -295,14 +323,16 @@ private: Status result = exec->executePlan(); if (!result.isOK()) { - error() << "ttl query execution for index " << idx - << " failed with status: " << redact(result); + LOGV2_ERROR(22543, + "ttl query execution for index {idx} failed with status: {result}", + "idx"_attr = idx, + "result"_attr = redact(result)); return; } const long long numDeleted = DeleteStage::getNumDeleted(*exec); ttlDeletedDocuments.increment(numDeleted); - LOG(1) << "deleted: " << numDeleted; + LOGV2_DEBUG(22536, 1, "deleted: {numDeleted}", "numDeleted"_attr = numDeleted); } ServiceContext* _serviceContext; diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp index 5d3e410cd41..174cbc37568 100644 --- a/src/mongo/db/views/durable_view_catalog.cpp +++ b/src/mongo/db/views/durable_view_catalog.cpp @@ -45,6 +45,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/storage/record_data.h" #include "mongo/db/views/view_catalog.h" +#include "mongo/logv2/log.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -195,7 +196,11 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx, Snapshotted<BSONObj> oldView; if (!id.isValid() || !systemViews->findDoc(opCtx, id, &oldView)) { - LOG(2) << "insert view " << view << " into " << _db->getSystemViewsName(); + LOGV2_DEBUG(22544, + 2, + "insert view {view} into {db_getSystemViewsName}", + "view"_attr = view, + "db_getSystemViewsName"_attr = _db->getSystemViewsName()); uassertStatusOK( systemViews->insertDocument(opCtx, InsertStatement(view), &CurOp::get(opCtx)->debug())); } else { @@ -225,7 +230,11 @@ void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceStri if (!id.isValid()) return; - LOG(2) << "remove view " << name << " from " << _db->getSystemViewsName(); + LOGV2_DEBUG(22545, + 2, + "remove view {name} from {db_getSystemViewsName}", + "name"_attr = name, + "db_getSystemViewsName"_attr = _db->getSystemViewsName()); systemViews->deleteDocument(opCtx, kUninitializedStmtId, id, &CurOp::get(opCtx)->debug()); } } // namespace mongo diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp index 11003651962..01a104b14d3 100644 --- a/src/mongo/db/views/view_catalog.cpp +++ b/src/mongo/db/views/view_catalog.cpp @@ -55,6 +55,7 @@ #include "mongo/db/views/resolved_view.h" #include "mongo/db/views/view.h" #include "mongo/db/views/view_graph.h" +#include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -94,7 +95,10 @@ Status ViewCatalog::reload(OperationContext* opCtx, ViewCatalogLookupBehavior lo Status ViewCatalog::_reload(WithLock, OperationContext* opCtx, ViewCatalogLookupBehavior lookupBehavior) { - LOG(1) << "reloading view catalog for database " << _durable->getName(); + LOGV2_DEBUG(22546, + 1, + "reloading view catalog for database {durable_getName}", + "durable_getName"_attr = _durable->getName()); _viewMap.clear(); _valid = false; @@ -137,8 +141,10 @@ Status ViewCatalog::_reload(WithLock, } } catch (const DBException& ex) { auto status = ex.toStatus(); - LOG(0) << "could not load view catalog for database " << _durable->getName() << ": " - << status; + LOGV2(22547, + "could not load view catalog for database {durable_getName}: {status}", + "durable_getName"_attr = _durable->getName(), + "status"_attr = status); return status; } diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 546a590c9b5..3f55e87de40 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -47,6 +47,7 @@ #include "mongo/db/storage/storage_engine.h" #include "mongo/db/transaction_validation.h" #include "mongo/db/write_concern_options.h" +#include "mongo/logv2/log.h" #include "mongo/rpc/protocol.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" @@ -97,8 +98,13 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx, auto wcDefault = ReadWriteConcernDefaults::get(opCtx->getServiceContext()) .getDefaultWriteConcern(opCtx); if (wcDefault) { - LOG(2) << "Applying default writeConcern on " << cmdObj.firstElementFieldName() - << " of " << wcDefault->toBSON(); + LOGV2_DEBUG(22548, + 2, + "Applying default writeConcern on {cmdObj_firstElementFieldName} " + "of {wcDefault}", + "cmdObj_firstElementFieldName"_attr = + cmdObj.firstElementFieldName(), + "wcDefault"_attr = wcDefault->toBSON()); return *wcDefault; } } @@ -210,8 +216,11 @@ Status waitForWriteConcern(OperationContext* opCtx, const OpTime& replOpTime, const WriteConcernOptions& writeConcern, WriteConcernResult* result) { - LOG(2) << "Waiting for write concern. OpTime: " << replOpTime - << ", write concern: " << writeConcern.toBSON(); + LOGV2_DEBUG(22549, + 2, + "Waiting for write concern. OpTime: {replOpTime}, write concern: {writeConcern}", + "replOpTime"_attr = replOpTime, + "writeConcern"_attr = writeConcern.toBSON()); auto const replCoord = repl::ReplicationCoordinator::get(opCtx); @@ -227,7 +236,7 @@ Status waitForWriteConcern(OperationContext* opCtx, switch (writeConcernWithPopulatedSyncMode.syncMode) { case WriteConcernOptions::SyncMode::UNSET: - severe() << "Attempting to wait on a WriteConcern with an unset sync option"; + LOGV2_FATAL(22550, "Attempting to wait on a WriteConcern with an unset sync option"); fassertFailed(34410); case WriteConcernOptions::SyncMode::NONE: break; |