diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/session_catalog.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/session_catalog.h | 3 | ||||
-rw-r--r-- | src/mongo/db/session_catalog_mongod.cpp | 13 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp index cade0e53405..a82af347a04 100644 --- a/src/mongo/db/session_catalog.cpp +++ b/src/mongo/db/session_catalog.cpp @@ -116,6 +116,14 @@ SessionCatalog::SessionToKill SessionCatalog::checkOutSessionForKill(OperationCo return SessionToKill(ScopedCheckedOutSession(*this, std::move(sri), std::move(killToken))); } +void SessionCatalog::scanSession(const LogicalSessionId& lsid, + const ScanSessionsCallbackFn& workerFn) { + stdx::lock_guard<stdx::mutex> lg(_mutex); + auto it = _sessions.find(lsid); + if (it != _sessions.end()) + workerFn({lg, it->second->session}); +} + void SessionCatalog::scanSessions(const SessionKiller::Matcher& matcher, const ScanSessionsCallbackFn& workerFn) { stdx::lock_guard<stdx::mutex> lg(_mutex); diff --git a/src/mongo/db/session_catalog.h b/src/mongo/db/session_catalog.h index 73cfcf40b1a..ca020d378d6 100644 --- a/src/mongo/db/session_catalog.h +++ b/src/mongo/db/session_catalog.h @@ -97,10 +97,9 @@ public: * not allowed to block, perform I/O or acquire any lock manager locks. * Iterates through the SessionCatalog and applies 'workerFn' to each Session. This locks the * SessionCatalog. - * - * TODO SERVER-33850: Take Matcher out of the SessionKiller namespace. */ using ScanSessionsCallbackFn = stdx::function<void(const ObservableSession&)>; + void scanSession(const LogicalSessionId& lsid, const ScanSessionsCallbackFn& workerFn); void scanSessions(const SessionKiller::Matcher& matcher, const ScanSessionsCallbackFn& workerFn); diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp index d17280e9ca3..39880028b28 100644 --- a/src/mongo/db/session_catalog_mongod.cpp +++ b/src/mongo/db/session_catalog_mongod.cpp @@ -202,8 +202,17 @@ void MongoDSessionCatalog::invalidateSessions(OperationContext* opCtx, auto sessionKillTokens = std::make_shared<std::vector<SessionCatalog::KillToken>>(); if (singleSessionDoc) { - sessionKillTokens->emplace_back(catalog->killSession(LogicalSessionId::parse( - IDLParserErrorContext("lsid"), singleSessionDoc->getField("_id").Obj()))); + const auto lsid = LogicalSessionId::parse(IDLParserErrorContext("lsid"), + singleSessionDoc->getField("_id").Obj()); + catalog->scanSession(lsid, [&sessionKillTokens](const ObservableSession& session) { + const auto participant = TransactionParticipant::get(session); + uassert(ErrorCodes::PreparedTransactionInProgress, + str::stream() << "Cannot modify the entry for session " + << session.getSessionId().getId() + << " because it is in the prepared state", + !participant.transactionIsPrepared()); + sessionKillTokens->emplace_back(session.kill()); + }); } else { SessionKiller::Matcher matcher( KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}); |