[SERVER-50264] Better FeatureCompatibility const correctness Created: 12/Aug/20  Updated: 29/Oct/23  Resolved: 27/Aug/20

Status: Closed
Project: Core Server
Component/s: Replication, Upgrade/Downgrade
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: Lingzhi Deng
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-49070 Add FCV gating helpers Closed
Backwards Compatibility: Fully Compatible
Sprint: Repl 2020-09-07
Participants:

 Description   

I was surprised when

if (const auto& fcv = serverGlobalParams.featureCompatibility; fcv.isVersionInitialized() &&
    fcv.isGreaterThanOrEqualTo(ServerGlobalParams::FeatureCompatibility::Version::kVersion47)) {
    // ...
}

wouldn't compile. So the newly-added accessors (isLessThanOrEqualTo, isGreaterThanOrEqualTo, isLessThan, isGreaterThan, isUpgradingOrDowngrading) should be const-qualified.

However in addition to this it might be better if serverGlobalParams.featureCompatibility was a const ref, with some other name for the places that legitimately need to modify it, eg.

 struct ServerGlobalParams {
     // ...
 
     struct FeatureCompatibility {
         // ...
-    } featureCompatibility;
+    } featureCompatibilityMutable;
+    const FeatureCompatibility& featureCompatibility = featureCompatibilityMutable;
 
     // ...
 };

This would have caught the missing const-qualifier on the accessors when they were added (in addition to helping prevent accidents).



 Comments   
Comment by Githook User [ 27/Aug/20 ]

Author:

{'name': 'Lingzhi Deng', 'email': 'lingzhi.deng@mongodb.com', 'username': 'ldennis'}

Message: SERVER-50264: Better FCV const correctness
Branch: master
https://github.com/mongodb/mongo/commit/d3fedc03bb3b2037bc4f2266b4cd106377c217b7

Comment by Githook User [ 27/Aug/20 ]

Author:

{'name': 'Lingzhi Deng', 'email': 'lingzhi.deng@mongodb.com', 'username': 'ldennis'}

Message: SERVER-50264: Better FCV const correctness
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/a5b8cd959afee8054f72be4ae00e8e4ae2dbd6d1

Generated at Thu Feb 08 05:22:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.