diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2021-07-26 14:26:00 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-29 08:20:46 +0000 |
commit | e81cb3762287d565644a96d2891d7d8ad820f1b0 (patch) | |
tree | 952364d65f9a12a22bf9b18ab04b139debeb1332 | |
parent | e6814e16c2f31cf0fd8328ddd3809e485be60d65 (diff) | |
download | mongo-e81cb3762287d565644a96d2891d7d8ad820f1b0.tar.gz |
SERVER-50675 Get rid of Grid's configOpTime after 5.0 has branched out
-rw-r--r-- | src/mongo/db/s/sharding_config_optime_gossip.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state_recovery.cpp | 12 | ||||
-rw-r--r-- | src/mongo/s/grid.cpp | 65 | ||||
-rw-r--r-- | src/mongo/s/grid.h | 18 | ||||
-rw-r--r-- | src/mongo/s/sharding_egress_metadata_hook.cpp | 7 |
5 files changed, 13 insertions, 91 deletions
diff --git a/src/mongo/db/s/sharding_config_optime_gossip.cpp b/src/mongo/db/s/sharding_config_optime_gossip.cpp index 204241e0979..7421ff74059 100644 --- a/src/mongo/db/s/sharding_config_optime_gossip.cpp +++ b/src/mongo/db/s/sharding_config_optime_gossip.cpp @@ -84,7 +84,7 @@ void advanceConfigOpTimeFromRequestMetadata(OperationContext* opCtx) { ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), ActionType::internal)); - Grid::get(opCtx)->advanceConfigOpTime(opCtx, *opTime, "request from"); + Grid::get(opCtx)->advanceConfigOpTime(opCtx, *opTime); } } // namespace rpc diff --git a/src/mongo/db/s/sharding_state_recovery.cpp b/src/mongo/db/s/sharding_state_recovery.cpp index e10f456c74e..9bfe36ff580 100644 --- a/src/mongo/db/s/sharding_state_recovery.cpp +++ b/src/mongo/db/s/sharding_state_recovery.cpp @@ -237,17 +237,7 @@ Status ShardingStateRecovery::recover(OperationContext* opCtx) { "recoveryDoc"_attr = redact(recoveryDoc.toBSON())); if (!recoveryDoc.getMinOpTimeUpdaters()) { - // Treat the minOpTime as up-to-date - const auto prevOpTime = grid->advanceConfigOpTime( - opCtx, recoveryDoc.getMinOpTime(), "sharding state recovery document"); - if (prevOpTime) { - LOGV2(22085, - "No in flight metadata change operations, so config server optime updated from " - "{prevConfigServerMinOpTime} to {newConfigServerMinOpTime}", - "No in flight metadata change operations, so config server optime updated", - "prevConfigServerMinOpTime"_attr = *prevOpTime, - "newConfigServerMinOpTime"_attr = recoveryDoc.getMinOpTime()); - } + grid->advanceConfigOpTime(opCtx, recoveryDoc.getMinOpTime()); return Status::OK(); } diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp index 4ee760ba2a1..4dae85d5df2 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -118,68 +118,19 @@ ReadPreferenceSetting Grid::readPreferenceWithConfigTime( 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); - - 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, - repl::OpTime opTime, - StringData what) { - const auto prevOpTime = _advanceConfigOpTime(opTime); - if (prevOpTime && prevOpTime->getTerm() != mongo::repl::OpTime::kUninitializedTerm && - opTime.getTerm() != mongo::repl::OpTime::kUninitializedTerm && - prevOpTime->getTerm() != opTime.getTerm()) { - std::string clientAddr = "(unknown)"; - if (opCtx && opCtx->getClient()) { - clientAddr = opCtx->getClient()->clientAddress(true); - } - LOGV2(22792, - "Received {reason} {clientAddress} indicating config server" - " term has increased, previous opTime {prevOpTime}, now {opTime}", - "Term advanced for config server", - "opTime"_attr = opTime, - "prevOpTime"_attr = prevOpTime, - "reason"_attr = what, - "clientAddress"_attr = clientAddr); - } - return prevOpTime; + const auto currentTime = VectorClock::get(grid.owner(this))->getTime(); + const auto vcConfigTimeTs = currentTime.configTime().asTimestamp(); + return mongo::repl::OpTime(vcConfigTimeTs, mongo::repl::OpTime::kUninitializedTerm); } -boost::optional<repl::OpTime> Grid::_advanceConfigOpTime(const repl::OpTime& opTime) { - invariant(serverGlobalParams.clusterRole != ClusterRole::ConfigServer); +void Grid::advanceConfigOpTime(OperationContext* opCtx, repl::OpTime opTime) { auto vectorClock = VectorClock::get(grid.owner(this)); - if (vectorClock->isEnabled()) { - vectorClock->gossipInConfigOpTime(opTime); + if (!vectorClock->isEnabled()) { + return; } - stdx::lock_guard<Latch> lk(_mutex); - if (_configOpTime < opTime) { - repl::OpTime prev = _configOpTime; - _configOpTime = opTime; - return prev; - } - return boost::none; + vectorClock->gossipInConfigOpTime(opTime); } void Grid::clearForUnitTests() { @@ -190,8 +141,6 @@ void Grid::clearForUnitTests() { _balancerConfig.reset(); _executorPool.reset(); _network = nullptr; - - _configOpTime = repl::OpTime(); } } // namespace mongo diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h index ad5372d222f..81a765db38d 100644 --- a/src/mongo/s/grid.h +++ b/src/mongo/s/grid.h @@ -154,9 +154,7 @@ public: * If the config optime was updated, returns the previous value. * NOTE: This is not valid to call on a config server instance. */ - boost::optional<repl::OpTime> advanceConfigOpTime(OperationContext* opCtx, - repl::OpTime opTime, - StringData what); + void advanceConfigOpTime(OperationContext* opCtx, repl::OpTime opTime); /** * Clears the grid object so that it can be reused between test executions. This will not @@ -184,23 +182,11 @@ private: // questions about the network configuration, such as getting the current server's hostname. executor::NetworkInterface* _network{nullptr}; - CustomConnectionPoolStatsFn _customConnectionPoolStatsFn; - AtomicWord<bool> _shardingInitialized{false}; - // Protects _configOpTime. mutable Mutex _mutex = MONGO_MAKE_LATCH(HierarchicalAcquisitionLevel(0), "Grid::_mutex"); - // Last known highest opTime from the config server that should be used when doing reads. - // This value is updated any time a shard or mongos talks to a config server or a shard. - repl::OpTime _configOpTime; - - /** - * Called to update what we've seen as the last config server optime. - * If the config optime was updated, returns the previous value. - * NOTE: This is not valid to call on a config server instance. - */ - boost::optional<repl::OpTime> _advanceConfigOpTime(const repl::OpTime& opTime); + CustomConnectionPoolStatsFn _customConnectionPoolStatsFn; }; } // namespace mongo diff --git a/src/mongo/s/sharding_egress_metadata_hook.cpp b/src/mongo/s/sharding_egress_metadata_hook.cpp index 9f0d11eeff7..640445e6a6c 100644 --- a/src/mongo/s/sharding_egress_metadata_hook.cpp +++ b/src/mongo/s/sharding_egress_metadata_hook.cpp @@ -103,7 +103,7 @@ Status ShardingEgressMetadataHook::_advanceConfigOpTimeFromShard(OperationContex // is safe to use. const auto& replMetadata = parseStatus.getValue(); const auto opTime = replMetadata.getLastOpCommitted(); - grid->advanceConfigOpTime(opCtx, opTime.opTime, "reply from config server node"); + grid->advanceConfigOpTime(opCtx, opTime.opTime); } } else { // Regular shards return the config opTime as part of ConfigServerMetadata. @@ -115,10 +115,7 @@ Status ShardingEgressMetadataHook::_advanceConfigOpTimeFromShard(OperationContex const auto& configMetadata = parseStatus.getValue(); const auto opTime = configMetadata.getOpTime(); if (opTime.is_initialized()) { - grid->advanceConfigOpTime(opCtx, - opTime.get(), - str::stream() - << "reply from shard " << shardId << " node"); + grid->advanceConfigOpTime(opCtx, opTime.get()); } } return Status::OK(); |