summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-04-18 17:26:44 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-05-02 17:32:13 -0400
commitdcf7912e275b72d1462d4ecf26f195f8accb45ad (patch)
treed96248496d8fa66ccd73fb3c1038bd67c801ad10 /src
parentdabbf059e6f96edb4898b42d532d460efd2510f2 (diff)
downloadmongo-dcf7912e275b72d1462d4ecf26f195f8accb45ad.tar.gz
SERVER-36483 Do not reap transaction entries for prepared transactions
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/session_catalog.cpp8
-rw-r--r--src/mongo/db/session_catalog.h3
-rw-r--r--src/mongo/db/session_catalog_mongod.cpp13
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)});