diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2020-08-25 21:45:18 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-27 15:40:00 +0000 |
commit | d3fedc03bb3b2037bc4f2266b4cd106377c217b7 (patch) | |
tree | 3e4f498a1ba9fca30effb239fadd55bf3fc675e6 /src | |
parent | 694ed4153b9d5424b5d169fea5c68f99d4dfb45a (diff) | |
download | mongo-d3fedc03bb3b2037bc4f2266b4cd106377c217b7.tar.gz |
SERVER-50264: Better FCV const correctness
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands/feature_compatibility_version.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/fcv_op_observer.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_mongod_test_fixture.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/server_options.h | 31 | ||||
-rw-r--r-- | src/mongo/dbtests/dbtests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/mongos_main.cpp | 2 | ||||
-rw-r--r-- | src/mongo/shell/mongo_main.cpp | 2 | ||||
-rw-r--r-- | src/mongo/unittest/ensure_fcv.h | 4 | ||||
-rw-r--r-- | src/mongo/unittest/unittest.cpp | 4 |
12 files changed, 30 insertions, 27 deletions
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp index d4d57344d22..6c93d22d318 100644 --- a/src/mongo/db/commands/feature_compatibility_version.cpp +++ b/src/mongo/db/commands/feature_compatibility_version.cpp @@ -266,7 +266,7 @@ void FeatureCompatibilityVersion::initializeForStartup(OperationContext* opCtx) } auto version = swVersion.getValue(); - serverGlobalParams.featureCompatibility.setVersion(version); + serverGlobalParams.mutableFeatureCompatibility.setVersion(version); FeatureCompatibilityVersion::updateMinWireVersion(); // On startup, if the version is in an upgrading or downgrading state, print a warning. diff --git a/src/mongo/db/fcv_op_observer.cpp b/src/mongo/db/fcv_op_observer.cpp index 3b75c0a8e97..d5a94048cc5 100644 --- a/src/mongo/db/fcv_op_observer.cpp +++ b/src/mongo/db/fcv_op_observer.cpp @@ -52,7 +52,7 @@ using FeatureCompatibilityParams = ServerGlobalParams::FeatureCompatibility; void FcvOpObserver::_setVersion(OperationContext* opCtx, ServerGlobalParams::FeatureCompatibility::Version newVersion) { - serverGlobalParams.featureCompatibility.setVersion(newVersion); + serverGlobalParams.mutableFeatureCompatibility.setVersion(newVersion); FeatureCompatibilityVersion::updateMinWireVersion(); // (Generic FCV reference): This FCV check should exist across LTS binary versions. diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index 7aa35351c99..d91141560ac 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -632,7 +632,7 @@ void InitialSyncer::_startInitialSyncAttemptCallback( "Resetting feature compatibility version to last-lts. If the sync source is in " "latest feature compatibility version, we will find out when we clone the " "server configuration collection (admin.system.version)"); - serverGlobalParams.featureCompatibility.reset(); + serverGlobalParams.mutableFeatureCompatibility.reset(); // Clear the oplog buffer. _oplogBuffer->clear(makeOpCtx().get()); diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index 0ec082420af..4bf9cebc028 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -4042,7 +4042,7 @@ OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch() { void InitialSyncerTest::doSuccessfulInitialSyncWithOneBatch() { auto lastOp = doInitialSyncWithOneBatch(); - serverGlobalParams.featureCompatibility.reset(); + serverGlobalParams.mutableFeatureCompatibility.reset(); ASSERT_OK(_lastApplied.getStatus()); ASSERT_EQUALS(lastOp.getOpTime(), _lastApplied.getValue().opTime); ASSERT_EQUALS(lastOp.getWallClockTime(), _lastApplied.getValue().wallTime); diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp index 61eec974350..cb390508c6c 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp @@ -128,7 +128,7 @@ void OplogApplierImplTest::setUp() { // test fixture does not create a featureCompatibilityVersion document from which to initialize // the server parameter. // (Generic FCV reference): This FCV reference should exist across LTS binary versions. - serverGlobalParams.featureCompatibility.setVersion( + serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); // This is necessary to generate ghost timestamps for index builds that are not 0, since 0 is an diff --git a/src/mongo/db/s/sharding_mongod_test_fixture.cpp b/src/mongo/db/s/sharding_mongod_test_fixture.cpp index ce0c23c09c6..4b73a742e02 100644 --- a/src/mongo/db/s/sharding_mongod_test_fixture.cpp +++ b/src/mongo/db/s/sharding_mongod_test_fixture.cpp @@ -138,7 +138,7 @@ ShardingMongodTestFixture::ShardingMongodTestFixture() { // Set the highest FCV because otherwise it defaults to the lower FCV. This way we default to // testing this release's code, not backwards compatibility code. // (Generic FCV reference): This FCV reference should exist across LTS binary versions. - serverGlobalParams.featureCompatibility.setVersion( + serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); } diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h index 9cff03225e1..057133d2124 100644 --- a/src/mongo/db/server_options.h +++ b/src/mongo/db/server_options.h @@ -232,15 +232,7 @@ struct ServerGlobalParams { return _version.load(); } - void reset() { - _version.store(Version::kUnsetDefault44Behavior); - } - - void setVersion(Version version) { - return _version.store(version); - } - - bool isLessThanOrEqualTo(Version version, Version* versionReturn = nullptr) { + bool isLessThanOrEqualTo(Version version, Version* versionReturn = nullptr) const { Version currentVersion = getVersion(); if (versionReturn != nullptr) { *versionReturn = currentVersion; @@ -248,7 +240,7 @@ struct ServerGlobalParams { return currentVersion <= version; } - bool isGreaterThanOrEqualTo(Version version, Version* versionReturn = nullptr) { + bool isGreaterThanOrEqualTo(Version version, Version* versionReturn = nullptr) const { Version currentVersion = getVersion(); if (versionReturn != nullptr) { *versionReturn = currentVersion; @@ -256,7 +248,7 @@ struct ServerGlobalParams { return currentVersion >= version; } - bool isLessThan(Version version, Version* versionReturn = nullptr) { + bool isLessThan(Version version, Version* versionReturn = nullptr) const { Version currentVersion = getVersion(); if (versionReturn != nullptr) { *versionReturn = currentVersion; @@ -264,7 +256,7 @@ struct ServerGlobalParams { return currentVersion < version; } - bool isGreaterThan(Version version, Version* versionReturn = nullptr) { + bool isGreaterThan(Version version, Version* versionReturn = nullptr) const { Version currentVersion = getVersion(); if (versionReturn != nullptr) { *versionReturn = currentVersion; @@ -273,17 +265,28 @@ struct ServerGlobalParams { } // This function is to be used for generic FCV references only, and not for FCV-gating. - bool isUpgradingOrDowngrading(boost::optional<Version> version = boost::none) { + bool isUpgradingOrDowngrading(boost::optional<Version> version = boost::none) const { if (version == boost::none) { version = getVersion(); } return version != kLatest && version != kLastContinuous && version != kLastLTS; } + void reset() { + _version.store(Version::kUnsetDefault44Behavior); + } + + void setVersion(Version version) { + return _version.store(version); + } + private: AtomicWord<Version> _version{Version::kUnsetDefault44Behavior}; - } featureCompatibility; + } mutableFeatureCompatibility; + + // Const reference for featureCompatibilityVersion checks. + const FeatureCompatibility& featureCompatibility = mutableFeatureCompatibility; // Feature validation differs depending on the role of a mongod in a replica set. Replica set // primaries can accept user-initiated writes and validate based on the feature compatibility diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index 3661ecdc5ed..0ecc021f82d 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -184,7 +184,7 @@ int dbtestsMain(int argc, char** argv) { mongo::runGlobalInitializersOrDie(std::vector<std::string>(argv, argv + argc)); // (Generic FCV reference): This FCV reference should exist across LTS binary versions. - serverGlobalParams.featureCompatibility.setVersion( + serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); repl::ReplSettings replSettings; replSettings.setOplogSizeBytes(10 * 1024 * 1024); diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp index 28d4e1b79b4..eaaa36b3fa1 100644 --- a/src/mongo/s/mongos_main.cpp +++ b/src/mongo/s/mongos_main.cpp @@ -883,7 +883,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetFeatureCompatibilityVersionLatest, ("EndStartupOptionStorage")) // (Generic FCV reference): This FCV reference should exist across LTS binary versions. (InitializerContext* context) { - serverGlobalParams.featureCompatibility.setVersion( + serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); return Status::OK(); } diff --git a/src/mongo/shell/mongo_main.cpp b/src/mongo/shell/mongo_main.cpp index ecdca584ab1..cb947fc76b1 100644 --- a/src/mongo/shell/mongo_main.cpp +++ b/src/mongo/shell/mongo_main.cpp @@ -118,7 +118,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetFeatureCompatibilityVersionLatest, ("EndStartupOptionSetup")) // (Generic FCV reference): This FCV reference should exist across LTS binary versions. (InitializerContext* context) { - mongo::serverGlobalParams.featureCompatibility.setVersion( + mongo::serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); return Status::OK(); } diff --git a/src/mongo/unittest/ensure_fcv.h b/src/mongo/unittest/ensure_fcv.h index bcba036e417..a0e6e19ed8d 100644 --- a/src/mongo/unittest/ensure_fcv.h +++ b/src/mongo/unittest/ensure_fcv.h @@ -43,10 +43,10 @@ public: using Version = ServerGlobalParams::FeatureCompatibility::Version; EnsureFCV(Version version) : _origVersion(serverGlobalParams.featureCompatibility.getVersion()) { - serverGlobalParams.featureCompatibility.setVersion(version); + serverGlobalParams.mutableFeatureCompatibility.setVersion(version); } ~EnsureFCV() { - serverGlobalParams.featureCompatibility.setVersion(_origVersion); + serverGlobalParams.mutableFeatureCompatibility.setVersion(_origVersion); } private: diff --git a/src/mongo/unittest/unittest.cpp b/src/mongo/unittest/unittest.cpp index 2e8dafe95c3..0d28c50999e 100644 --- a/src/mongo/unittest/unittest.cpp +++ b/src/mongo/unittest/unittest.cpp @@ -156,11 +156,11 @@ namespace { // with a meaningful value will trigger failures as of SERVER-32630. // (Generic FCV reference): This FCV reference should exist across LTS binary versions. void setUpFCV() { - serverGlobalParams.featureCompatibility.setVersion( + serverGlobalParams.mutableFeatureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::kLatest); } void tearDownFCV() { - serverGlobalParams.featureCompatibility.reset(); + serverGlobalParams.mutableFeatureCompatibility.reset(); } struct TestSuiteEnvironment { |