From dc15e9c5fd0d8bb8b50679e5cf1170f426de60fb Mon Sep 17 00:00:00 2001 From: Jordi Serra Torrens Date: Thu, 29 Sep 2022 09:37:43 +0000 Subject: SERVER-70047 Add linter rule that checks CollectionSharingRuntime is not used outside sharding code --- buildscripts/linter/simplecpplint.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/buildscripts/linter/simplecpplint.py b/buildscripts/linter/simplecpplint.py index e9e28ff2d2a..a237b4c84b7 100644 --- a/buildscripts/linter/simplecpplint.py +++ b/buildscripts/linter/simplecpplint.py @@ -60,6 +60,7 @@ _RE_ASSERT = re.compile(r'\bassert\s*\(') _RE_UNSTRUCTURED_LOG = re.compile(r'\blogd\s*\(') _RE_STD_OPTIONAL = re.compile(r'\bstd::optional\b') _RE_TRACING_SUPPORT = re.compile(r'\bTracerProvider::(get|initialize)\b') +_RE_COLLECTION_SHARDING_RUNTIME = re.compile(r'\bCollectionShardingRuntime\b') _RE_GENERIC_FCV_COMMENT = re.compile(r'\(Generic FCV reference\):') GENERIC_FCV = [ @@ -153,6 +154,7 @@ class Linter: self._check_for_ctype(linenum) self._check_for_std_optional(linenum) self._check_for_tracing_support(linenum) + self._check_for_collection_sharding_runtime(linenum) # Relax the rule of commenting generic FCV references for files directly related to FCV # implementations. @@ -289,6 +291,15 @@ class Linter: linenum, 'mongodb/tracing', 'Illegal use of tracing support, ' 'this is only for local development use and should not be committed.') + def _check_for_collection_sharding_runtime(self, linenum): + line = self.clean_lines[linenum] + if _RE_COLLECTION_SHARDING_RUNTIME.search( + line) and "/src/mongo/db/s/" not in self.file_name: + self._error( + linenum, 'mongodb/collection_sharding_runtime', 'Illegal use of ' + 'CollectionShardingRuntime outside of mongo/db/s/; use CollectionShardingState ' + 'instead; see src/mongo/db/s/collection_sharding_state.h for details.') + def _license_error(self, linenum, msg, category='legal/license'): style_url = 'https://github.com/mongodb/mongo/wiki/Server-Code-Style' self._error(linenum, category, '{} See {}'.format(msg, style_url)) -- cgit v1.2.1