summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_session_cache_impl.cpp
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2020-05-17 17:58:09 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-20 01:24:31 +0000
commit35c86a14e2ad2ef8d14fe7ea3ea02951f30e646a (patch)
treeba5d773cadc850b39c086c1ec68ff616a54b90bc /src/mongo/db/logical_session_cache_impl.cpp
parent9299e694984e377bab6924bb9dfdd479c626ad28 (diff)
downloadmongo-35c86a14e2ad2ef8d14fe7ea3ea02951f30e646a.tar.gz
SERVER-40441 Make arbiters not try to setup the sessions collection or check if it exists in LogicalSessionCache refresh/reap thread
Diffstat (limited to 'src/mongo/db/logical_session_cache_impl.cpp')
-rw-r--r--src/mongo/db/logical_session_cache_impl.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp
index 524f910ec1d..1a0e2f0d13e 100644
--- a/src/mongo/db/logical_session_cache_impl.cpp
+++ b/src/mongo/db/logical_session_cache_impl.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/logical_session_id.h"
#include "mongo/db/logical_session_id_helpers.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/logv2/log.h"
@@ -146,6 +147,21 @@ void LogicalSessionCacheImpl::_periodicReap(Client* client) {
}
Status LogicalSessionCacheImpl::_reap(Client* client) {
+ boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
+ auto* const opCtx = [&] {
+ if (client->getOperationContext()) {
+ return client->getOperationContext();
+ }
+
+ uniqueCtx.emplace(client->makeOperationContext());
+ return uniqueCtx->get();
+ }();
+
+ const auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (replCoord && replCoord->getMemberState().arbiter()) {
+ return Status::OK();
+ }
+
// Take the lock to update some stats.
{
stdx::lock_guard<Latch> lk(_mutex);
@@ -159,16 +175,6 @@ Status LogicalSessionCacheImpl::_reap(Client* client) {
_stats.setTransactionReaperJobCount(_stats.getTransactionReaperJobCount() + 1);
}
- boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
- auto* const opCtx = [&] {
- if (client->getOperationContext()) {
- return client->getOperationContext();
- }
-
- uniqueCtx.emplace(client->makeOperationContext());
- return uniqueCtx->get();
- }();
-
int numReaped = 0;
try {
@@ -216,6 +222,22 @@ Status LogicalSessionCacheImpl::_reap(Client* client) {
}
void LogicalSessionCacheImpl::_refresh(Client* client) {
+ // get or make an opCtx
+ boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
+ auto* const opCtx = [&client, &uniqueCtx] {
+ if (client->getOperationContext()) {
+ return client->getOperationContext();
+ }
+
+ uniqueCtx.emplace(client->makeOperationContext());
+ return uniqueCtx->get();
+ }();
+
+ const auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (replCoord && replCoord->getMemberState().arbiter()) {
+ return;
+ }
+
// Stats for serverStatus:
{
stdx::lock_guard<Latch> lk(_mutex);
@@ -238,17 +260,6 @@ void LogicalSessionCacheImpl::_refresh(Client* client) {
_stats.setLastSessionsCollectionJobDurationMillis(millis.count());
});
- // get or make an opCtx
- boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
- auto* const opCtx = [&client, &uniqueCtx] {
- if (client->getOperationContext()) {
- return client->getOperationContext();
- }
-
- uniqueCtx.emplace(client->makeOperationContext());
- return uniqueCtx->get();
- }();
-
ON_BLOCK_EXIT([&opCtx] { clearShardingOperationFailedStatus(opCtx); });
try {