diff options
Diffstat (limited to 'src/mongo/db/kill_sessions_local.cpp')
-rw-r--r-- | src/mongo/db/kill_sessions_local.cpp | 105 |
1 files changed, 57 insertions, 48 deletions
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 |