diff options
Diffstat (limited to 'src/mongo/db/s/sessions_collection_config_server.cpp')
| -rw-r--r-- | src/mongo/db/s/sessions_collection_config_server.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/mongo/db/s/sessions_collection_config_server.cpp b/src/mongo/db/s/sessions_collection_config_server.cpp index 48374167b41..4cc60077aec 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" @@ -96,8 +98,10 @@ void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* SessionsCollection::generateCreateIndexesCmd(), ReadPreferenceSetting(ReadPreference::PrimaryOnly), Shard::RetryPolicy::kNoRetry, - BSONObj() /* query */, - BSONObj() /* collation */); + BSONObj() /*query*/, + BSONObj() /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); }); } @@ -111,6 +115,29 @@ void SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* o _shardCollectionIfNeeded(opCtx); _generateIndexesIfNeeded(opCtx); + static constexpr int64_t kAverageSessionDocSizeBytes = 200; + static constexpr int64_t kDesiredDocsInChunks = 1000; + static constexpr int64_t kMaxChunkSizeBytes = + kAverageSessionDocSizeBytes * kDesiredDocsInChunks; + + 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 |
