summaryrefslogtreecommitdiff
path: root/src/mongo/db/session.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/session.h')
-rw-r--r--src/mongo/db/session.h71
1 files changed, 11 insertions, 60 deletions
diff --git a/src/mongo/db/session.h b/src/mongo/db/session.h
index ba01d6458f5..ad5a9dfb82b 100644
--- a/src/mongo/db/session.h
+++ b/src/mongo/db/session.h
@@ -32,13 +32,12 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/db/logical_session_id.h"
+#include "mongo/db/operation_context.h"
#include "mongo/util/concurrency/with_lock.h"
#include "mongo/util/decorable.h"
namespace mongo {
-class OperationContext;
-
/**
* A decorable container for state associated with an active session running on a MongoD or MongoS
* server. Refer to SessionCatalog for more information on the semantics of sessions.
@@ -46,10 +45,11 @@ class OperationContext;
class Session : public Decorable<Session> {
MONGO_DISALLOW_COPYING(Session);
+ friend class ObservableSession;
friend class SessionCatalog;
public:
- explicit Session(LogicalSessionId sessionId);
+ explicit Session(LogicalSessionId sessionId) : _sessionId(std::move(sessionId)) {}
/**
* The logical session id that this object represents.
@@ -58,72 +58,23 @@ public:
return _sessionId;
}
- /**
- * Returns a pointer to the current operation running on this Session, or nullptr if there is no
- * operation currently running on this Session.
- */
- OperationContext* currentOperation() const;
-
- /**
- * Increments the number of "killers" for this session 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. This token is later on passed to
- * '_markNotKilled' in order to decrement the number of "killers".
- *
- * Marking session as killed is an internal property only that will cause any further calls to
- * 'checkOutSession' to block until 'checkOutSessionForKill' is called the same number of times
- * as 'kill' was called and the returned scoped object destroyed.
- *
- * If the first killer finds the session checked-out, this method will also interrupt the
- * operation context which has it checked-out.
- *
- * 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;
+ OperationContext* currentOperation_forTest() const {
+ return _checkoutOpCtx;
+ }
private:
- /**
- * Set/clear the current check-out state of the session by storing the operation which has this
- * session currently checked-out.
- *
- * Must be called under the SessionCatalog mutex and internally will acquire the Session mutex.
- */
- 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;
- // Protects the member variables below. The order of lock acquisition should always be:
- //
- // 1) SessionCatalog mutex (if applicable)
- // 2) Session mutex
- // 3) Any decoration mutexes and/or the currently running Client's lock
- mutable stdx::mutex _mutex;
-
// A pointer back to the currently running operation on this Session, or nullptr if there
// is no operation currently running for the Session.
+ //
+ // May be read by holders of the SessionCatalog mutex. May only be set when clear or cleared
+ // when set, and the opCtx being set or cleared must have its client locked at the time.
OperationContext* _checkoutOpCtx{nullptr};
- // Incremented every time 'kill' is invoked and decremented by '_markNotKilled'.
+ // Counter indicating the number of times ObservableSession::kill has been called on this
+ // session, which have not yet had a corresponding call to checkOutSessionForKill.
int _killsRequested{0};
};