summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2022-12-14 08:32:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-14 09:02:34 +0000
commit43c5e7d26928b45ed4b44d81ed33e46682db58b2 (patch)
tree99bd220828dbef3b6576c3ad8cf28e7f25940efe /src/mongo/db/s
parentc4478b804977b5821911ad2ca7d6227a3f84ba8b (diff)
downloadmongo-43c5e7d26928b45ed4b44d81ed33e46682db58b2.tar.gz
SERVER-72065 Fix refresh of sessions cache in CSRS secondary nodes
Diffstat (limited to 'src/mongo/db/s')
-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 f2e6e4e4e84..6bf33492fad 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -598,6 +598,7 @@ env.Library(
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/dbdirectclient',
'$BUILD_DIR/mongo/db/pipeline/sharded_agg_helpers',
+ '$BUILD_DIR/mongo/db/shard_role',
'$BUILD_DIR/mongo/s/sessions_collection_sharded',
'$BUILD_DIR/mongo/s/sharding_api',
],
diff --git a/src/mongo/db/s/sessions_collection_config_server.cpp b/src/mongo/db/s/sessions_collection_config_server.cpp
index 1f5e5353a62..2e4d040f2d4 100644
--- a/src/mongo/db/s/sessions_collection_config_server.cpp
+++ b/src/mongo/db/s/sessions_collection_config_server.cpp
@@ -28,6 +28,8 @@
*/
#include "mongo/db/s/sessions_collection_config_server.h"
+#include "mongo/db/catalog_raii.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/logv2/log.h"
#include "mongo/s/chunk_constraints.h"
@@ -118,20 +120,25 @@ void SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* o
_shardCollectionIfNeeded(opCtx);
_generateIndexesIfNeeded(opCtx);
- auto filterQuery =
- BSON("_id" << NamespaceString::kLogicalSessionsNamespace.ns()
- << CollectionType::kMaxChunkSizeBytesFieldName << BSON("$exists" << false));
- auto updateQuery = BSON("$set" << BSON(CollectionType::kMaxChunkSizeBytesFieldName
- << logical_sessions::kMaxChunkSizeBytes
- << CollectionType::kNoAutoSplitFieldName << true));
-
- uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument(
- opCtx,
- CollectionType::ConfigNS,
- filterQuery,
- updateQuery,
- false,
- ShardingCatalogClient::kMajorityWriteConcern));
+
+ AutoGetCollection autoColl(opCtx, NamespaceString::kLogicalSessionsNamespace, MODE_IS);
+ if (const auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ replCoord->canAcceptWritesFor(opCtx, NamespaceString::kLogicalSessionsNamespace)) {
+ auto filterQuery =
+ BSON("_id" << NamespaceString::kLogicalSessionsNamespace.ns()
+ << CollectionType::kMaxChunkSizeBytesFieldName << BSON("$exists" << false));
+ auto updateQuery = BSON("$set" << BSON(CollectionType::kMaxChunkSizeBytesFieldName
+ << logical_sessions::kMaxChunkSizeBytes
+ << CollectionType::kNoAutoSplitFieldName << true));
+
+ uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument(
+ opCtx,
+ CollectionType::ConfigNS,
+ filterQuery,
+ updateQuery,
+ false,
+ ShardingCatalogClient::kLocalWriteConcern));
+ }
}
} // namespace mongo