summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/SConscript1
-rw-r--r--src/mongo/s/session_catalog_router.cpp28
-rw-r--r--src/mongo/s/session_catalog_router.h2
-rw-r--r--src/mongo/s/transaction_router.cpp6
-rw-r--r--src/mongo/s/transaction_router.h2
5 files changed, 36 insertions, 3 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 3566cbbf4b3..d0940c4fd8e 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -74,6 +74,7 @@ env.Library(
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/session_catalog',
+ '$BUILD_DIR/mongo/db/sessions_collection',
],
)
diff --git a/src/mongo/s/session_catalog_router.cpp b/src/mongo/s/session_catalog_router.cpp
index 3139b97637a..aa4f770bec7 100644
--- a/src/mongo/s/session_catalog_router.cpp
+++ b/src/mongo/s/session_catalog_router.cpp
@@ -33,12 +33,38 @@
#include "mongo/s/session_catalog_router.h"
+#include "mongo/db/sessions_collection.h"
+
namespace mongo {
int RouterSessionCatalog::reapSessionsOlderThan(OperationContext* opCtx,
SessionsCollection& sessionsCollection,
Date_t possiblyExpired) {
- return 0;
+ const auto catalog = SessionCatalog::get(opCtx);
+
+ // Capture the possbily expired in-memory session ids
+ LogicalSessionIdSet lsids;
+ catalog->scanSessions(
+ SessionKiller::Matcher(KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}),
+ [&](const ObservableSession& session) {
+ if (session.getLastCheckout() < possiblyExpired) {
+ lsids.insert(session.getSessionId());
+ }
+ });
+
+ // From the passed-in sessions, find the ones which are actually expired/removed
+ auto expiredSessionIds = uassertStatusOK(sessionsCollection.findRemovedSessions(opCtx, lsids));
+
+ // Remove the session ids from the in-memory catalog
+ int numReaped = 0;
+ for (const auto& lsid : expiredSessionIds) {
+ catalog->scanSession(lsid, [&](ObservableSession& session) {
+ session.markForReap();
+ ++numReaped;
+ });
+ }
+
+ return numReaped;
}
RouterOperationContextSession::RouterOperationContextSession(OperationContext* opCtx)
diff --git a/src/mongo/s/session_catalog_router.h b/src/mongo/s/session_catalog_router.h
index da503404391..057f9632593 100644
--- a/src/mongo/s/session_catalog_router.h
+++ b/src/mongo/s/session_catalog_router.h
@@ -40,6 +40,8 @@ public:
/**
* Locates session entries from the in-memory catalog which have not been referenced before
* 'possiblyExpired' and deletes them.
+ *
+ * Returns the number of sessions, which were reaped from the in-memory catalog.
*/
static int reapSessionsOlderThan(OperationContext* opCtx,
SessionsCollection& sessionsCollection,
diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp
index 3fe1193f1fb..4c62186fc6a 100644
--- a/src/mongo/s/transaction_router.cpp
+++ b/src/mongo/s/transaction_router.cpp
@@ -43,8 +43,6 @@
#include "mongo/db/logical_session_id.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/db/repl/read_concern_args.h"
-#include "mongo/db/server_options.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/async_requests_sender.h"
@@ -383,6 +381,10 @@ TransactionRouter* TransactionRouter::get(OperationContext* opCtx) {
return nullptr;
}
+TransactionRouter* get(const ObservableSession& osession) {
+ return &getTransactionRouter(osession.get());
+}
+
TransactionRouter::TransactionRouter() = default;
TransactionRouter::~TransactionRouter() = default;
diff --git a/src/mongo/s/transaction_router.h b/src/mongo/s/transaction_router.h
index 4d38a52562d..ea69181a842 100644
--- a/src/mongo/s/transaction_router.h
+++ b/src/mongo/s/transaction_router.h
@@ -35,6 +35,7 @@
#include "mongo/db/logical_session_id.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/read_concern_args.h"
+#include "mongo/db/session_catalog.h"
#include "mongo/s/async_requests_sender.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/shard_id.h"
@@ -174,6 +175,7 @@ public:
* attached.
*/
static TransactionRouter* get(OperationContext* opCtx);
+ static TransactionRouter* get(const ObservableSession& osession);
/**
* Starts a fresh transaction in this session or continue an existing one. Also cleans up the