summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_session_cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/logical_session_cache.cpp')
-rw-r--r--src/mongo/db/logical_session_cache.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/mongo/db/logical_session_cache.cpp b/src/mongo/db/logical_session_cache.cpp
index 9ab51495f52..1c94e019ac3 100644
--- a/src/mongo/db/logical_session_cache.cpp
+++ b/src/mongo/db/logical_session_cache.cpp
@@ -145,8 +145,8 @@ Status LogicalSessionCache::startSession(LogicalSessionRecord authoritativeRecor
}
void LogicalSessionCache::_refresh() {
- SessionList activeSessions;
- SessionList deadSessions;
+ LogicalSessionIdSet activeSessions;
+ LogicalSessionIdSet deadSessions;
auto now = _service->now();
@@ -164,9 +164,9 @@ void LogicalSessionCache::_refresh() {
for (auto& it : cacheCopy) {
auto record = it.second;
if (!_isDead(record, now)) {
- activeSessions.push_back(record.getLsid());
+ activeSessions.insert(record.getLsid());
} else {
- deadSessions.push_back(record.getLsid());
+ deadSessions.insert(record.getLsid());
}
}
@@ -190,25 +190,28 @@ void LogicalSessionCache::_refresh() {
// by another thread.
it->second.setLastUse(now);
}
+
+ activeSessions.insert(lsid);
}
}
- activeSessions.splice(activeSessions.begin(), serviceSessions);
-
// Query into the sessions collection to do the refresh. If any sessions have
// failed to refresh, it means their authoritative records were removed, and
// we should remove such records from our cache as well.
auto failedToRefresh = _sessionsColl->refreshSessions(std::move(activeSessions));
- deadSessions.splice(deadSessions.begin(), failedToRefresh);
// Prune any dead records out of the cache. Dead records are ones that failed to
// refresh, or ones that have expired locally. We don't make an effort to check
// if the locally-expired records still have live authoritative records in the
// sessions collection. We also don't attempt to resurrect our expired records.
+ // However, we *do* keep records alive if they are active on the service.
{
stdx::unique_lock<stdx::mutex> lk(_cacheMutex);
- for (auto deadId : deadSessions) {
- _cache.erase(deadId);
+ for (auto deadId : failedToRefresh) {
+ auto it = serviceSessions.find(deadId);
+ if (it == serviceSessions.end()) {
+ _cache.erase(deadId);
+ }
}
}
}