summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/client/fetcher.h2
-rw-r--r--src/mongo/client/read_preference.cpp7
-rw-r--r--src/mongo/client/read_preference.h16
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp6
-rw-r--r--src/mongo/db/repl/database_cloner.cpp2
-rw-r--r--src/mongo/db/repl/databases_cloner.cpp2
-rw-r--r--src/mongo/db/repl/initial_syncer.cpp2
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp20
-rw-r--r--src/mongo/db/repl/oplog_fetcher_test.cpp4
-rw-r--r--src/mongo/db/repl/rollback_common_point_resolver.cpp2
-rw-r--r--src/mongo/db/repl/sync_source_resolver.cpp4
-rw-r--r--src/mongo/s/balancer_configuration_test.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_add_shard_test.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_append_db_stats_test.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_remove_shard_test.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_shard_collection_test.cpp4
-rw-r--r--src/mongo/s/catalog/sharding_catalog_test.cpp16
-rw-r--r--src/mongo/s/client/shard_remote.cpp7
-rw-r--r--src/mongo/s/cluster_identity_loader_test.cpp2
19 files changed, 56 insertions, 48 deletions
diff --git a/src/mongo/client/fetcher.h b/src/mongo/client/fetcher.h
index 050ac50f249..af4e79d9ce0 100644
--- a/src/mongo/client/fetcher.h
+++ b/src/mongo/client/fetcher.h
@@ -129,7 +129,7 @@ public:
const std::string& dbname,
const BSONObj& cmdObj,
const CallbackFn& work,
- const BSONObj& metadata = rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ const BSONObj& metadata = ReadPreferenceSetting::secondaryPreferredMetadata(),
Milliseconds timeout = RemoteCommandRequest::kNoTimeout,
std::unique_ptr<RemoteCommandRetryScheduler::RetryPolicy> firstCommandRetryPolicy =
RemoteCommandRetryScheduler::makeNoRetryPolicy());
diff --git a/src/mongo/client/read_preference.cpp b/src/mongo/client/read_preference.cpp
index e54a85357c5..acdd83c1771 100644
--- a/src/mongo/client/read_preference.cpp
+++ b/src/mongo/client/read_preference.cpp
@@ -119,6 +119,13 @@ TagSet defaultTagSetForMode(ReadPreference mode) {
*/
const Seconds ReadPreferenceSetting::kMinimalMaxStalenessValue(90);
+const BSONObj& ReadPreferenceSetting::secondaryPreferredMetadata() {
+ // This is a static method rather than a static member only because it is used by another TU
+ // during dynamic init.
+ static const auto bson = BSON("$ssm" << BSON("$secondaryOk" << true));
+ return bson;
+}
+
TagSet::TagSet() : _tags(BSON_ARRAY(BSONObj())) {}
TagSet TagSet::primaryOnly() {
diff --git a/src/mongo/client/read_preference.h b/src/mongo/client/read_preference.h
index 0e80e872970..35ef1c9067b 100644
--- a/src/mongo/client/read_preference.h
+++ b/src/mongo/client/read_preference.h
@@ -116,6 +116,17 @@ private:
struct ReadPreferenceSetting {
/**
+ * The minimal value maxStalenessSeconds can have.
+ */
+ static const Seconds kMinimalMaxStalenessValue;
+
+ /**
+ * An object representing the metadata generated for a SecondaryPreferred read preference:
+ * {$ssm: {$secondaryOk: true}}
+ */
+ static const BSONObj& secondaryPreferredMetadata();
+
+ /**
* @param pref the read preference mode.
* @param tag the tag set. Note that this object will have the
* tag set will have this in a reset state (meaning, this
@@ -156,11 +167,6 @@ struct ReadPreferenceSetting {
TagSet tags;
Seconds maxStalenessSeconds{};
repl::OpTime minOpTime{};
-
- /**
- * The minimal value maxStalenessSeconds can have.
- */
- static const Seconds kMinimalMaxStalenessValue;
};
} // namespace mongo
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp
index 72fc777ff08..67ba31592fc 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -95,7 +95,7 @@ CollectionCloner::CollectionCloner(executor::TaskExecutor* executor,
RemoteCommandRequest(_source,
_sourceNss.db().toString(),
BSON("count" << _sourceNss.coll()),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
nullptr,
RemoteCommandRequest::kNoTimeout),
stdx::bind(&CollectionCloner::_countCallback, this, stdx::placeholders::_1),
@@ -112,7 +112,7 @@ CollectionCloner::CollectionCloner(executor::TaskExecutor* executor,
stdx::placeholders::_1,
stdx::placeholders::_2,
stdx::placeholders::_3),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
RemoteCommandRequest::kNoTimeout,
RemoteCommandRetryScheduler::makeRetryPolicy(
numInitialSyncListIndexesAttempts.load(),
@@ -488,7 +488,7 @@ void CollectionCloner::_beginCollectionCallback(const executor::TaskExecutor::Ca
stdx::placeholders::_2,
stdx::placeholders::_3,
onCompletionGuard),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
RemoteCommandRequest::kNoTimeout,
RemoteCommandRetryScheduler::makeRetryPolicy(
numInitialSyncCollectionFindAttempts.load(),
diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp
index 649d6d8efa3..9015b723dec 100644
--- a/src/mongo/db/repl/database_cloner.cpp
+++ b/src/mongo/db/repl/database_cloner.cpp
@@ -115,7 +115,7 @@ DatabaseCloner::DatabaseCloner(executor::TaskExecutor* executor,
stdx::placeholders::_1,
stdx::placeholders::_2,
stdx::placeholders::_3),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
RemoteCommandRequest::kNoTimeout,
RemoteCommandRetryScheduler::makeRetryPolicy(
numInitialSyncListCollectionsAttempts.load(),
diff --git a/src/mongo/db/repl/databases_cloner.cpp b/src/mongo/db/repl/databases_cloner.cpp
index ff0c9170e15..4e423aeb77b 100644
--- a/src/mongo/db/repl/databases_cloner.cpp
+++ b/src/mongo/db/repl/databases_cloner.cpp
@@ -204,7 +204,7 @@ Status DatabasesCloner::startup() noexcept {
Request listDBsReq(_source,
"admin",
BSON("listDatabases" << true),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
nullptr);
_listDBsScheduler = stdx::make_unique<RemoteCommandRetryScheduler>(
_exec,
diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp
index 5193be72264..b200804dda1 100644
--- a/src/mongo/db/repl/initial_syncer.cpp
+++ b/src/mongo/db/repl/initial_syncer.cpp
@@ -1165,7 +1165,7 @@ Status InitialSyncer::_scheduleLastOplogEntryFetcher_inlock(Fetcher::CallbackFn
_opts.remoteOplogNS.db().toString(),
query,
callback,
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
RemoteCommandRequest::kNoTimeout,
RemoteCommandRetryScheduler::makeRetryPolicy(
numInitialSyncOplogFindAttempts.load(),
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index 54b572b3e68..071d401bca2 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -98,15 +98,15 @@ BSONObj makeGetMoreCommandObject(const NamespaceString& nss,
/**
* Returns command metadata object suitable for tailing remote oplog.
*/
-StatusWith<BSONObj> makeMetadataObject(bool isV1ElectionProtocol) {
- return isV1ElectionProtocol
- ? BSON(rpc::kReplSetMetadataFieldName
- << 1
- << rpc::kOplogQueryMetadataFieldName
- << 1
- << rpc::ServerSelectionMetadata::fieldName()
- << BSON(rpc::ServerSelectionMetadata::kSecondaryOkFieldName << true))
- : rpc::ServerSelectionMetadata(true, boost::none).toBSON();
+BSONObj makeMetadataObject(bool isV1ElectionProtocol) {
+ if (!isV1ElectionProtocol)
+ return ReadPreferenceSetting::secondaryPreferredMetadata();
+
+ BSONObjBuilder metaBuilder;
+ metaBuilder << rpc::kReplSetMetadataFieldName << 1;
+ metaBuilder << rpc::kOplogQueryMetadataFieldName << 1;
+ metaBuilder.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
+ return metaBuilder.obj();
}
/**
@@ -320,7 +320,7 @@ OplogFetcher::OplogFetcher(executor::TaskExecutor* executor,
maxFetcherRestarts,
onShutdownCallbackFn,
"oplog fetcher"),
- _metadataObject(uassertStatusOK(makeMetadataObject(config.getProtocolVersion() == 1LL))),
+ _metadataObject(makeMetadataObject(config.getProtocolVersion() == 1LL)),
_requiredRBID(requiredRBID),
_requireFresherSyncSource(requireFresherSyncSource),
_dataReplicatorExternalState(dataReplicatorExternalState),
diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp
index af4e74f99a3..ee4cf02f5fc 100644
--- a/src/mongo/db/repl/oplog_fetcher_test.cpp
+++ b/src/mongo/db/repl/oplog_fetcher_test.cpp
@@ -279,9 +279,7 @@ TEST_F(OplogFetcherTest, MetadataObjectIsEmptyUnderProtocolVersion0) {
enqueueDocumentsFn,
[](Status) {})
.getMetadataObject_forTest();
- ASSERT_BSONOBJ_EQ(BSON(rpc::ServerSelectionMetadata::fieldName()
- << BSON(rpc::ServerSelectionMetadata::kSecondaryOkFieldName << 1)),
- metadataObj);
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(), metadataObj);
}
TEST_F(OplogFetcherTest, AwaitDataTimeoutShouldEqualHalfElectionTimeoutUnderProtocolVersion1) {
diff --git a/src/mongo/db/repl/rollback_common_point_resolver.cpp b/src/mongo/db/repl/rollback_common_point_resolver.cpp
index 747818e6a9a..258fe3c9a24 100644
--- a/src/mongo/db/repl/rollback_common_point_resolver.cpp
+++ b/src/mongo/db/repl/rollback_common_point_resolver.cpp
@@ -96,7 +96,7 @@ RollbackCommonPointResolver::RollbackCommonPointResolver(executor::TaskExecutor*
maxFetcherRestarts,
onShutdownCallbackFn,
"rollback common point resolver"),
- _metadataObject(rpc::ServerSelectionMetadata(true, boost::none).toBSON()),
+ _metadataObject(ReadPreferenceSetting::secondaryPreferredMetadata()),
_localOplog(localOplog),
_listener(listener) {
diff --git a/src/mongo/db/repl/sync_source_resolver.cpp b/src/mongo/db/repl/sync_source_resolver.cpp
index d14be44f6fe..6589660709e 100644
--- a/src/mongo/db/repl/sync_source_resolver.cpp
+++ b/src/mongo/db/repl/sync_source_resolver.cpp
@@ -174,7 +174,7 @@ std::unique_ptr<Fetcher> SyncSourceResolver::_makeFirstOplogEntryFetcher(
stdx::placeholders::_1,
candidate,
earliestOpTimeSeen),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
kFetcherTimeout);
}
@@ -194,7 +194,7 @@ std::unique_ptr<Fetcher> SyncSourceResolver::_makeRequiredOpTimeFetcher(HostAndP
stdx::placeholders::_1,
candidate,
earliestOpTimeSeen),
- rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ReadPreferenceSetting::secondaryPreferredMetadata(),
kFetcherTimeout);
}
diff --git a/src/mongo/s/balancer_configuration_test.cpp b/src/mongo/s/balancer_configuration_test.cpp
index 72a3b8da06d..9afd5bfaa1d 100644
--- a/src/mongo/s/balancer_configuration_test.cpp
+++ b/src/mongo/s/balancer_configuration_test.cpp
@@ -54,7 +54,7 @@ using unittest::assertGet;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
diff --git a/src/mongo/s/catalog/sharding_catalog_add_shard_test.cpp b/src/mongo/s/catalog/sharding_catalog_add_shard_test.cpp
index a3fee100fd6..d983a489461 100644
--- a/src/mongo/s/catalog/sharding_catalog_add_shard_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_add_shard_test.cpp
@@ -70,7 +70,7 @@ using unittest::assertGet;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
diff --git a/src/mongo/s/catalog/sharding_catalog_append_db_stats_test.cpp b/src/mongo/s/catalog/sharding_catalog_append_db_stats_test.cpp
index 5e2259b56fb..3f6a2782c98 100644
--- a/src/mongo/s/catalog/sharding_catalog_append_db_stats_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_append_db_stats_test.cpp
@@ -53,7 +53,7 @@ using ShardingCatalogClientAppendDbStatsTest = ShardingCatalogTestFixture;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
diff --git a/src/mongo/s/catalog/sharding_catalog_remove_shard_test.cpp b/src/mongo/s/catalog/sharding_catalog_remove_shard_test.cpp
index b9b8285ce33..fa3d295dce4 100644
--- a/src/mongo/s/catalog/sharding_catalog_remove_shard_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_remove_shard_test.cpp
@@ -67,7 +67,7 @@ static const Seconds kFutureTimeout{5};
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
diff --git a/src/mongo/s/catalog/sharding_catalog_shard_collection_test.cpp b/src/mongo/s/catalog/sharding_catalog_shard_collection_test.cpp
index f60ead6821e..86b6bfe755c 100644
--- a/src/mongo/s/catalog/sharding_catalog_shard_collection_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_shard_collection_test.cpp
@@ -75,7 +75,7 @@ using unittest::assertGet;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
@@ -739,7 +739,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
ASSERT_EQUALS(0, request.cmdObj["maxSplitPoints"].numberLong());
ASSERT_EQUALS(0, request.cmdObj["maxChunkObjects"].numberLong());
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "splitKeys"
diff --git a/src/mongo/s/catalog/sharding_catalog_test.cpp b/src/mongo/s/catalog/sharding_catalog_test.cpp
index 7b21c2429f4..fba69fe6445 100644
--- a/src/mongo/s/catalog/sharding_catalog_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_test.cpp
@@ -79,7 +79,7 @@ const int kMaxCommandRetry = 3;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};
@@ -1492,7 +1492,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseSuccess) {
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 10);
@@ -1506,7 +1506,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseSuccess) {
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 1);
@@ -1519,7 +1519,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseSuccess) {
string cmdName = request.cmdObj.firstElement().fieldName();
ASSERT_EQUALS("listDatabases", cmdName);
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 100);
@@ -1774,7 +1774,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseDuplicateKeyOnInsert) {
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 10);
@@ -1788,7 +1788,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseDuplicateKeyOnInsert) {
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 1);
@@ -1802,7 +1802,7 @@ TEST_F(ShardingCatalogClientTest, createDatabaseDuplicateKeyOnInsert) {
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return BSON("ok" << 1 << "totalSize" << 100);
@@ -1900,7 +1900,7 @@ TEST_F(ShardingCatalogClientTest, EnableShardingNoDBExists) {
ASSERT_EQ("admin", request.dbname);
ASSERT_BSONOBJ_EQ(BSON("listDatabases" << 1), request.cmdObj);
- ASSERT_BSONOBJ_EQ(rpc::ServerSelectionMetadata(true, boost::none).toBSON(),
+ ASSERT_BSONOBJ_EQ(ReadPreferenceSetting::secondaryPreferredMetadata(),
rpc::TrackingMetadata::removeTrackingData(request.metadata));
return fromjson(R"({
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index 4224df96267..3d0f2570d4e 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -69,9 +69,6 @@ namespace {
// response.
const BSONObj kReplMetadata(BSON(rpc::kReplSetMetadataFieldName << 1));
-// Allow the command to be executed on a secondary (see ServerSelectionMetadata).
-const BSONObj kSecondaryOkMetadata{rpc::ServerSelectionMetadata(true, boost::none).toBSON()};
-
/**
* Returns a new BSONObj describing the same command and arguments as 'cmdObj', but with maxTimeMS
* replaced by maxTimeMSOverride (or removed if maxTimeMSOverride is Milliseconds::max()).
@@ -164,12 +161,12 @@ BSONObj ShardRemote::_appendMetadataForCommand(OperationContext* opCtx,
if (readPref.pref == ReadPreference::PrimaryOnly) {
builder.appendElements(kReplMetadata);
} else {
- builder.appendElements(kSecondaryOkMetadata);
+ builder.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
builder.appendElements(kReplMetadata);
}
} else {
if (readPref.pref != ReadPreference::PrimaryOnly) {
- builder.appendElements(kSecondaryOkMetadata);
+ builder.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
}
}
return builder.obj();
diff --git a/src/mongo/s/cluster_identity_loader_test.cpp b/src/mongo/s/cluster_identity_loader_test.cpp
index fd9c0f474e2..8c1af517e89 100644
--- a/src/mongo/s/cluster_identity_loader_test.cpp
+++ b/src/mongo/s/cluster_identity_loader_test.cpp
@@ -61,7 +61,7 @@ using unittest::assertGet;
const BSONObj kReplSecondaryOkMetadata{[] {
BSONObjBuilder o;
- o.appendElements(rpc::ServerSelectionMetadata(true, boost::none).toBSON());
+ o.appendElements(ReadPreferenceSetting::secondaryPreferredMetadata());
o.append(rpc::kReplSetMetadataFieldName, 1);
return o.obj();
}()};