summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2022-12-17 22:39:18 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-17 23:43:21 +0000
commit86879bd6bc684703083729f979c43a5788979014 (patch)
tree7ff6b59d84b180d54db6bb0e12ecce117f9be867
parentb953dbf36cba018c98a407d362580ed9ed9b9d23 (diff)
downloadmongo-86879bd6bc684703083729f979c43a5788979014.tar.gz
SERVER-72065 Fix refresh of sessions cache in CSRS secondary nodes
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/sessions_collection_config_server.cpp35
2 files changed, 22 insertions, 14 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index eca1b1a2a0c..90958b0ef0f 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -494,6 +494,7 @@ env.Library(
'sessions_collection_config_server.cpp',
],
LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/db/concurrency/lock_manager',
'$BUILD_DIR/mongo/db/dbdirectclient',
'$BUILD_DIR/mongo/db/pipeline/sharded_agg_helpers',
'$BUILD_DIR/mongo/s/sessions_collection_sharded',
diff --git a/src/mongo/db/s/sessions_collection_config_server.cpp b/src/mongo/db/s/sessions_collection_config_server.cpp
index 7c33603a199..8e5fdd9180a 100644
--- a/src/mongo/db/s/sessions_collection_config_server.cpp
+++ b/src/mongo/db/s/sessions_collection_config_server.cpp
@@ -30,6 +30,8 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kControl
#include "mongo/db/s/sessions_collection_config_server.h"
+#include "mongo/db/concurrency/d_concurrency.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
@@ -115,20 +117,25 @@ void SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* o
static constexpr int64_t kDesiredDocsInChunks = 1000;
static constexpr int64_t kMaxChunkSizeBytes =
kAverageSessionDocSizeBytes * kDesiredDocsInChunks;
- auto filterQuery =
- BSON("_id" << NamespaceString::kLogicalSessionsNamespace.ns()
- << CollectionType::kMaxChunkSizeBytesFieldName << BSON("$exists" << false));
- auto updateQuery = BSON("$set" << BSON(CollectionType::kMaxChunkSizeBytesFieldName
- << kMaxChunkSizeBytes
- << CollectionType::kNoAutoSplitFieldName << true));
-
- uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument(
- opCtx,
- CollectionType::ConfigNS,
- filterQuery,
- updateQuery,
- false,
- ShardingCatalogClient::kMajorityWriteConcern));
+
+ Lock::GlobalLock lock(opCtx, MODE_IX);
+ if (const auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ replCoord->canAcceptWritesFor(opCtx, CollectionType::ConfigNS)) {
+ auto filterQuery =
+ BSON("_id" << NamespaceString::kLogicalSessionsNamespace.ns()
+ << CollectionType::kMaxChunkSizeBytesFieldName << BSON("$exists" << false));
+ auto updateQuery = BSON("$set" << BSON(CollectionType::kMaxChunkSizeBytesFieldName
+ << kMaxChunkSizeBytes
+ << CollectionType::kNoAutoSplitFieldName << true));
+
+ uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument(
+ opCtx,
+ CollectionType::ConfigNS,
+ filterQuery,
+ updateQuery,
+ false,
+ ShardingCatalogClient::kLocalWriteConcern));
+ }
}
} // namespace mongo