diff options
Diffstat (limited to 'src/mongo/client')
-rw-r--r-- | src/mongo/client/read_preference.cpp | 4 | ||||
-rw-r--r-- | src/mongo/client/read_preference_test.cpp | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/client/read_preference.cpp b/src/mongo/client/read_preference.cpp index 1676708d6f4..6a55dcf985d 100644 --- a/src/mongo/client/read_preference.cpp +++ b/src/mongo/client/read_preference.cpp @@ -179,6 +179,10 @@ StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSO } } + if (!hedgingMode && mode == ReadPreference::Nearest) { + hedgingMode = HedgingMode(); + } + TagSet tags; BSONElement tagsElem; auto tagExtractStatus = diff --git a/src/mongo/client/read_preference_test.cpp b/src/mongo/client/read_preference_test.cpp index d0a6a1e048c..5352cb203c2 100644 --- a/src/mongo/client/read_preference_test.cpp +++ b/src/mongo/client/read_preference_test.cpp @@ -112,6 +112,15 @@ TEST(ReadPreferenceSetting, ParseHedgingMode) { ASSERT_TRUE(rps.pref == ReadPreference::PrimaryOnly); ASSERT_FALSE(rps.hedgingMode.has_value()); + // Implicit opt-in for readPreference mode "nearest". + rpsObj = BSON("mode" + << "nearest"); + rps = parse(rpsObj); + ASSERT_TRUE(rps.pref == ReadPreference::Nearest); + ASSERT_TRUE(rps.hedgingMode.has_value()); + ASSERT_TRUE(rps.hedgingMode->getEnabled()); + ASSERT_TRUE(rps.hedgingMode->getDelay()); + // Default hedging mode. rpsObj = BSON("mode" << "primaryPreferred" @@ -284,7 +293,7 @@ void checkRoundtrip(const ReadPreferenceSetting& rps) { } TEST(ReadPreferenceSetting, Roundtrip) { - checkRoundtrip(ReadPreferenceSetting(ReadPreference::Nearest, + checkRoundtrip(ReadPreferenceSetting(ReadPreference::SecondaryOnly, TagSet(BSON_ARRAY(BSON("dc" << "ca") << BSON("foo" @@ -299,7 +308,7 @@ TEST(ReadPreferenceSetting, Roundtrip) { << "rack" << "bar"))))); - checkRoundtrip(ReadPreferenceSetting(ReadPreference::Nearest, + checkRoundtrip(ReadPreferenceSetting(ReadPreference::SecondaryPreferred, TagSet(BSON_ARRAY(BSON("dc" << "ca") << BSON("foo" |