summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorHuayu Ouyang <huayu.ouyang@mongodb.com>2023-05-12 17:22:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-12 19:42:37 +0000
commit44d9b193ab7a2e86b7f63a276f0215d24c3c35d6 (patch)
tree9a4e3ede53d97a41f3ea2e4f32ae485eefe1a4ec /src/mongo/db
parent3524229a9780f5dfbbf2beba978629ac8e908f82 (diff)
downloadmongo-44d9b193ab7a2e86b7f63a276f0215d24c3c35d6.tar.gz
SERVER-75577 Allow specifying FCV on new mongod
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp37
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.idl5
2 files changed, 38 insertions, 4 deletions
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index 9ebad874918..9398afd6b12 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -431,8 +431,14 @@ void FeatureCompatibilityVersion::updateFeatureCompatibilityVersionDocument(
void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
repl::StorageInterface* storageInterface) {
- if (!hasNoReplicatedCollections(opCtx))
+ if (!hasNoReplicatedCollections(opCtx)) {
+ if (!gDefaultStartupFCV.empty()) {
+ LOGV2(7557701,
+ "Ignoring the provided defaultStartupFCV parameter since the FCV already exists");
+ }
return;
+ }
+
// If the server was not started with --shardsvr, the default featureCompatibilityVersion on
// clean startup is the upgrade version. If it was started with --shardsvr, the default
@@ -450,11 +456,34 @@ void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
uassertStatusOK(storageInterface->createCollection(opCtx, nss, options));
}
+ // Set FCV to lastLTS for nodes started with --shardsvr. If an FCV was specified at startup
+ // through a startup parameter, set it to that FCV. Otherwise, set it to latest.
FeatureCompatibilityVersionDocument fcvDoc;
- if (storeUpgradeVersion) {
- fcvDoc.setVersion(GenericFCV::kLatest);
- } else {
+ if (!storeUpgradeVersion) {
fcvDoc.setVersion(GenericFCV::kLastLTS);
+ } else if (!gDefaultStartupFCV.empty()) {
+ StringData versionString = StringData(gDefaultStartupFCV);
+ FCV parsedVersion;
+
+ if (versionString == multiversion::toString(GenericFCV::kLastLTS)) {
+ parsedVersion = GenericFCV::kLastLTS;
+ } else if (versionString == multiversion::toString(GenericFCV::kLastContinuous)) {
+ parsedVersion = GenericFCV::kLastContinuous;
+ } else if (versionString == multiversion::toString(GenericFCV::kLatest)) {
+ parsedVersion = GenericFCV::kLatest;
+ } else {
+ parsedVersion = GenericFCV::kLatest;
+ LOGV2_WARNING_OPTIONS(7557700,
+ {logv2::LogTag::kStartupWarnings},
+ "The provided 'defaultStartupFCV' is not a valid FCV. Setting "
+ "the FCV to the latest FCV instead",
+ "defaultStartupFCV"_attr = versionString,
+ "latestFCV"_attr = multiversion::toString(GenericFCV::kLatest));
+ }
+
+ fcvDoc.setVersion(parsedVersion);
+ } else {
+ fcvDoc.setVersion(GenericFCV::kLatest);
}
// We then insert the featureCompatibilityVersion document into the server configuration
diff --git a/src/mongo/db/commands/feature_compatibility_version.idl b/src/mongo/db/commands/feature_compatibility_version.idl
index 1161730d965..f60cc55eda6 100644
--- a/src/mongo/db/commands/feature_compatibility_version.idl
+++ b/src/mongo/db/commands/feature_compatibility_version.idl
@@ -44,3 +44,8 @@ server_parameters:
cpp_vartype: bool
cpp_varname: gInternalValidateFeaturesAsPrimary
default: true
+ defaultStartupFCV:
+ description: 'Startup parameter to set a default FCV at startup'
+ set_at: startup
+ cpp_vartype: std::string
+ cpp_varname: gDefaultStartupFCV