summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/session_catalog.cpp16
-rw-r--r--src/mongo/db/session_catalog.h7
-rw-r--r--src/mongo/db/session_catalog_mongod.cpp21
-rw-r--r--src/mongo/s/session_catalog_router.cpp21
4 files changed, 40 insertions, 25 deletions
diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp
index d239366b18d..bc5b97b8566 100644
--- a/src/mongo/db/session_catalog.cpp
+++ b/src/mongo/db/session_catalog.cpp
@@ -173,6 +173,22 @@ void SessionCatalog::scanSessions(const SessionKiller::Matcher& matcher,
}
}
+void SessionCatalog::scanParentSessions(const ScanSessionsCallbackFn& workerFn) {
+ stdx::lock_guard<Latch> lg(_mutex);
+
+ LOGV2_DEBUG(6685000,
+ 2,
+ "Scanning {sessionCount} sessions",
+ "Scanning sessions",
+ "sessionCount"_attr = _sessions.size());
+
+ for (auto& [parentLsid, sri] : _sessions) {
+ ObservableSession osession(lg, sri.get(), &sri->parentSession);
+ workerFn(osession);
+ invariant(!osession._markedForReap, "Cannot reap a session via 'scanSessions'");
+ }
+}
+
LogicalSessionIdSet SessionCatalog::scanSessionsForReap(
const LogicalSessionId& parentLsid,
const ScanSessionsCallbackFn& parentSessionWorkerFn,
diff --git a/src/mongo/db/session_catalog.h b/src/mongo/db/session_catalog.h
index 43fc2251c2d..937889c82cc 100644
--- a/src/mongo/db/session_catalog.h
+++ b/src/mongo/db/session_catalog.h
@@ -96,7 +96,7 @@ public:
/**
* Iterates through the SessionCatalog under the SessionCatalog mutex and applies 'workerFn' to
- * each Session which matches the specified 'matcher'. Does not support reaping.
+ * each Session which matches the specified 'lsid' or 'matcher'. Does not support reaping.
*
* NOTE: Since this method runs with the session catalog mutex, the work done by 'workerFn' is
* not allowed to block, perform I/O or acquire any lock manager locks.
@@ -108,6 +108,11 @@ public:
const ScanSessionsCallbackFn& workerFn);
/**
+ * Same as the above but only applies 'workerFn' to parent Sessions.
+ */
+ void scanParentSessions(const ScanSessionsCallbackFn& workerFn);
+
+ /**
* Same as the above but applies 'parentSessionWorkerFn' to the Session whose session id is
* equal to 'parentLsid' and then applies 'childSessionWorkerFn' to the Sessions whose parent
* session id is equal to 'parentLsid'. To be used with 'markForReap' for reaping sessions
diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp
index 0e14c08a058..427569bba01 100644
--- a/src/mongo/db/session_catalog_mongod.cpp
+++ b/src/mongo/db/session_catalog_mongod.cpp
@@ -135,18 +135,15 @@ LogicalSessionIdSet removeExpiredTransactionSessionsNotInUseFromMemory(
// 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(sessionId);
- }
- });
+ // 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.
+ catalog->scanParentSessions([&](const ObservableSession& session) {
+ const auto sessionId = session.getSessionId();
+ invariant(!getParentSessionId(sessionId));
+ if (session.getLastCheckout() < possiblyExpired) {
+ possiblyExpiredLogicalSessionIds.insert(sessionId);
+ }
+ });
// From the possibly expired logical session ids, find the ones that have been removed from
// from the config.system.sessions collection.
LogicalSessionIdSet expiredLogicalSessionIds =
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 =