summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildscripts/linter/simplecpplint.py34
-rw-r--r--src/mongo/db/fcv_op_observer.cpp1
-rw-r--r--src/mongo/db/repl/initial_syncer_test.cpp5
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp3
-rw-r--r--src/mongo/db/startup_recovery.cpp2
5 files changed, 45 insertions, 0 deletions
diff --git a/buildscripts/linter/simplecpplint.py b/buildscripts/linter/simplecpplint.py
index cf4df8e4b47..5ca79216de0 100644
--- a/buildscripts/linter/simplecpplint.py
+++ b/buildscripts/linter/simplecpplint.py
@@ -2,6 +2,7 @@
"""Simple C++ Linter."""
import argparse
+import bisect
import io
import logging
import re
@@ -58,6 +59,19 @@ _RE_MUTEX = re.compile('[ ({,]stdx?::mutex[ ({]')
_RE_ASSERT = re.compile(r'\bassert\s*\(')
_RE_UNSTRUCTURED_LOG = re.compile(r'\blogd\s*\(')
+_RE_GENERIC_FCV_COMMENT = re.compile(r'\(Generic FCV reference\):')
+GENERIC_FCV = [
+ r'::kLatest',
+ r'::kLastContinuous',
+ r'::kLastLTS',
+ r'::kUpgradingFromLastLTSToLatest',
+ r'::kUpgradingFromLastContinuousToLatest',
+ r'::kDowngradingFromLatestToLastLTS',
+ r'::kDowngradingFromLatestToLastContinuous',
+ r'\.isUpgradingOrDowngrading',
+]
+_RE_GENERIC_FCV_REF = re.compile(r'(' + '|'.join(GENERIC_FCV) + r')\b')
+
class Linter:
"""Simple C++ Linter."""
@@ -68,6 +82,7 @@ class Linter:
self.raw_lines = raw_lines
self.clean_lines = []
self.nolint_supression = []
+ self.generic_fcv_comments = []
self._error_count = 0
self.found_config_header = False
@@ -110,6 +125,11 @@ class Linter:
self._check_for_mongo_unstructured_log(linenum)
self._check_for_mongo_config_header(linenum)
+ # Relax the rule of commenting generic FCV references for files directly related to FCV
+ # implementations.
+ if not "feature_compatibility_version" in self.file_name:
+ self._check_for_generic_fcv(linenum)
+
return self._error_count
def _check_and_strip_comments(self):
@@ -125,6 +145,9 @@ class Linter:
if _RE_LINT.search(clean_line):
self.nolint_supression.append(linenum)
+ if _RE_GENERIC_FCV_COMMENT.search(clean_line):
+ self.generic_fcv_comments.append(linenum)
+
if not in_multi_line_comment:
if "/*" in clean_line and not "*/" in clean_line:
in_multi_line_comment = True
@@ -255,6 +278,17 @@ class Linter:
self._error(linenum, 'build/config_h_include',
'MONGO_CONFIG define used without prior inclusion of config.h.')
+ def _check_for_generic_fcv(self, linenum):
+ line = self.clean_lines[linenum]
+ if _RE_GENERIC_FCV_REF.search(line):
+ # Find the first generic FCV comment preceding the current line.
+ i = bisect.bisect_right(self.generic_fcv_comments, linenum)
+ if not i or self.generic_fcv_comments[i - 1] < (linenum - 10):
+ self._error(
+ linenum, 'mongodb/fcv',
+ 'Please add a comment containing "(Generic FCV reference):" within 10 lines ' +
+ 'before the generic FCV reference.')
+
def _error(self, linenum, category, message):
if linenum in self.nolint_supression:
return
diff --git a/src/mongo/db/fcv_op_observer.cpp b/src/mongo/db/fcv_op_observer.cpp
index d5a94048cc5..bb70616821c 100644
--- a/src/mongo/db/fcv_op_observer.cpp
+++ b/src/mongo/db/fcv_op_observer.cpp
@@ -75,6 +75,7 @@ void FcvOpObserver::_setVersion(OperationContext* opCtx,
// transactions here to release the global IX locks held by the transactions more proactively
// rather than waiting for the transactions to complete. FCV changes take the global S lock when
// in the upgrading/downgrading state.
+ // (Generic FCV reference): This FCV check should exist across LTS binary versions.
if (serverGlobalParams.featureCompatibility.isUpgradingOrDowngrading()) {
SessionKiller::Matcher matcherAllSessions(
KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)});
diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp
index 4bf9cebc028..ff78d54ec78 100644
--- a/src/mongo/db/repl/initial_syncer_test.cpp
+++ b/src/mongo/db/repl/initial_syncer_test.cpp
@@ -676,6 +676,7 @@ void assertFCVRequest(RemoteCommandRequest request) {
void InitialSyncerTest::processSuccessfulFCVFetcherResponseLastLTS() {
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
processSuccessfulFCVFetcherResponse({fcvDoc.toBSON()});
}
@@ -1893,6 +1894,7 @@ TEST_F(InitialSyncerTest,
TEST_F(InitialSyncerTest,
InitialSyncerReturnsTooManyMatchingDocumentsWhenFCVFetcherReturnsMultipleDocuments) {
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
auto docs = {fcvDoc.toBSON(),
BSON("_id"
@@ -1903,6 +1905,7 @@ TEST_F(InitialSyncerTest,
TEST_F(InitialSyncerTest,
InitialSyncerReturnsIncompatibleServerVersionWhenFCVFetcherReturnsUpgradeTargetVersion) {
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
fcvDoc.setTargetVersion(ServerGlobalParams::FeatureCompatibility::kLatest);
runInitialSyncWithBadFCVResponse({fcvDoc.toBSON()}, ErrorCodes::IncompatibleServerVersion);
@@ -1911,6 +1914,7 @@ TEST_F(InitialSyncerTest,
TEST_F(InitialSyncerTest,
InitialSyncerReturnsIncompatibleServerVersionWhenFCVFetcherReturnsDowngradeTargetVersion) {
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
fcvDoc.setTargetVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
fcvDoc.setPreviousVersion(ServerGlobalParams::FeatureCompatibility::kLatest);
@@ -1951,6 +1955,7 @@ TEST_F(InitialSyncerTest, InitialSyncerSucceedsWhenFCVFetcherReturnsOldVersion)
processSuccessfulLastOplogEntryFetcherResponse({makeOplogEntryObj(1)});
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
processSuccessfulFCVFetcherResponse({fcvDoc.toBSON()});
}
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 bbf0b76ac9c..1bb71524d3a 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
@@ -657,6 +657,7 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
Lock::SharedLock lk(opCtx->lockState(), FeatureCompatibilityVersion::fcvLock);
BSONObjBuilder setFCVBuilder;
+ // (Generic FCV reference): These FCV checks should exist across LTS binary versions.
switch (serverGlobalParams.featureCompatibility.getVersion()) {
case ServerGlobalParams::FeatureCompatibility::kLatest:
case ServerGlobalParams::FeatureCompatibility::Version::kUpgradingFrom44To47: {
@@ -668,6 +669,8 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
break;
}
default:
+ // (Generic FCV reference): This FCV reference should exist across LTS binary
+ // versions.
SetFeatureCompatibilityVersion setLastLTSCmd(
ServerGlobalParams::FeatureCompatibility::kLastLTS);
// The serialize function generated by IDL requires the DB name to be set.
diff --git a/src/mongo/db/startup_recovery.cpp b/src/mongo/db/startup_recovery.cpp
index 08c69d42e63..11d38fa42c3 100644
--- a/src/mongo/db/startup_recovery.cpp
+++ b/src/mongo/db/startup_recovery.cpp
@@ -96,6 +96,7 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
// create it.
if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
opCtx, NamespaceString::kServerConfigurationNamespace)) {
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
LOGV2(4926905,
"Re-creating featureCompatibilityVersion document that was deleted. Creating new "
"document with last LTS version.",
@@ -122,6 +123,7 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
"version"_attr = FeatureCompatibilityVersionParser::kVersion44);
FeatureCompatibilityVersionDocument fcvDoc;
+ // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
fcvDoc.setVersion(ServerGlobalParams::FeatureCompatibility::kLastLTS);
writeConflictRetry(opCtx, "insertFCVDocument", fcvNss.ns(), [&] {