Session* OperationContextSession::get(OperationContext* opCtx) { auto& operationSession = operationSessionDecoration(opCtx); if (operationSession) { return operationSession->get(); } return nullptr; }
Session* OperationContextSession::get(OperationContext* opCtx) { auto& checkedOutSession = operationSessionDecoration(opCtx); if (checkedOutSession) { return checkedOutSession->scopedSession.get(); } return nullptr; }
OperationContextSession::~OperationContextSession() { auto& checkedOutSession = operationSessionDecoration(_opCtx); if (checkedOutSession) { invariant(checkedOutSession->checkOutNestingLevel > 0); if (--checkedOutSession->checkOutNestingLevel == 0) { checkedOutSession.reset(); } } }
OperationContextSession::OperationContextSession(OperationContext* opCtx) : _opCtx(opCtx) { if (!opCtx->getLogicalSessionId()) { return; } auto sessionTransactionTable = SessionCatalog::get(opCtx); auto& operationSession = operationSessionDecoration(opCtx); operationSession.emplace(sessionTransactionTable->checkOutSession(opCtx)); }
OperationContextSession::OperationContextSession(OperationContext* opCtx) : _opCtx(opCtx) { if (!opCtx->getLogicalSessionId()) { return; } auto& checkedOutSession = operationSessionDecoration(opCtx); if (!checkedOutSession) { auto sessionTransactionTable = SessionCatalog::get(opCtx); checkedOutSession.emplace(sessionTransactionTable->checkOutSession(opCtx)); } const auto session = checkedOutSession->scopedSession.get(); invariant(opCtx->getLogicalSessionId() == session->getSessionId()); checkedOutSession->checkOutNestingLevel++; if (checkedOutSession->checkOutNestingLevel > 1) { return; } if (opCtx->getTxnNumber()) { checkedOutSession->scopedSession->begin(opCtx, opCtx->getTxnNumber().get()); } }
OperationContextSession::~OperationContextSession() { auto& operationSession = operationSessionDecoration(_opCtx); operationSession.reset(); }