diff options
author | Cheahuychou Mao <cheahuychou.mao@mongodb.com> | 2020-01-25 02:54:56 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-25 02:54:56 +0000 |
commit | e9aff0aa463d8a85a27e2ca254a6175eb23f2bf8 (patch) | |
tree | 785dec273f96842a239c470ab6c5d861b9da02f9 /src/mongo/client | |
parent | 93e3b247c1c63dac5cd6758a932b8443f046a1b7 (diff) | |
download | mongo-e9aff0aa463d8a85a27e2ca254a6175eb23f2bf8.tar.gz |
SERVER-45440 Add support for implicit operation hedging when using readPreference mode nearest
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" |