summaryrefslogtreecommitdiff
path: root/src/mongo/db/session_catalog.cpp
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2019-07-09 16:14:31 -0400
committerRandolph Tan <randolph@10gen.com>2019-07-18 14:08:29 -0400
commit36dc61299993ce6473a4660150bfb25a59afce77 (patch)
tree5742a6c76e03880eb20abf7a8fd50c27b868bd63 /src/mongo/db/session_catalog.cpp
parenta4f07aed5277cb31d2422b3dc658b5758d1773ed (diff)
downloadmongo-36dc61299993ce6473a4660150bfb25a59afce77.tar.gz
SERVER-39692 Make mongos shutdown drain all in-progress transactions
Diffstat (limited to 'src/mongo/db/session_catalog.cpp')
-rw-r--r--src/mongo/db/session_catalog.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp
index d8ac79858a2..55b0c331ad4 100644
--- a/src/mongo/db/session_catalog.cpp
+++ b/src/mongo/db/session_catalog.cpp
@@ -251,6 +251,23 @@ OperationContextSession::OperationContextSession(OperationContext* opCtx) : _opC
checkOut(opCtx);
}
+OperationContextSession::OperationContextSession(OperationContext* opCtx,
+ SessionCatalog::KillToken killToken)
+ : _opCtx(opCtx) {
+ auto& checkedOutSession = operationSessionDecoration(opCtx);
+
+ invariant(!checkedOutSession);
+ invariant(!opCtx->getLogicalSessionId()); // lsid is specified by killToken argument.
+
+ const auto catalog = SessionCatalog::get(opCtx);
+ auto scopedSessionForKill = catalog->checkOutSessionForKill(opCtx, std::move(killToken));
+
+ // We acquire a Client lock here to guard the construction of this session so that references to
+ // this session are safe to use while the lock is held
+ stdx::lock_guard lk(*opCtx->getClient());
+ checkedOutSession.emplace(std::move(scopedSessionForKill._scos));
+}
+
OperationContextSession::~OperationContextSession() {
// Only release the checked out session at the end of the top-level request from the client, not
// at the end of a nested DBDirectClient call