From 05683c2d9d9654079df750e9ac5f389a10068b63 Mon Sep 17 00:00:00 2001 From: Cheahuychou Mao Date: Tue, 31 May 2022 14:36:05 +0000 Subject: SERVER-66850 Make the LogicalSessionCache reaper only scan parent sessions when searching for expired logical sessions (cherry picked from commit d461c7c2fb3197b82585099f7aa7c1a07f2223db) --- src/mongo/s/session_catalog_router.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/mongo/s') diff --git a/src/mongo/s/session_catalog_router.cpp b/src/mongo/s/session_catalog_router.cpp index aef732d30b0..6bbe4e8af65 100644 --- a/src/mongo/s/session_catalog_router.cpp +++ b/src/mongo/s/session_catalog_router.cpp @@ -45,18 +45,15 @@ int RouterSessionCatalog::reapSessionsOlderThan(OperationContext* opCtx, // Find the possibly expired logical session ids in the in-memory catalog. LogicalSessionIdSet possiblyExpiredLogicalSessionIds; - catalog->scanSessions( - SessionKiller::Matcher(KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}), - [&](const ObservableSession& session) { - const auto sessionId = session.getSessionId(); - - // Skip child transaction sessions since they correspond to the same logical session as - // their parent transaction session so they have the same last check-out time as the - // the parent's. - if (session.getLastCheckout() < possiblyExpired && !getParentSessionId(sessionId)) { - possiblyExpiredLogicalSessionIds.insert(session.getSessionId()); - } - }); + // Skip child transaction sessions since they correspond to the same logical session as their + // parent transaction session so they have the same last check-out time as the parent's. + catalog->scanParentSessions([&](const ObservableSession& session) { + const auto sessionId = session.getSessionId(); + invariant(!getParentSessionId(sessionId)); + if (session.getLastCheckout() < possiblyExpired) { + possiblyExpiredLogicalSessionIds.insert(session.getSessionId()); + } + }); // From the possibly expired logical session ids, find the ones that have been removed from // from the config.system.sessions collection. auto expiredLogicalSessionIds = -- cgit v1.2.1