summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/replsets/reconfig_uses_default_protocolVersion.js23
-rw-r--r--src/mongo/db/repl/repl_set_config.cpp4
3 files changed, 27 insertions, 2 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index a2a6482b612..e47013f3459 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -53,6 +53,8 @@ replica_sets_multiversion:
test_file: jstests/replsets/trigger_initial_stable_checkpoint.js
- ticket: SERVER-45178
test_file: jstests/replsets/rollback_via_refetch_update_rollback_id_before_oplog_truncation.js
+- ticket: SERVER-45143
+ test_file: jstests/replsets/reconfig_uses_default_protocolVersion.js
sharding_multiversion:
- ticket: SERVER-38691
diff --git a/jstests/replsets/reconfig_uses_default_protocolVersion.js b/jstests/replsets/reconfig_uses_default_protocolVersion.js
new file mode 100644
index 00000000000..706872b9522
--- /dev/null
+++ b/jstests/replsets/reconfig_uses_default_protocolVersion.js
@@ -0,0 +1,23 @@
+/**
+ * Test that protocolVersion defaults to 1 even during a replSetReconfig.
+ */
+(function() {
+"use strict";
+
+var rst = new ReplSetTest({nodes: 2});
+rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+var config = primary.getDB("local").system.replset.findOne();
+config.version++;
+delete config.protocolVersion;
+
+assert.commandWorked(primary.adminCommand({replSetReconfig: config}));
+
+// Make sure that the config still has the proper protocolVersion.
+config = primary.getDB("local").system.replset.findOne();
+assert.eq(config.protocolVersion, 1);
+
+rst.stopSet();
+})(); \ No newline at end of file
diff --git a/src/mongo/db/repl/repl_set_config.cpp b/src/mongo/db/repl/repl_set_config.cpp
index db794713203..4fa689c7b11 100644
--- a/src/mongo/db/repl/repl_set_config.cpp
+++ b/src/mongo/db/repl/repl_set_config.cpp
@@ -167,8 +167,8 @@ Status ReplSetConfig::_initialize(const BSONObj& cfg, bool forInitiate, OID defa
// Parse protocol version
//
status = bsonExtractIntegerField(cfg, kProtocolVersionFieldName, &_protocolVersion);
- // If 'protocolVersion' field is missing for initiate, then _protocolVersion defaults to 1.
- if (!(status.isOK() || (status == ErrorCodes::NoSuchKey && forInitiate))) {
+ // If 'protocolVersion' field is missing, then _protocolVersion defaults to 1.
+ if (!status.isOK() && status != ErrorCodes::NoSuchKey) {
return status;
}