diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-10-16 15:29:41 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-10-18 08:14:38 -0400 |
commit | c3f581ee05ca1252aa2f42bbf16a913f9f819e1d (patch) | |
tree | d27f776e475be72bac358d64a35ab9f65c616098 /src/mongo/db/session_catalog.cpp | |
parent | 689e308e910b1c689246da34ac85ca0198f68e4a (diff) | |
download | mongo-c3f581ee05ca1252aa2f42bbf16a913f9f819e1d.tar.gz |
SERVER-31342 Do not remove checked-out sessions from the cache on invalidation
Diffstat (limited to 'src/mongo/db/session_catalog.cpp')
-rw-r--r-- | src/mongo/db/session_catalog.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp index 8f73410fe1c..30b1ddfeb8a 100644 --- a/src/mongo/db/session_catalog.cpp +++ b/src/mongo/db/session_catalog.cpp @@ -67,7 +67,13 @@ const auto operationSessionDecoration = SessionCatalog::SessionCatalog(ServiceContext* serviceContext) : _serviceContext(serviceContext) {} -SessionCatalog::~SessionCatalog() = default; +SessionCatalog::~SessionCatalog() { + stdx::lock_guard<stdx::mutex> lg(_mutex); + for (const auto& entry : _txnTable) { + auto& sri = entry.second; + invariant(!sri->checkedOut); + } +} void SessionCatalog::create(ServiceContext* service) { auto& sessionTransactionTable = sessionTransactionTableDecoration(service); @@ -145,12 +151,12 @@ ScopedCheckedOutSession SessionCatalog::checkOutSession(OperationContext* opCtx) auto sri = _getOrCreateSessionRuntimeInfo(opCtx, lsid, ul); - // Wait until the session is no longer in use + // Wait until the session is no longer checked out opCtx->waitForConditionOrInterrupt( - sri->availableCondVar, ul, [&sri]() { return sri->state != SessionRuntimeInfo::kInUse; }); + sri->availableCondVar, ul, [&sri]() { return !sri->checkedOut; }); - invariant(sri->state == SessionRuntimeInfo::kAvailable); - sri->state = SessionRuntimeInfo::kInUse; + invariant(!sri->checkedOut); + sri->checkedOut = true; return ScopedCheckedOutSession(opCtx, ScopedSession(std::move(sri))); } @@ -183,7 +189,12 @@ void SessionCatalog::invalidateSessions(OperationContext* opCtx, const auto invalidateSessionFn = [&](WithLock, SessionRuntimeInfoMap::iterator it) { auto& sri = it->second; sri->txnState.invalidate(); - _txnTable.erase(it); + + // We cannot remove checked-out sessions from the cache, because operations expect to find + // them there to check back in + if (!sri->checkedOut) { + _txnTable.erase(it); + } }; stdx::lock_guard<stdx::mutex> lg(_mutex); @@ -223,9 +234,9 @@ void SessionCatalog::_releaseSession(const LogicalSessionId& lsid) { invariant(it != _txnTable.end()); auto& sri = it->second; - invariant(sri->state == SessionRuntimeInfo::kInUse); + invariant(sri->checkedOut); - sri->state = SessionRuntimeInfo::kAvailable; + sri->checkedOut = false; sri->availableCondVar.notify_one(); } |