summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Andrei <mihai.andrei@10gen.com>2021-05-21 16:46:49 +0300
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-25 17:37:59 +0000
commitabc24b79dbf25d77915e3d8a4a7e8eea5e86992f (patch)
treea821217609e2eb58d4377e988a5b784e87d9a168
parent2dbf533354997a809b73e2c026f3d157fe6e364c (diff)
downloadmongo-abc24b79dbf25d77915e3d8a4a7e8eea5e86992f.tar.gz
SERVER-57117 Verify that 'hedge' option is an object when parsing ReadPreferenceSetting
(cherry picked from commit 9a796a6115c3a6c3dafc3ad0298d54a64e1cda01) (cherry picked from commit b9106a428a9520dfd85a01dc13b817ba2a017454)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/sharding/read_pref_with_hedging_mode.js11
-rw-r--r--src/mongo/client/read_preference.cpp6
3 files changed, 16 insertions, 3 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index d0bfa1396aa..7fdaf197aef 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -131,6 +131,8 @@ all:
test_file: jstests/sharding/time_zone_info_mongos.js
- ticket: SERVER-53760
test_file: jstests/core/sort_spill_estimate_data_size.js
+ - ticket: SERVER-57117
+ test_file: jstests/sharding/read_pref_with_hedging_mode.js
suites:
diff --git a/jstests/sharding/read_pref_with_hedging_mode.js b/jstests/sharding/read_pref_with_hedging_mode.js
index bddadc66594..a33afcd007a 100644
--- a/jstests/sharding/read_pref_with_hedging_mode.js
+++ b/jstests/sharding/read_pref_with_hedging_mode.js
@@ -1,6 +1,6 @@
-/*
- * Intergration test for read preference with hedging mode. The more comprehensive
- * unit test can be found in dbtests/read_preference_test.cpp and s/hedge_options_util_test.cpp.
+/**
+ * Integration test for read preference with hedging mode. The more comprehensive unit test can be
+ * found in dbtests/read_preference_test.cpp and s/hedge_options_util_test.cpp.
*
* TODO (SERVER-45432): test that hedging is performed as expected.
* @tags: [requires_fcv_44]
@@ -22,6 +22,11 @@ assert.commandFailedWithCode(
testDB.runCommand({query: {count: collName}, $readPreference: {mode: "primary", hedge: {}}}),
ErrorCodes.InvalidOptions);
+assert.commandFailedWithCode(
+ testDB.runCommand(
+ {query: {count: collName}, $readPreference: {mode: "secondaryPreferred", hedge: "_1"}}),
+ ErrorCodes.TypeMismatch);
+
// Test "readHedgingMode" server parameter validation.
assert.commandFailedWithCode(st.s.adminCommand({setParameter: 1, readHedgingMode: "invalidMode"}),
ErrorCodes.BadValue);
diff --git a/src/mongo/client/read_preference.cpp b/src/mongo/client/read_preference.cpp
index 3d52248f223..d789e10ff16 100644
--- a/src/mongo/client/read_preference.cpp
+++ b/src/mongo/client/read_preference.cpp
@@ -138,6 +138,12 @@ StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSO
boost::optional<HedgingMode> hedgingMode;
if (auto hedgingModeEl = readPrefObj[kHedgeFieldName]) {
+ if (hedgingModeEl.type() != BSONType::Object) {
+ return Status(ErrorCodes::TypeMismatch,
+ str::stream() << kHedgeFieldName
+ << " field must be of type object if provided; found "
+ << hedgingModeEl);
+ }
hedgingMode = HedgingMode::parse(IDLParserErrorContext(kHedgeFieldName),
hedgingModeEl.embeddedObject());
if (hedgingMode->getEnabled() && mode == ReadPreference::PrimaryOnly) {