summaryrefslogtreecommitdiff
path: root/src/mongo/db/session_catalog.h
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2022-02-25 21:39:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-25 22:07:09 +0000
commit2a08e923539db20d79af032a27344a5990cee4a4 (patch)
tree6e59738a33f7422c8fa7a60acb34c9e3efd49cf3 /src/mongo/db/session_catalog.h
parent8bf8d04181e865a51b1e0d356805ab048bfbb950 (diff)
downloadmongo-2a08e923539db20d79af032a27344a5990cee4a4.tar.gz
SERVER-63978 Killing a child session should prevent checking out its parent
Diffstat (limited to 'src/mongo/db/session_catalog.h')
-rw-r--r--src/mongo/db/session_catalog.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/mongo/db/session_catalog.h b/src/mongo/db/session_catalog.h
index eb838038d8d..a744e067907 100644
--- a/src/mongo/db/session_catalog.h
+++ b/src/mongo/db/session_catalog.h
@@ -63,11 +63,13 @@ public:
class SessionToKill;
struct KillToken {
- KillToken(LogicalSessionId lsid) : lsidToKill(std::move(lsid)) {}
+ KillToken(LogicalSessionId lsid, boost::optional<LogicalSessionId> parentLsid)
+ : lsidToKill(std::move(lsid)), parentLsidToKill(std::move(parentLsid)) {}
KillToken(KillToken&&) = default;
KillToken& operator=(KillToken&&) = default;
LogicalSessionId lsidToKill;
+ boost::optional<LogicalSessionId> parentLsidToKill;
};
SessionCatalog() = default;
@@ -123,7 +125,14 @@ public:
private:
struct SessionRuntimeInfo {
- SessionRuntimeInfo(LogicalSessionId lsid) : session(std::move(lsid)) {}
+ SessionRuntimeInfo(LogicalSessionId lsid, SessionRuntimeInfo* parentSri)
+ : session(std::move(lsid)) {
+ // If we're a child we must have been given a parent session, if not, we must not have.
+ invariant(bool(getParentSessionId(lsid)) == bool(parentSri));
+ if (parentSri) {
+ session._parentSession = &parentSri->session;
+ }
+ }
~SessionRuntimeInfo();
// Must only be accessed when the state is kInUse and only by the operation context, which
@@ -166,8 +175,13 @@ private:
/**
* Creates or returns the session runtime info for 'lsid' from the '_sessions' map. The
* returned pointer is guaranteed to be linked on the map for as long as the mutex is held.
+ *
+ * If we're creating a child session, a pointer to the session runtime info of its parent must
+ * be provided.
*/
- SessionRuntimeInfo* _getOrCreateSessionRuntimeInfo(WithLock lk, const LogicalSessionId& lsid);
+ SessionRuntimeInfo* _getOrCreateSessionRuntimeInfo(WithLock lk,
+ const LogicalSessionId& lsid,
+ SessionRuntimeInfo* parentSri);
/**
* Makes a session, previously checked out through 'checkoutSession', available again.