summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp9
-rw-r--r--src/mongo/db/catalog/database_impl.cpp9
-rw-r--r--src/mongo/db/index/index_descriptor.cpp4
-rw-r--r--src/mongo/db/mongod_main.cpp5
-rw-r--r--src/mongo/db/ops/insert.cpp4
-rw-r--r--src/mongo/db/repl/initial_syncer.cpp3
-rw-r--r--src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp8
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp4
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp4
-rw-r--r--src/mongo/db/server_options.h40
-rw-r--r--src/mongo/db/storage/storage_engine_impl.cpp5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp4
-rw-r--r--src/mongo/db/vector_clock.cpp6
-rw-r--r--src/mongo/db/views/view_catalog.cpp9
-rw-r--r--src/mongo/s/mongos_main.cpp5
16 files changed, 78 insertions, 44 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 25d9db7db51..f3c722afee0 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -233,18 +233,17 @@ StatusWith<CollModRequest> parseCollModRequest(OperationContext* opCtx,
continue;
}
} else if (fieldName == "validator" && !isView) {
- // Save this to a variable to avoid reading the atomic variable multiple times.
- const auto currentFCV = serverGlobalParams.featureCompatibility.getVersion();
-
// If the feature compatibility version is not kLatest, and we are validating features
// as master, ban the use of new agg features introduced in kLatest to prevent them from
// being persisted in the catalog.
boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
maxFeatureCompatibilityVersion;
// (Generic FCV reference): This FCV check should exist across LTS binary versions.
+ ServerGlobalParams::FeatureCompatibility::Version fcv;
if (serverGlobalParams.validateFeaturesAsMaster.load() &&
- currentFCV != ServerGlobalParams::FeatureCompatibility::kLatest) {
- maxFeatureCompatibilityVersion = currentFCV;
+ serverGlobalParams.featureCompatibility.isLessThan(
+ ServerGlobalParams::FeatureCompatibility::kLatest, &fcv)) {
+ maxFeatureCompatibilityVersion = fcv;
}
cmr.collValidator = coll->parseValidator(opCtx,
e.Obj().getOwned(),
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 3b61a99f4cf..1bce91141fa 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -864,16 +864,15 @@ Status DatabaseImpl::userCreateNS(OperationContext* opCtx,
boost::intrusive_ptr<ExpressionContext> expCtx(
new ExpressionContext(opCtx, std::move(collator), nss));
- // Save this to a variable to avoid reading the atomic variable multiple times.
- const auto currentFCV = serverGlobalParams.featureCompatibility.getVersion();
-
// If the feature compatibility version is not kLatest, and we are validating features as
// master, ban the use of new agg features introduced in kLatest to prevent them from being
// persisted in the catalog.
// (Generic FCV reference): This FCV check should exist across LTS binary versions.
+ ServerGlobalParams::FeatureCompatibility::Version fcv;
if (serverGlobalParams.validateFeaturesAsMaster.load() &&
- currentFCV != ServerGlobalParams::FeatureCompatibility::kLatest) {
- expCtx->maxFeatureCompatibilityVersion = currentFCV;
+ serverGlobalParams.featureCompatibility.isLessThan(
+ ServerGlobalParams::FeatureCompatibility::kLatest, &fcv)) {
+ expCtx->maxFeatureCompatibilityVersion = fcv;
}
// The match expression parser needs to know that we're parsing an expression for a
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp
index 6dddcf4c0d2..a16478bc4ac 100644
--- a/src/mongo/db/index/index_descriptor.cpp
+++ b/src/mongo/db/index/index_descriptor.cpp
@@ -179,8 +179,8 @@ IndexDescriptor::Comparison IndexDescriptor::compareIndexOptions(
// The partialFilterExpression is only part of the index signature if FCV has been set to 4.6.
// TODO SERVER-47766: remove these FCV checks after we branch for 4.7.
- auto isFCV46 = serverGlobalParams.featureCompatibility.getVersion() ==
- ServerGlobalParams::FeatureCompatibility::Version::kVersion451;
+ auto isFCV46 = serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
+ ServerGlobalParams::FeatureCompatibility::Version::kVersion451);
// If we have a partial filter expression and the other index doesn't, or vice-versa, then the
// two indexes are not equivalent. We therefore return Comparison::kDifferent immediately.
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index 9c3de78b56d..ee2aed80c34 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -1061,7 +1061,10 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
}
// TODO SERVER-49138: Remove this FCV check once we branch for 4.8.
- if (serverGlobalParams.featureCompatibility.isVersion(
+ // We must FCV gate the Quiesce mode feature so that a 4.6 node entering Quiesce mode in a mixed
+ // 4.4/4.6 replica set does not delay a 4.4 node from finding a valid sync source.
+ if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
ServerGlobalParams::FeatureCompatibility::Version::kVersion451)) {
if (auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
replCoord && replCoord->enterQuiesceModeIfSecondary(shutdownTimeout)) {
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index 9333440f060..91a405a18d9 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -174,8 +174,8 @@ StatusWith<BSONObj> fixDocumentForInsert(ServiceContext* service, const BSONObj&
Status userAllowedWriteNS(const NamespaceString& ns) {
// TODO (SERVER-49545): Remove the FCV check after branching for 4.8.
if (ns.isSystemDotProfile() ||
- (ns.isSystemDotViews() &&
- serverGlobalParams.featureCompatibility.isVersion(
+ (ns.isSystemDotViews() && serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
ServerGlobalParams::FeatureCompatibility::Version::kVersion451))) {
return Status(ErrorCodes::InvalidNamespace, str::stream() << "cannot write to " << ns);
}
diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp
index 7fc437c2b6b..ec21186276d 100644
--- a/src/mongo/db/repl/initial_syncer.cpp
+++ b/src/mongo/db/repl/initial_syncer.cpp
@@ -1087,8 +1087,7 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
// Changing the featureCompatibilityVersion during initial sync is unsafe.
// (Generic FCV reference): This FCV check should exist across LTS binary versions.
- if (version > ServerGlobalParams::FeatureCompatibility::kLastLTS &&
- version < ServerGlobalParams::FeatureCompatibility::kLatest) {
+ if (serverGlobalParams.featureCompatibility.isUpgradingOrDowngrading(version)) {
onCompletionGuard->setResultAndCancelRemainingWork_inlock(
lock,
Status(ErrorCodes::IncompatibleServerVersion,
diff --git a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp b/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp
index c1bc9b7ac83..1da6ec13f11 100644
--- a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp
+++ b/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp
@@ -179,7 +179,8 @@ void ReplSetHeartbeatArgsV1::addToBSON(BSONObjBuilder* builder) const {
builder->appendIntOrLL(kTermFieldName, _term);
// TODO SERVER-49382: Remove this FCV check after we branch for 4.7.
- if (serverGlobalParams.featureCompatibility.isVersion(
+ if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
ServerGlobalParams::FeatureCompatibility::Version::kVersion451)) {
builder->append(kPrimaryIdFieldName, _primaryId);
}
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 53fe1169ba0..52908aedbae 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -3173,12 +3173,8 @@ Status ReplicationCoordinatorImpl::processReplSetFreeze(int secs, BSONObjBuilder
}
bool ReplicationCoordinatorImpl::_supportsAutomaticReconfig() const {
- if (serverGlobalParams.featureCompatibility.getVersion() !=
- ServerGlobalParams::FeatureCompatibility::Version::kVersion451) {
- return false;
- }
-
- return true;
+ return serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
+ ServerGlobalParams::FeatureCompatibility::Version::kVersion451);
}
Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCtx,
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
index c4ebaad4ce5..c1365f31ee4 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -302,8 +302,8 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponse(
// binaries to have on-disk repl config with 'newlyAdded' fields.
invariant(
_supportsAutomaticReconfig() ||
- serverGlobalParams.featureCompatibility.getVersion() >
- ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo44);
+ serverGlobalParams.featureCompatibility.isGreaterThan(
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo44));
const auto memId = mem->getId();
auto status = _replExecutor->scheduleWork(
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
index 20b238c4344..fbc5d0c6e51 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
@@ -339,8 +339,8 @@ StatusWith<ShardType> ShardingCatalogManager::_validateHostAsShard(
<< connectionString.toString() << " as a shard");
}
// (Generic FCV reference): This FCV check should exist across LTS binary versions.
- if (serverGlobalParams.featureCompatibility.getVersion() >
- ServerGlobalParams::FeatureCompatibility::kLastLTS) {
+ if (serverGlobalParams.featureCompatibility.isGreaterThan(
+ ServerGlobalParams::FeatureCompatibility::kLastLTS)) {
// If the cluster's FCV is kLatest, or upgrading to / downgrading from, the node being added
// must be a version kLatest binary.
invariant(maxWireVersion == WireVersion::LATEST_WIRE_VERSION);
diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h
index 2b2f88dee47..4d239097d91 100644
--- a/src/mongo/db/server_options.h
+++ b/src/mongo/db/server_options.h
@@ -242,8 +242,44 @@ struct ServerGlobalParams {
return _version.store(version);
}
- bool isVersion(Version version) {
- return _version.load() == version;
+ bool isLessThanOrEqualTo(Version version, Version* versionReturn = nullptr) {
+ Version currentVersion = getVersion();
+ if (versionReturn != nullptr) {
+ *versionReturn = currentVersion;
+ }
+ return currentVersion <= version;
+ }
+
+ bool isGreaterThanOrEqualTo(Version version, Version* versionReturn = nullptr) {
+ Version currentVersion = getVersion();
+ if (versionReturn != nullptr) {
+ *versionReturn = currentVersion;
+ }
+ return currentVersion >= version;
+ }
+
+ bool isLessThan(Version version, Version* versionReturn = nullptr) {
+ Version currentVersion = getVersion();
+ if (versionReturn != nullptr) {
+ *versionReturn = currentVersion;
+ }
+ return currentVersion < version;
+ }
+
+ bool isGreaterThan(Version version, Version* versionReturn = nullptr) {
+ Version currentVersion = getVersion();
+ if (versionReturn != nullptr) {
+ *versionReturn = currentVersion;
+ }
+ return currentVersion > version;
+ }
+
+ // This function is to be used for generic FCV references only, and not for FCV-gating.
+ bool isUpgradingOrDowngrading(boost::optional<Version> version = boost::none) {
+ if (version == boost::none) {
+ version = getVersion();
+ }
+ return version != kLatest && version != kLastContinuous && version != kLastLTS;
}
private:
diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp
index aad57d352e3..d739fb000dc 100644
--- a/src/mongo/db/storage/storage_engine_impl.cpp
+++ b/src/mongo/db/storage/storage_engine_impl.cpp
@@ -927,8 +927,9 @@ bool StorageEngineImpl::supportsOplogStones() const {
bool StorageEngineImpl::supportsResumableIndexBuilds() const {
return enableResumableIndexBuilds && supportsReadConcernMajority() && !isEphemeral() &&
- serverGlobalParams.featureCompatibility.getVersion() ==
- ServerGlobalParams::FeatureCompatibility::Version::kVersion451 &&
+ serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
+ ServerGlobalParams::FeatureCompatibility::Version::kVersion451) &&
!repl::ReplSettings::shouldRecoverFromOplogAsStandalone();
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 3fa21ec4f8d..e027e67162a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -146,8 +146,8 @@ bool WiredTigerFileVersion::shouldDowngrade(bool readOnly,
_startupVersion == StartupVersion::IS_42;
}
- if (serverGlobalParams.featureCompatibility.getVersion() !=
- ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo44) {
+ if (serverGlobalParams.featureCompatibility.isGreaterThan(
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo44)) {
// Only consider downgrading when FCV is set to kFullyDowngraded.
// (This FCV gate must remain across binary version releases.)
return false;
diff --git a/src/mongo/db/vector_clock.cpp b/src/mongo/db/vector_clock.cpp
index 92f060ac16a..b45badf38c3 100644
--- a/src/mongo/db/vector_clock.cpp
+++ b/src/mongo/db/vector_clock.cpp
@@ -160,9 +160,9 @@ public:
BSONObjBuilder* out,
LogicalTime time,
Component component) const override {
- const auto& fcv = serverGlobalParams.featureCompatibility;
- if (fcv.isVersionInitialized() &&
- fcv.getVersion() == ServerGlobalParams::FeatureCompatibility::Version::kVersion451) {
+ if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
+ ServerGlobalParams::FeatureCompatibility::Version::kVersion451)) {
return ActualFormat::out(service, opCtx, permitRefresh, out, time, component);
}
return false;
diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp
index ad05c435d43..ee8e5198b17 100644
--- a/src/mongo/db/views/view_catalog.cpp
+++ b/src/mongo/db/views/view_catalog.cpp
@@ -328,16 +328,15 @@ StatusWith<stdx::unordered_set<NamespaceString>> ViewCatalog::_validatePipeline(
std::move(resolvedNamespaces),
boost::none);
- // Save this to a variable to avoid reading the atomic variable multiple times.
- auto currentFCV = serverGlobalParams.featureCompatibility.getVersion();
-
// If the feature compatibility version is not kLatest, and we are validating features as
// master, ban the use of new agg features introduced in kLatest to prevent them from being
// persisted in the catalog.
// (Generic FCV reference): This FCV check should exist across LTS binary versions.
+ ServerGlobalParams::FeatureCompatibility::Version fcv;
if (serverGlobalParams.validateFeaturesAsMaster.load() &&
- currentFCV != ServerGlobalParams::FeatureCompatibility::kLatest) {
- expCtx->maxFeatureCompatibilityVersion = currentFCV;
+ serverGlobalParams.featureCompatibility.isLessThan(
+ ServerGlobalParams::FeatureCompatibility::kLatest, &fcv)) {
+ expCtx->maxFeatureCompatibilityVersion = fcv;
}
// The pipeline parser needs to know that we're parsing a pipeline for a view definition
diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp
index 234a1a84c53..fcb9b6c0b2e 100644
--- a/src/mongo/s/mongos_main.cpp
+++ b/src/mongo/s/mongos_main.cpp
@@ -289,8 +289,9 @@ void cleanupTask(const ShutdownTaskArgs& shutdownArgs) {
// so that clients can re-route their operations.
//
// TODO SERVER-49138: Remove this FCV check once we branch for 4.8.
- if (serverGlobalParams.featureCompatibility.isVersion(
- ServerGlobalParams::FeatureCompatibility::Version::kVersion451);
+ if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo(
+ ServerGlobalParams::FeatureCompatibility::Version::kVersion451);
auto mongosTopCoord = MongosTopologyCoordinator::get(opCtx)) {
mongosTopCoord->enterQuiesceModeAndWait(opCtx, quiesceTime);
}