diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2021-01-04 17:25:21 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-05 10:27:53 +0000 |
commit | 74d0af15cd83994ac120c8497a900b594456a647 (patch) | |
tree | b45bc644abd80e3185fea715c9df92be0e9fbabb | |
parent | 423c395534da5afc1d297e8db85065986d596421 (diff) | |
download | mongo-74d0af15cd83994ac120c8497a900b594456a647.tar.gz |
SERVER-53548 Replace all usages of Grid's configTime with VectorClock
-rw-r--r-- | src/mongo/s/grid.cpp | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp index 5d0fc668092..0b0c64d39e7 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -46,13 +46,6 @@ namespace mongo { namespace { const auto grid = ServiceContext::declareDecoration<Grid>(); - -// TODO SERVER-50675: Remove this FVC function when 5.0 becomes last-lts. -bool fcvGreaterThanOrEqualTo47() { - auto& fcv = serverGlobalParams.featureCompatibility; - return fcv.isVersionInitialized() && - fcv.isGreaterThanOrEqualTo(ServerGlobalParams::FeatureCompatibility::Version::kVersion47); -} } // namespace Grid::Grid() = default; @@ -123,41 +116,40 @@ void Grid::setAllowLocalHost(bool allow) { repl::ReadConcernArgs Grid::readConcernWithConfigTime( repl::ReadConcernLevel readConcernLevel) const { - auto configTime = configOpTime(); - if (fcvGreaterThanOrEqualTo47()) { - const auto currentTime = VectorClock::get(grid.owner(this))->getTime(); - const auto vcConfigTimeTs = currentTime.configTime().asTimestamp(); - if (!vcConfigTimeTs.isNull() && vcConfigTimeTs > configTime.getTimestamp()) { - // TODO SERVER-44097: investigate why not using a term (e.g. with a LogicalTime) - // can lead - upon CSRS stepdowns - to a last applied opTime lower than the - // previous primary's committed opTime - configTime = - mongo::repl::OpTime(vcConfigTimeTs, mongo::repl::OpTime::kUninitializedTerm); - } - } - return ReadConcernArgs(configTime, readConcernLevel); + return ReadConcernArgs(configOpTime(), readConcernLevel); } ReadPreferenceSetting Grid::readPreferenceWithConfigTime( const ReadPreferenceSetting& readPreference) const { - auto configTimeTs = configOpTime().getTimestamp(); - if (fcvGreaterThanOrEqualTo47()) { - const auto currentTime = VectorClock::get(grid.owner(this))->getTime(); - const auto vcConfigTimeTs = currentTime.configTime().asTimestamp(); - if (!vcConfigTimeTs.isNull() && vcConfigTimeTs > configTimeTs) { - configTimeTs = vcConfigTimeTs; - } - } ReadPreferenceSetting readPrefToReturn(readPreference); - readPrefToReturn.minClusterTime = configTimeTs; + readPrefToReturn.minClusterTime = configOpTime().getTimestamp(); return readPrefToReturn; } +// TODO SERVER-50675: directly use VectorClock's configTime once 5.0 becomes last-lts. repl::OpTime Grid::configOpTime() const { invariant(serverGlobalParams.clusterRole != ClusterRole::ConfigServer); - stdx::lock_guard<Latch> lk(_mutex); - return _configOpTime; + auto configTime = [this] { + stdx::lock_guard<Latch> lk(_mutex); + return _configOpTime; + }(); + + const auto& fcv = serverGlobalParams.featureCompatibility; + if (fcv.isVersionInitialized() && + fcv.isGreaterThanOrEqualTo(ServerGlobalParams::FeatureCompatibility::Version::kVersion47)) { + const auto currentTime = VectorClock::get(grid.owner(this))->getTime(); + const auto vcConfigTimeTs = currentTime.configTime().asTimestamp(); + if (!vcConfigTimeTs.isNull() && vcConfigTimeTs >= configTime.getTimestamp()) { + // TODO SERVER-44097: investigate why not using a term (e.g. with a LogicalTime) + // can lead - upon CSRS stepdowns - to a last applied opTime lower than the + // previous primary's committed opTime + configTime = + mongo::repl::OpTime(vcConfigTimeTs, mongo::repl::OpTime::kUninitializedTerm); + } + } + + return configTime; } boost::optional<repl::OpTime> Grid::advanceConfigOpTime(OperationContext* opCtx, |