void MongoDSessionCatalog::invalidateSessions(OperationContext* opCtx, boost::optional<BSONObj> singleSessionDoc) { const auto replCoord = repl::ReplicationCoordinator::get(opCtx); bool isReplSet = replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet; if (isReplSet) { uassert(40528, str::stream() << "Direct writes against " << NamespaceString::kSessionTransactionsTableNamespace.ns() << " cannot be performed using a transaction or on a session.", !opCtx->getLogicalSessionId()); } const auto catalog = SessionCatalog::get(opCtx); // The use of shared_ptr here is in order to work around the limitation of stdx::function that // the functor must be copyable. auto sessionKillTokens = std::make_shared<std::vector<SessionCatalog::KillToken>>(); if (singleSessionDoc) { sessionKillTokens->emplace_back(catalog->killSession(LogicalSessionId::parse( IDLParserErrorContext("lsid"), singleSessionDoc->getField("_id").Obj()))); } else { SessionKiller::Matcher matcher( KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}); catalog->scanSessions(matcher, [&sessionKillTokens](const ObservableSession& session) { sessionKillTokens->emplace_back(session.kill()); }); } killSessionTokensFunction(opCtx, sessionKillTokens); }
/*! \fn AppContext::cleanSessions() */ void AppContext::cleanSessions() { sptk::CGuard guard(m_sessionLock); sessionlist_t::iterator cur=m_sessions.begin(); while(cur!=m_sessions.end()){ if(!cur->second->validP()){ std::string sid = cur->first; cur++; killSession(sid); } else { cur++; } } }