summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/multiVersion/internal_validate_features_as_master_upgrade_to_latest.js91
-rw-r--r--jstests/noPassthrough/internal_validate_features_as_primary.js87
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.idl5
-rw-r--r--src/mongo/db/mongod_main.cpp2
-rw-r--r--src/mongo/db/server_options_server_helpers.cpp18
5 files changed, 195 insertions, 8 deletions
diff --git a/jstests/multiVersion/internal_validate_features_as_master_upgrade_to_latest.js b/jstests/multiVersion/internal_validate_features_as_master_upgrade_to_latest.js
new file mode 100644
index 00000000000..d6de3d3fad1
--- /dev/null
+++ b/jstests/multiVersion/internal_validate_features_as_master_upgrade_to_latest.js
@@ -0,0 +1,91 @@
+/**
+ * Tests that setting internalValidateFeaturesOnMaster on 4.4 and then
+ * upgrading to latest does not cause server to crash and that the
+ * original server parameter is still set.
+ */
+(function() {
+"use strict";
+load('./jstests/multiVersion/libs/multi_rs.js'); // Used for upgradeSet.
+
+function runChecksBeforeUpgrade(db, internalValidateFeaturesBool) {
+ // Verify that we can get the internalValidateFeaturesAsMaster parameter on 4.4.
+ let res = db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
+ assert.commandWorked(res);
+ assert.eq(res.internalValidateFeaturesAsMaster, internalValidateFeaturesBool);
+
+ // Verify that we cannot get the internalValidateFeaturesAsPrimary parameter on 4.4.
+ res = db.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
+ assert.commandFailed(res);
+}
+
+function runChecksAfterUpgrade(db, port, internalValidateFeaturesBool) {
+ // Verify that we can still get the internalValidateFeaturesAsMaster parameter on the latest
+ // binary.
+ let res = db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
+ assert.commandWorked(res);
+ assert.eq(res.internalValidateFeaturesAsMaster, internalValidateFeaturesBool);
+
+ // However, trying to use the deprecated internalValidateFeaturesAsMaster parameter results
+ // in a deprecation warning log.
+ const joinShell = startParallelShell(
+ "db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});", port);
+ joinShell();
+ assert(rawMongoProgramOutput().match(
+ "\"Use of deprecated server parameter name\",\"attr\":{\"deprecatedName\":\"internalValidateFeaturesAsMaster\""));
+
+ // Verify that we can also get the internalValidateFeaturesAsPrimary parameter on the latest
+ // binary.
+ res = db.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
+ assert.commandWorked(res);
+ assert.eq(res.internalValidateFeaturesAsPrimary, internalValidateFeaturesBool);
+}
+
+function replicaSetTest() {
+ jsTestLog("Testing on replica set with version last-lts");
+ const nodes = {
+ 0: {binVersion: "4.4"},
+ 1: {binVersion: "4.4"},
+ };
+
+ const rst = new ReplSetTest({nodes: nodes});
+ rst.startSet();
+ rst.initiate();
+ let primary = rst.getPrimary();
+
+ runChecksBeforeUpgrade(primary, true);
+
+ jsTestLog("Upgrading set to latest");
+ rst.upgradeSet({binVersion: "latest"});
+ primary = rst.getPrimary();
+
+ jsTestLog("Testing on replica set with version latest");
+ runChecksAfterUpgrade(primary, primary.port, true);
+
+ rst.stopSet();
+}
+
+function standaloneTest() {
+ jsTestLog("Testing on standalone with version last-lts");
+ let conn = MongoRunner.runMongod(
+ {binVersion: "4.4", setParameter: "internalValidateFeaturesAsMaster=0"});
+ assert.neq(null, conn, "mongod was unable to start up");
+
+ let db = conn.getDB("admin");
+ runChecksBeforeUpgrade(db, false);
+
+ MongoRunner.stopMongod(conn);
+
+ jsTest.log("Testing on standalone with version latest");
+ conn = MongoRunner.runMongod(
+ {binVersion: "latest", setParameter: "internalValidateFeaturesAsMaster=0"});
+ assert.neq(null, conn, "mongod was unable to start up");
+
+ db = conn.getDB("admin");
+ runChecksAfterUpgrade(db, conn.port, false);
+
+ MongoRunner.stopMongod(conn);
+}
+
+replicaSetTest();
+standaloneTest();
+})();
diff --git a/jstests/noPassthrough/internal_validate_features_as_primary.js b/jstests/noPassthrough/internal_validate_features_as_primary.js
new file mode 100644
index 00000000000..5dbc7154e39
--- /dev/null
+++ b/jstests/noPassthrough/internal_validate_features_as_primary.js
@@ -0,0 +1,87 @@
+/**
+ * Tests that the internalValidateFeaturesAsPrimary server parameter
+ * and the deprecated alias internalValidateFeaturesAsMaster both work.
+ * @tags: [requires_fcv_48]
+ */
+(function() {
+"use strict";
+
+// internalValidateFeaturesAsPrimary can be set via startup parameter.
+let conn = MongoRunner.runMongod({setParameter: "internalValidateFeaturesAsPrimary=0"});
+assert.neq(null, conn, "mongod was unable to start up");
+let res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
+assert.commandWorked(res);
+assert.eq(res.internalValidateFeaturesAsPrimary, false);
+
+// Even though we set internalValidateFeaturesAsPrimary, verify that calling
+// getParameter with the deprecated alias internalValidateFeaturesAsMaster works
+// and uses the value we set for internalValidateFeaturesAsPrimary.
+res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
+assert.commandWorked(res);
+assert.eq(res.internalValidateFeaturesAsMaster, false);
+
+// Use of deprecated parameter shows deprecation message.
+let joinShell = startParallelShell(
+ "db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});", conn.port);
+joinShell();
+assert(rawMongoProgramOutput().match(
+ "\"Use of deprecated server parameter name\",\"attr\":{\"deprecatedName\":\"internalValidateFeaturesAsMaster\""));
+MongoRunner.stopMongod(conn);
+
+// internalValidateFeaturesAsMaster can be set via startup parameter.
+conn = MongoRunner.runMongod({setParameter: "internalValidateFeaturesAsMaster=1"});
+assert.neq(null, conn, "mongod was unable to start up");
+res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
+assert.commandWorked(res);
+assert.eq(res.internalValidateFeaturesAsMaster, true);
+
+// Verify that calling getParameter with internalValidateFeaturesAsPrimary
+// uses the value we set for internalValidateFeaturesAsMaster.
+res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
+assert.commandWorked(res);
+assert.eq(res.internalValidateFeaturesAsPrimary, true);
+MongoRunner.stopMongod(conn);
+
+// internalValidateFeaturesAsPrimary cannot be set with --replSet.
+conn = MongoRunner.runMongod(
+ {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"});
+assert.eq(null, conn, "mongod was unexpectedly able to start up");
+
+conn = MongoRunner.runMongod(
+ {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=1"});
+assert.eq(null, conn, "mongod was unexpectedly able to start up");
+
+// Correct error message is logged based on parameter name.
+conn = MongoRunner.runMongod({});
+joinShell = startParallelShell(() => {
+ MongoRunner.runMongod(
+ {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"});
+}, conn.port);
+joinShell();
+let joinShellOutput = rawMongoProgramOutput();
+assert(joinShellOutput.match(
+ "Cannot specify both internalValidateFeaturesAsPrimary and replication.replSet"));
+assert(!joinShellOutput.match(
+ "Cannot specify both internalValidateFeaturesAsMaster and replication.replSet"));
+
+clearRawMongoProgramOutput();
+joinShell = startParallelShell(() => {
+ MongoRunner.runMongod(
+ {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"});
+}, conn.port);
+joinShell();
+joinShellOutput = rawMongoProgramOutput();
+assert(joinShellOutput.match(
+ "Cannot specify both internalValidateFeaturesAsMaster and replication.replSet"));
+assert(!joinShellOutput.match(
+ "Cannot specify both internalValidateFeaturesAsPrimary and replication.replSet"));
+
+MongoRunner.stopMongod(conn);
+
+// internalValidateFeaturesAsPrimary cannot be set via runtime parameter.
+conn = MongoRunner.runMongod({});
+assert.commandFailed(conn.adminCommand({setParameter: 1, internalValidateFeaturesAsPrimary: true}));
+assert.commandFailed(
+ conn.adminCommand({setParameter: 1, internalValidateFeaturesAsPrimary: false}));
+MongoRunner.stopMongod(conn);
+}());
diff --git a/src/mongo/db/commands/feature_compatibility_version.idl b/src/mongo/db/commands/feature_compatibility_version.idl
index ca4ff5652a9..881e7a25f73 100644
--- a/src/mongo/db/commands/feature_compatibility_version.idl
+++ b/src/mongo/db/commands/feature_compatibility_version.idl
@@ -37,11 +37,12 @@ server_parameters:
cpp_class:
name: FeatureCompatibilityVersionParameter
override_ctor: true
- internalValidateFeaturesAsMaster:
+ internalValidateFeaturesAsPrimary:
+ deprecated_name: "internalValidateFeaturesAsMaster"
description: >
Startup parameter to ignore featureCompatibilityVersion checks. This parameter cannot be set if
the node is started with --replSet. This should never be set by end users.
set_at: startup
cpp_vartype: bool
- cpp_varname: gInternalValidateFeaturesAsMaster
+ cpp_varname: gInternalValidateFeaturesAsPrimary
default: true
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index 07629f33788..ba18280bddd 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -679,7 +679,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
startTTLMonitor(serviceContext);
}
- if (replSettings.usingReplSets() || !gInternalValidateFeaturesAsMaster) {
+ if (replSettings.usingReplSets() || !gInternalValidateFeaturesAsPrimary) {
serverGlobalParams.validateFeaturesAsMaster.store(false);
}
}
diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp
index dc58d92985d..641ce12cca6 100644
--- a/src/mongo/db/server_options_server_helpers.cpp
+++ b/src/mongo/db/server_options_server_helpers.cpp
@@ -174,14 +174,22 @@ Status validateServerOptions(const moe::Environment& params) {
haveAuthenticationMechanisms = false;
}
- if (parameters.find("internalValidateFeaturesAsMaster") != parameters.end()) {
- // Command line options that are disallowed when internalValidateFeaturesAsMaster is
- // specified.
+ bool internalValidateFeaturesAsPrimaryUsed =
+ parameters.find("internalValidateFeaturesAsPrimary") != parameters.end();
+ bool internalValidateFeaturesAsMasterUsed =
+ parameters.find("internalValidateFeaturesAsMaster") != parameters.end();
+
+ if (internalValidateFeaturesAsPrimaryUsed || internalValidateFeaturesAsMasterUsed) {
+ // Command line options that are disallowed when internalValidateFeaturesAsPrimary or
+ // internalValidateFeaturesAsMaster, the deprecated alias, is specified.
+ std::string parameterName = internalValidateFeaturesAsPrimaryUsed
+ ? "internalValidateFeaturesAsPrimary"
+ : "internalValidateFeaturesAsMaster";
if (params.count("replication.replSet")) {
return Status(ErrorCodes::BadValue,
str::stream() << //
- "Cannot specify both internalValidateFeaturesAsMaster and "
- "replication.replSet");
+ "Cannot specify both " + parameterName +
+ " and replication.replSet");
}
}
}