summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_session_cache.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-06-08 18:18:28 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-06-09 11:08:57 -0400
commitfb22390ab04a55fcbd91eba673dde310cb938351 (patch)
tree7754063c492174dbd45084c61b228d59b704c02d /src/mongo/db/logical_session_cache.cpp
parentff412300b3688dad4938bb381ec3aba12a81024b (diff)
downloadmongo-fb22390ab04a55fcbd91eba673dde310cb938351.tar.gz
SERVER-28346 Add more unit tests for the logical session cache
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);
+ }
}
}
}