diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-10-09 08:17:38 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-10-31 04:50:08 -0400 |
commit | 236c6c28a18210586673097ee436c5b613b6c46f (patch) | |
tree | 9c26586d5943845b8f3356cbbee41dc75533670d /src/mongo/db/session.h | |
parent | e701da7ff3ec84b2bb3b353fa748c22f7b2a5878 (diff) | |
download | mongo-236c6c28a18210586673097ee436c5b613b6c46f.tar.gz |
SERVER-37244 Make sessions killable outside of the Session/TransactionParticipant object
Diffstat (limited to 'src/mongo/db/session.h')
-rw-r--r-- | src/mongo/db/session.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/session.h b/src/mongo/db/session.h index e1e95741c11..f7349e0d29e 100644 --- a/src/mongo/db/session.h +++ b/src/mongo/db/session.h @@ -64,6 +64,35 @@ public: */ OperationContext* currentOperation() const; + /** + * Marks the session as killed and returns a 'kill token' to to be passed later on to + * 'checkOutSessionForKill' method of the SessionCatalog in order to permit the caller to + * execute any kill cleanup tasks and pass further on to '_markNotKilled' in order to reset the + * kill state. Marking session as killed is an internal property only that will cause any + * further calls to 'checkOutSession' to block until 'checkOutSessionForKill' is called and the + * returned scoped object destroyed. + * + * If the session is currently checked-out, this method will also interrupt the operation + * context which has it checked-out. + * + * If the session is already killed throws ConflictingOperationInProgress exception. + * + * Must be called under the owning SessionCatalog's lock. + */ + struct KillToken { + KillToken(LogicalSessionId lsid) : lsidToKill(std::move(lsid)) {} + KillToken(KillToken&&) = default; + KillToken& operator=(KillToken&&) = default; + + LogicalSessionId lsidToKill; + }; + KillToken kill(WithLock sessionCatalogLock, ErrorCodes::Error reason = ErrorCodes::Interrupted); + + /** + * Returns whether 'kill' has been called on this session. + */ + bool killed() const; + private: /** * Set/clear the current check-out state of the session by storing the operation which has this @@ -74,6 +103,12 @@ private: void _markCheckedOut(WithLock sessionCatalogLock, OperationContext* checkoutOpCtx); void _markCheckedIn(WithLock sessionCatalogLock); + /** + * Used by the session catalog when checking a session back in after a call to 'kill'. See the + * comments for 'kill for more details. + */ + void _markNotKilled(WithLock sessionCatalogLock, KillToken killToken); + // The id of the session with which this object is associated const LogicalSessionId _sessionId; @@ -87,6 +122,9 @@ private: // A pointer back to the currently running operation on this Session, or nullptr if there // is no operation currently running for the Session. OperationContext* _checkoutOpCtx{nullptr}; + + // Set to true if markKilled has been invoked for this session. + bool _killRequested{false}; }; } // namespace mongo |