Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50264

Better FeatureCompatibility const correctness

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.7.0
    • None
    • Fully Compatible
    • Repl 2020-09-07

    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).

      Attachments

        Issue Links

          Activity

            People

              lingzhi.deng@mongodb.com Lingzhi Deng
              kevin.pulo@mongodb.com Kevin Pulo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: