summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2020-01-25 02:54:56 +0000
committerevergreen <evergreen@mongodb.com>2020-01-25 02:54:56 +0000
commite9aff0aa463d8a85a27e2ca254a6175eb23f2bf8 (patch)
tree785dec273f96842a239c470ab6c5d861b9da02f9 /src/mongo/client
parent93e3b247c1c63dac5cd6758a932b8443f046a1b7 (diff)
downloadmongo-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.cpp4
-rw-r--r--src/mongo/client/read_preference_test.cpp13
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"