summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-10-31 16:38:01 +0000
committerevergreen <evergreen@mongodb.com>2019-10-31 16:38:01 +0000
commit1f94484d52064e12baedc7b586a8238d63560baf (patch)
tree5bb03cebfcb2d3137321b4762a0500f8831463dd /src/mongo
parent7a3d17ea6b73bc916d94e59a44d5c1a56cbcb2e5 (diff)
downloadmongo-1f94484d52064e12baedc7b586a8238d63560baf.tar.gz
SERVER-42508 Get rid of some additional unused code in SessionsCollection
... and also improve comments.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/reap_logical_session_cache_now.cpp8
-rw-r--r--src/mongo/db/commands/refresh_logical_session_cache_now.cpp7
-rw-r--r--src/mongo/db/logical_session_cache.h8
-rw-r--r--src/mongo/db/logical_session_cache_impl.cpp20
-rw-r--r--src/mongo/db/logical_session_cache_impl.h9
-rw-r--r--src/mongo/db/logical_session_cache_noop.h10
-rw-r--r--src/mongo/db/logical_session_cache_test.cpp20
-rw-r--r--src/mongo/db/sessions_collection.cpp17
-rw-r--r--src/mongo/db/sessions_collection.h34
-rw-r--r--src/mongo/db/sessions_collection_config_server.cpp13
-rw-r--r--src/mongo/db/sessions_collection_config_server.h14
-rw-r--r--src/mongo/db/sessions_collection_rs.cpp37
-rw-r--r--src/mongo/db/sessions_collection_sharded.cpp51
-rw-r--r--src/mongo/db/sessions_collection_sharded.h18
-rw-r--r--src/mongo/db/sessions_collection_standalone.cpp19
-rw-r--r--src/mongo/s/query/cluster_cursor_manager_test.cpp6
16 files changed, 115 insertions, 176 deletions
diff --git a/src/mongo/db/commands/reap_logical_session_cache_now.cpp b/src/mongo/db/commands/reap_logical_session_cache_now.cpp
index e60e0fb28fd..c1a4d9baf65 100644
--- a/src/mongo/db/commands/reap_logical_session_cache_now.cpp
+++ b/src/mongo/db/commands/reap_logical_session_cache_now.cpp
@@ -30,7 +30,6 @@
#include "mongo/platform/basic.h"
#include "mongo/base/init.h"
-#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/logical_session_cache.h"
@@ -70,12 +69,9 @@ public:
const std::string& db,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
- auto cache = LogicalSessionCache::get(opCtx);
- auto client = opCtx->getClient();
-
- auto res = cache->reapNow(client);
- uassertStatusOK(res);
+ const auto cache = LogicalSessionCache::get(opCtx);
+ cache->reapNow(opCtx);
return true;
}
};
diff --git a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
index b6fb0cb4fd4..2580b4f427d 100644
--- a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
+++ b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
@@ -30,12 +30,10 @@
#include "mongo/platform/basic.h"
#include "mongo/base/init.h"
-#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/logical_session_cache.h"
#include "mongo/db/logical_session_id_helpers.h"
-#include "mongo/db/operation_context.h"
namespace mongo {
namespace {
@@ -75,10 +73,9 @@ public:
const std::string& db,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
- auto cache = LogicalSessionCache::get(opCtx);
- auto client = opCtx->getClient();
+ const auto cache = LogicalSessionCache::get(opCtx);
- auto res = cache->refreshNow(client);
+ auto res = cache->refreshNow(opCtx);
if (res.code() != ErrorCodes::DuplicateKey) {
uassertStatusOK(res);
}
diff --git a/src/mongo/db/logical_session_cache.h b/src/mongo/db/logical_session_cache.h
index 7dcbb8a5373..a6785d00494 100644
--- a/src/mongo/db/logical_session_cache.h
+++ b/src/mongo/db/logical_session_cache.h
@@ -40,10 +40,6 @@
namespace mongo {
-class Client;
-class OperationContext;
-class ServiceContext;
-
/**
* The interface for the logical session cache
*/
@@ -87,12 +83,12 @@ public:
* Refreshes the cache synchronously. This flushes all pending refreshes and inserts to the
* sessions collection.
*/
- virtual Status refreshNow(Client* client) = 0;
+ virtual Status refreshNow(OperationContext* opCtx) = 0;
/**
* Reaps transaction records synchronously.
*/
- virtual Status reapNow(Client* client) = 0;
+ virtual void reapNow(OperationContext* opCtx) = 0;
/**
* Returns the number of session records currently in the cache.
diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp
index 2d8834461ab..eae770cfecc 100644
--- a/src/mongo/db/logical_session_cache_impl.cpp
+++ b/src/mongo/db/logical_session_cache_impl.cpp
@@ -87,14 +87,14 @@ void LogicalSessionCacheImpl::joinOnShutDown() {
Status LogicalSessionCacheImpl::startSession(OperationContext* opCtx,
const LogicalSessionRecord& record) {
stdx::lock_guard lg(_mutex);
- return _addToCache(lg, record);
+ return _addToCacheIfNotFull(lg, record);
}
Status LogicalSessionCacheImpl::vivify(OperationContext* opCtx, const LogicalSessionId& lsid) {
stdx::lock_guard lg(_mutex);
auto it = _activeSessions.find(lsid);
if (it == _activeSessions.end())
- return _addToCache(lg, makeLogicalSessionRecord(opCtx, lsid, _service->now()));
+ return _addToCacheIfNotFull(lg, makeLogicalSessionRecord(opCtx, lsid, _service->now()));
auto& cacheEntry = it->second;
cacheEntry.setLastUse(_service->now());
@@ -102,17 +102,17 @@ Status LogicalSessionCacheImpl::vivify(OperationContext* opCtx, const LogicalSes
return Status::OK();
}
-Status LogicalSessionCacheImpl::refreshNow(Client* client) {
+Status LogicalSessionCacheImpl::refreshNow(OperationContext* opCtx) {
try {
- _refresh(client);
+ _refresh(opCtx->getClient());
} catch (...) {
return exceptionToStatus();
}
return Status::OK();
}
-Status LogicalSessionCacheImpl::reapNow(Client* client) {
- return _reap(client);
+void LogicalSessionCacheImpl::reapNow(OperationContext* opCtx) {
+ uassertStatusOK(_reap(opCtx->getClient()));
}
size_t LogicalSessionCacheImpl::size() {
@@ -242,9 +242,9 @@ void LogicalSessionCacheImpl::_refresh(Client* client) {
try {
_sessionsColl->setupSessionsCollection(opCtx);
- } catch (DBException& ex) {
- log() << "Failed to refresh session cache: " << ex.reason()
- << ", will try again at the next refresh interval";
+ } catch (const DBException& ex) {
+ log() << "Failed to refresh session cache, will try again at the next refresh interval"
+ << causedBy(redact(ex));
return;
}
@@ -365,7 +365,7 @@ LogicalSessionCacheStats LogicalSessionCacheImpl::getStats() {
return _stats;
}
-Status LogicalSessionCacheImpl::_addToCache(WithLock, LogicalSessionRecord record) {
+Status LogicalSessionCacheImpl::_addToCacheIfNotFull(WithLock, LogicalSessionRecord record) {
if (_activeSessions.size() >= size_t(maxSessions)) {
Status status = {ErrorCodes::TooManyLogicalSessions,
str::stream()
diff --git a/src/mongo/db/logical_session_cache_impl.h b/src/mongo/db/logical_session_cache_impl.h
index c92e45fee4a..afea7052761 100644
--- a/src/mongo/db/logical_session_cache_impl.h
+++ b/src/mongo/db/logical_session_cache_impl.h
@@ -71,9 +71,9 @@ public:
Status vivify(OperationContext* opCtx, const LogicalSessionId& lsid) override;
- Status refreshNow(Client* client) override;
+ Status refreshNow(OperationContext* opCtx) override;
- Status reapNow(Client* client) override;
+ void reapNow(OperationContext* opCtx) override;
size_t size() override;
@@ -100,10 +100,7 @@ private:
*/
bool _isDead(const LogicalSessionRecord& record, Date_t now) const;
- /**
- *
- */
- Status _addToCache(WithLock, LogicalSessionRecord record);
+ Status _addToCacheIfNotFull(WithLock, LogicalSessionRecord record);
const std::unique_ptr<ServiceLiaison> _service;
const std::shared_ptr<SessionsCollection> _sessionsColl;
diff --git a/src/mongo/db/logical_session_cache_noop.h b/src/mongo/db/logical_session_cache_noop.h
index 430704a47f0..5d6e12e5f78 100644
--- a/src/mongo/db/logical_session_cache_noop.h
+++ b/src/mongo/db/logical_session_cache_noop.h
@@ -33,10 +33,6 @@
namespace mongo {
-class Client;
-class OperationContext;
-class ServiceContext;
-
/**
* A noop logical session cache for use in tests
*/
@@ -52,13 +48,11 @@ public:
return Status::OK();
}
- Status refreshNow(Client* client) override {
+ Status refreshNow(OperationContext* opCtx) override {
return Status::OK();
}
- Status reapNow(Client* client) override {
- return Status::OK();
- }
+ void reapNow(OperationContext* opCtx) override {}
size_t size() override {
return 0;
diff --git a/src/mongo/db/logical_session_cache_test.cpp b/src/mongo/db/logical_session_cache_test.cpp
index ca23c62e655..b4a301e6b92 100644
--- a/src/mongo/db/logical_session_cache_test.cpp
+++ b/src/mongo/db/logical_session_cache_test.cpp
@@ -77,6 +77,7 @@ public:
Client::releaseCurrent();
Client::initThread(getThreadName());
_opCtx = makeOperationContext();
+
auto mockService = std::make_unique<MockServiceLiaison>(_service);
auto mockSessions = std::make_unique<MockSessionsCollection>(_sessions);
_cache = std::make_unique<LogicalSessionCacheImpl>(
@@ -105,14 +106,6 @@ public:
return _sessions;
}
- void setOpCtx() {
- _opCtx = getClient()->makeOperationContext();
- }
-
- void clearOpCtx() {
- _opCtx.reset();
- }
-
OperationContext* opCtx() {
return _opCtx.get();
}
@@ -168,8 +161,7 @@ TEST_F(LogicalSessionCacheTest, StartSession) {
ASSERT(!sessions()->has(lsid));
// Do refresh, cached records should get flushed to collection.
- clearOpCtx();
- ASSERT(cache()->refreshNow(getClient()).isOK());
+ ASSERT(cache()->refreshNow(opCtx()).isOK());
ASSERT(sessions()->has(lsid));
// Try to start the same session again, should succeed.
@@ -200,7 +192,7 @@ TEST_F(LogicalSessionCacheTest, BasicSessionExpiration) {
service()->fastForward(Milliseconds(kSessionTimeout.count() + 5));
// Check that it is no longer in the cache
- ASSERT_OK(cache()->refreshNow(getClient()));
+ ASSERT_OK(cache()->refreshNow(opCtx()));
ASSERT_EQ(0UL, cache()->size());
}
@@ -219,9 +211,8 @@ TEST_F(LogicalSessionCacheTest, ManySignedLsidsInCacheRefresh) {
});
// Force a refresh
- clearOpCtx();
service()->fastForward(kForceRefresh);
- ASSERT(cache()->refreshNow(getClient()).isOK());
+ ASSERT_OK(cache()->refreshNow(opCtx()));
}
//
@@ -337,9 +328,8 @@ TEST_F(LogicalSessionCacheTest, RefreshMatrixSessionState) {
}
// Force a refresh
- clearOpCtx();
service()->fastForward(kForceRefresh);
- ASSERT(cache()->refreshNow(getClient()).isOK());
+ ASSERT_OK(cache()->refreshNow(opCtx()));
for (int i = 0; i < 32; i++) {
std::stringstream failText;
diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp
index 21e5f55b8f4..98ab79de215 100644
--- a/src/mongo/db/sessions_collection.cpp
+++ b/src/mongo/db/sessions_collection.cpp
@@ -195,9 +195,9 @@ SessionsCollection::FindBatchFn SessionsCollection::makeFindFnForCommand(const N
return send;
}
-void SessionsCollection::doRefresh(const NamespaceString& ns,
- const std::vector<LogicalSessionRecord>& sessions,
- SendBatchFn send) {
+void SessionsCollection::_doRefresh(const NamespaceString& ns,
+ const std::vector<LogicalSessionRecord>& sessions,
+ SendBatchFn send) {
auto init = [ns](BSONObjBuilder* batch) {
batch->append("update", ns.coll());
batch->append("ordered", false);
@@ -213,9 +213,9 @@ void SessionsCollection::doRefresh(const NamespaceString& ns,
runBulkCmd("updates", init, add, send, sessions);
}
-void SessionsCollection::doRemove(const NamespaceString& ns,
- const std::vector<LogicalSessionId>& sessions,
- SendBatchFn send) {
+void SessionsCollection::_doRemove(const NamespaceString& ns,
+ const std::vector<LogicalSessionId>& sessions,
+ SendBatchFn send) {
auto init = [ns](BSONObjBuilder* batch) {
batch->append("delete", ns.coll());
batch->append("ordered", false);
@@ -229,9 +229,8 @@ void SessionsCollection::doRemove(const NamespaceString& ns,
runBulkCmd("deletes", init, add, send, sessions);
}
-LogicalSessionIdSet SessionsCollection::doFindRemoved(const NamespaceString& ns,
- const std::vector<LogicalSessionId>& sessions,
- FindBatchFn send) {
+LogicalSessionIdSet SessionsCollection::_doFindRemoved(
+ const NamespaceString& ns, const std::vector<LogicalSessionId>& sessions, FindBatchFn send) {
auto makeT = [] { return std::vector<LogicalSessionId>{}; };
auto add = [](std::vector<LogicalSessionId>& batch, const LogicalSessionId& record) {
diff --git a/src/mongo/db/sessions_collection.h b/src/mongo/db/sessions_collection.h
index 58230d7a83f..e10b493b332 100644
--- a/src/mongo/db/sessions_collection.h
+++ b/src/mongo/db/sessions_collection.h
@@ -51,7 +51,8 @@ public:
virtual ~SessionsCollection();
/**
- * Ensures that the sessions collection exists and has the proper indexes.
+ * Ensures that the sessions collection exists and has the proper indexes. Implementations of
+ * this method must support multiple concurrent invocations.
*/
virtual void setupSessionsCollection(OperationContext* opCtx) = 0;
@@ -61,8 +62,8 @@ public:
virtual void checkSessionsCollectionExists(OperationContext* opCtx) = 0;
/**
- * Updates the last-use times on the given sessions to be greater than
- * or equal to the given time. Throws an exception if a networking issue occurred.
+ * Updates the last-use times on the given sessions to be greater than or equal to the given
+ * time. Throws an exception if a networking issue occurred.
*/
virtual void refreshSessions(OperationContext* opCtx,
const LogicalSessionRecordSet& sessions) = 0;
@@ -70,15 +71,15 @@ public:
/**
* Removes the authoritative records for the specified sessions.
*
- * Implementations should perform authentication checks to ensure that
- * session records may only be removed if their owner is logged in.
+ * Implementations should perform authentication checks to ensure that session records may only
+ * be removed if their owner is logged in.
*
* Throws an exception if the removal fails, for example from a network error.
*/
virtual void removeRecords(OperationContext* opCtx, const LogicalSessionIdSet& sessions) = 0;
/**
- * Checks a set of lsids and returns the set that no longer exists
+ * Checks a set of lsids and returns the set that no longer exists.
*
* Throws an exception if the fetch cannot occur, for example from a network error.
*/
@@ -98,9 +99,6 @@ public:
protected:
SessionsCollection();
- /**
- * Makes a send function for the given client.
- */
using SendBatchFn = std::function<void(BSONObj batch)>;
static SendBatchFn makeSendFnForCommand(const NamespaceString& ns, DBClientBase* client);
static SendBatchFn makeSendFnForBatchWrite(const NamespaceString& ns, DBClientBase* client);
@@ -111,25 +109,25 @@ protected:
/**
* Formats and sends batches of refreshes for the given set of sessions.
*/
- void doRefresh(const NamespaceString& ns,
- const std::vector<LogicalSessionRecord>& sessions,
- SendBatchFn send);
+ void _doRefresh(const NamespaceString& ns,
+ const std::vector<LogicalSessionRecord>& sessions,
+ SendBatchFn send);
/**
* Formats and sends batches of deletes for the given set of sessions.
*/
- void doRemove(const NamespaceString& ns,
- const std::vector<LogicalSessionId>& sessions,
- SendBatchFn send);
+ void _doRemove(const NamespaceString& ns,
+ const std::vector<LogicalSessionId>& sessions,
+ SendBatchFn send);
/**
* Returns those lsids from the input 'sessions' array which are not present in the sessions
* collection (essentially performs an inner join of 'sessions' against the sessions
* collection).
*/
- LogicalSessionIdSet doFindRemoved(const NamespaceString& ns,
- const std::vector<LogicalSessionId>& sessions,
- FindBatchFn send);
+ LogicalSessionIdSet _doFindRemoved(const NamespaceString& ns,
+ const std::vector<LogicalSessionId>& sessions,
+ FindBatchFn send);
};
} // namespace mongo
diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp
index 6ed8792c8d8..d319d5357fd 100644
--- a/src/mongo/db/sessions_collection_config_server.cpp
+++ b/src/mongo/db/sessions_collection_config_server.cpp
@@ -47,13 +47,13 @@
namespace mongo {
-// Returns an error if the collection didn't exist and we couldn't
-// shard it into existence, either.
void SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext* opCtx) {
// First, check if the collection is already sharded.
- auto res = _checkCacheForSessionsCollection(opCtx);
- if (res.isOK()) {
+ try {
+ checkSessionsCollectionExists(opCtx);
return;
+ } catch (const DBException&) {
+ // If the sessions collection doesn't exist, create it
}
// If we don't have any shards, we can't set up this collection yet.
@@ -83,7 +83,6 @@ void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext*
opCtx,
NamespaceString::kLogicalSessionsNamespace,
SessionsCollection::generateCreateIndexesCmd());
-
} catch (DBException& ex) {
ex.addContext(str::stream()
<< "Failed to generate TTL index for "
@@ -104,8 +103,4 @@ void SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* o
_generateIndexesIfNeeded(opCtx);
}
-void SessionsCollectionConfigServer::checkSessionsCollectionExists(OperationContext* opCtx) {
- uassertStatusOK(_checkCacheForSessionsCollection(opCtx));
-}
-
} // namespace mongo
diff --git a/src/mongo/db/sessions_collection_config_server.h b/src/mongo/db/sessions_collection_config_server.h
index 619d8811f3a..0c5bdbb596e 100644
--- a/src/mongo/db/sessions_collection_config_server.h
+++ b/src/mongo/db/sessions_collection_config_server.h
@@ -46,24 +46,22 @@ class OperationContext;
class SessionsCollectionConfigServer : public SessionsCollectionSharded {
public:
/**
- * Ensures that the sessions collection has been set up for this cluster,
- * sharded, and with the proper indexes.
+ * Ensures that the sessions collection has been set up for this cluster, sharded, and with the
+ * proper indexes.
*
- * This method may safely be called multiple times.
+ * This method may safely be called multiple times and if called concurrently the calls will get
+ * serialised using the mutex below.
*
* If there are no shards in this cluster, this method will do nothing.
*/
void setupSessionsCollection(OperationContext* opCtx) override;
- /**
- * Checks if the sessions collection exists.
- */
- void checkSessionsCollectionExists(OperationContext* opCtx) override;
-
private:
void _shardCollectionIfNeeded(OperationContext* opCtx);
void _generateIndexesIfNeeded(OperationContext* opCtx);
+ // Serialises concurrent calls to setupSessionsCollection so that only one thread performs the
+ // sharded operations
Mutex _mutex = MONGO_MAKE_LATCH("SessionsCollectionConfigServer::_mutex");
};
diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp
index 10c5c06125a..f043e30254a 100644
--- a/src/mongo/db/sessions_collection_rs.cpp
+++ b/src/mongo/db/sessions_collection_rs.cpp
@@ -175,20 +175,21 @@ void SessionsCollectionRS::refreshSessions(OperationContext* opCtx,
const LogicalSessionRecordSet& sessions) {
const std::vector<LogicalSessionRecord> sessionsVector(sessions.begin(), sessions.end());
- _dispatch(
- NamespaceString::kLogicalSessionsNamespace,
- opCtx,
- [&] {
- DBDirectClient client(opCtx);
- doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ _dispatch(NamespaceString::kLogicalSessionsNamespace,
+ opCtx,
+ [&] {
+ DBDirectClient client(opCtx);
+ _doRefresh(
+ NamespaceString::kLogicalSessionsNamespace,
sessionsVector,
makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
- },
- [&](DBClientBase* client) {
- doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ },
+ [&](DBClientBase* client) {
+ _doRefresh(
+ NamespaceString::kLogicalSessionsNamespace,
sessionsVector,
makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, client));
- });
+ });
}
void SessionsCollectionRS::removeRecords(OperationContext* opCtx,
@@ -200,14 +201,14 @@ void SessionsCollectionRS::removeRecords(OperationContext* opCtx,
opCtx,
[&] {
DBDirectClient client(opCtx);
- doRemove(NamespaceString::kLogicalSessionsNamespace,
- sessionsVector,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
+ _doRemove(NamespaceString::kLogicalSessionsNamespace,
+ sessionsVector,
+ makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
},
[&](DBClientBase* client) {
- doRemove(NamespaceString::kLogicalSessionsNamespace,
- sessionsVector,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, client));
+ _doRemove(NamespaceString::kLogicalSessionsNamespace,
+ sessionsVector,
+ makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, client));
});
}
@@ -220,13 +221,13 @@ LogicalSessionIdSet SessionsCollectionRS::findRemovedSessions(OperationContext*
opCtx,
[&] {
DBDirectClient client(opCtx);
- return doFindRemoved(
+ return _doFindRemoved(
NamespaceString::kLogicalSessionsNamespace,
sessionsVector,
makeFindFnForCommand(NamespaceString::kLogicalSessionsNamespace, &client));
},
[&](DBClientBase* client) {
- return doFindRemoved(
+ return _doFindRemoved(
NamespaceString::kLogicalSessionsNamespace,
sessionsVector,
makeFindFnForCommand(NamespaceString::kLogicalSessionsNamespace, client));
diff --git a/src/mongo/db/sessions_collection_sharded.cpp b/src/mongo/db/sessions_collection_sharded.cpp
index 243fc1b3c97..df1bb8c54dd 100644
--- a/src/mongo/db/sessions_collection_sharded.cpp
+++ b/src/mongo/db/sessions_collection_sharded.cpp
@@ -60,27 +60,6 @@ BSONObj lsidQuery(const LogicalSessionId& lsid) {
} // namespace
-Status SessionsCollectionSharded::_checkCacheForSessionsCollection(OperationContext* opCtx) {
- // If the sharding state is not yet initialized, fail.
- if (!Grid::get(opCtx)->isShardingInitialized()) {
- return {ErrorCodes::ShardingStateNotInitialized, "sharding state is not yet initialized"};
- }
-
- // If the collection doesn't exist, fail. Only the config servers generate it.
- auto res = Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
- opCtx, NamespaceString::kLogicalSessionsNamespace);
- if (!res.isOK()) {
- return res.getStatus();
- }
-
- auto routingInfo = res.getValue();
- if (routingInfo.cm()) {
- return Status::OK();
- }
-
- return {ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist"};
-}
-
std::vector<LogicalSessionId> SessionsCollectionSharded::_groupSessionIdsByOwningShard(
OperationContext* opCtx, const LogicalSessionIdSet& sessions) {
auto routingInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(
@@ -140,7 +119,17 @@ void SessionsCollectionSharded::setupSessionsCollection(OperationContext* opCtx)
}
void SessionsCollectionSharded::checkSessionsCollectionExists(OperationContext* opCtx) {
- uassertStatusOK(_checkCacheForSessionsCollection(opCtx));
+ uassert(ErrorCodes::ShardingStateNotInitialized,
+ "sharding state is not yet initialized",
+ Grid::get(opCtx)->isShardingInitialized());
+
+ // If the collection doesn't exist, fail. Only the config servers generate it.
+ const auto routingInfo = uassertStatusOK(
+ Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
+ opCtx, NamespaceString::kLogicalSessionsNamespace));
+
+ uassert(
+ ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist", routingInfo.cm());
}
void SessionsCollectionSharded::refreshSessions(OperationContext* opCtx,
@@ -157,9 +146,9 @@ void SessionsCollectionSharded::refreshSessions(OperationContext* opCtx,
return response.toStatus();
};
- doRefresh(NamespaceString::kLogicalSessionsNamespace,
- _groupSessionRecordsByOwningShard(opCtx, sessions),
- send);
+ _doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ _groupSessionRecordsByOwningShard(opCtx, sessions),
+ send);
}
void SessionsCollectionSharded::removeRecords(OperationContext* opCtx,
@@ -176,9 +165,9 @@ void SessionsCollectionSharded::removeRecords(OperationContext* opCtx,
return response.toStatus();
};
- doRemove(NamespaceString::kLogicalSessionsNamespace,
- _groupSessionIdsByOwningShard(opCtx, sessions),
- send);
+ _doRemove(NamespaceString::kLogicalSessionsNamespace,
+ _groupSessionIdsByOwningShard(opCtx, sessions),
+ send);
}
LogicalSessionIdSet SessionsCollectionSharded::findRemovedSessions(
@@ -214,9 +203,9 @@ LogicalSessionIdSet SessionsCollectionSharded::findRemovedSessions(
return replyBuilder.releaseBody();
};
- return doFindRemoved(NamespaceString::kLogicalSessionsNamespace,
- _groupSessionIdsByOwningShard(opCtx, sessions),
- send);
+ return _doFindRemoved(NamespaceString::kLogicalSessionsNamespace,
+ _groupSessionIdsByOwningShard(opCtx, sessions),
+ send);
}
} // namespace mongo
diff --git a/src/mongo/db/sessions_collection_sharded.h b/src/mongo/db/sessions_collection_sharded.h
index 755034d91b7..c43c1b67fa6 100644
--- a/src/mongo/db/sessions_collection_sharded.h
+++ b/src/mongo/db/sessions_collection_sharded.h
@@ -45,8 +45,9 @@ class OperationContext;
class SessionsCollectionSharded : public SessionsCollection {
public:
/**
- * Ensures that the sessions collection exists, is sharded,
- * and has the proper indexes.
+ * Only ensures that the sessions collection exists, is sharded and has the proper indexes, but
+ * doesn't do any configuration on its own. This is left to the config server's implementation
+ * in SessionsCollectionConfigServer.
*/
void setupSessionsCollection(OperationContext* opCtx) override;
@@ -54,25 +55,16 @@ public:
* Checks if the sessions collection exists. Does not check if the index exists in the sharded
* version of this function.
*/
- virtual void checkSessionsCollectionExists(OperationContext* opCtx) override;
+ void checkSessionsCollectionExists(OperationContext* opCtx) final;
- /**
- * Updates the last-use times on the given sessions to be greater than
- * or equal to the current time.
- */
void refreshSessions(OperationContext* opCtx, const LogicalSessionRecordSet& sessions) override;
- /**
- * Removes the authoritative records for the specified sessions.
- */
void removeRecords(OperationContext* opCtx, const LogicalSessionIdSet& sessions) override;
LogicalSessionIdSet findRemovedSessions(OperationContext* opCtx,
const LogicalSessionIdSet& sessions) override;
-protected:
- Status _checkCacheForSessionsCollection(OperationContext* opCtx);
-
+private:
/**
* These two methods use the sharding routing metadata to do a best effort attempt at grouping
* the specified set of sessions by the shards, which have the records for these sessions. This
diff --git a/src/mongo/db/sessions_collection_standalone.cpp b/src/mongo/db/sessions_collection_standalone.cpp
index 83f83748d2b..3032d521a18 100644
--- a/src/mongo/db/sessions_collection_standalone.cpp
+++ b/src/mongo/db/sessions_collection_standalone.cpp
@@ -99,27 +99,28 @@ void SessionsCollectionStandalone::refreshSessions(OperationContext* opCtx,
const LogicalSessionRecordSet& sessions) {
const std::vector<LogicalSessionRecord> sessionsVector(sessions.begin(), sessions.end());
DBDirectClient client(opCtx);
- doRefresh(NamespaceString::kLogicalSessionsNamespace,
- sessionsVector,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
+ _doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ sessionsVector,
+ makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
}
void SessionsCollectionStandalone::removeRecords(OperationContext* opCtx,
const LogicalSessionIdSet& sessions) {
const std::vector<LogicalSessionId> sessionsVector(sessions.begin(), sessions.end());
DBDirectClient client(opCtx);
- doRemove(NamespaceString::kLogicalSessionsNamespace,
- sessionsVector,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
+ _doRemove(NamespaceString::kLogicalSessionsNamespace,
+ sessionsVector,
+ makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
}
LogicalSessionIdSet SessionsCollectionStandalone::findRemovedSessions(
OperationContext* opCtx, const LogicalSessionIdSet& sessions) {
const std::vector<LogicalSessionId> sessionsVector(sessions.begin(), sessions.end());
DBDirectClient client(opCtx);
- return doFindRemoved(NamespaceString::kLogicalSessionsNamespace,
- sessionsVector,
- makeFindFnForCommand(NamespaceString::kLogicalSessionsNamespace, &client));
+ return _doFindRemoved(
+ NamespaceString::kLogicalSessionsNamespace,
+ sessionsVector,
+ makeFindFnForCommand(NamespaceString::kLogicalSessionsNamespace, &client));
}
} // namespace mongo
diff --git a/src/mongo/s/query/cluster_cursor_manager_test.cpp b/src/mongo/s/query/cluster_cursor_manager_test.cpp
index 43e5b63df3b..9c35dc8034a 100644
--- a/src/mongo/s/query/cluster_cursor_manager_test.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager_test.cpp
@@ -29,21 +29,18 @@
#include "mongo/platform/basic.h"
-#include "mongo/s/query/cluster_cursor_manager.h"
-
#include <memory>
#include <vector>
-#include "mongo/db/logical_session_cache.h"
#include "mongo/db/logical_session_cache_noop.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/s/query/cluster_client_cursor_mock.h"
+#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
namespace mongo {
-
namespace {
using unittest::assertGet;
@@ -111,7 +108,6 @@ protected:
}
void killCursorFromDifferentOpCtx(const NamespaceString& nss, CursorId cursorId) {
-
// Set up another client to kill the cursor.
auto killCursorClient = getServiceContext()->makeClient("killCursorClient");
auto killCursorOpCtx = killCursorClient->makeOperationContext();