From cc923b4e66e0c76714f877b33ce9fd5f28e17f62 Mon Sep 17 00:00:00 2001 From: Matthew Saltz Date: Tue, 7 May 2019 17:39:06 -0400 Subject: SERVER-39498 Make rollback trigger a lazy (rather than blocking) reload of the ShardRegistry (cherry picked from commit d3ee35d6e3ac7a42cd5ad106c3ecb9fb554900c7) --- src/mongo/db/op_observer_impl.cpp | 11 +++-------- src/mongo/db/repl/rs_rollback.cpp | 11 +++-------- src/mongo/s/client/shard_registry.cpp | 10 ++++++++-- src/mongo/s/client/shard_registry.h | 6 ++++++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 7b106277c61..cb6fd810ee7 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -985,16 +985,11 @@ void OpObserverImpl::onReplicationRollback(OperationContext* opCtx, fassertFailedNoTrace(50712); } - // The code below will force the config server to update its shard registry. - // Otherwise it may have the stale data that has been just rolled back. + // Force the config server to update its shard registry on next access. Otherwise it may have + // the stale data that has been just rolled back. if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { if (auto shardRegistry = Grid::get(opCtx)->shardRegistry()) { - auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx); - ON_BLOCK_EXIT([ argsCopy = readConcernArgs, &readConcernArgs ] { - readConcernArgs = std::move(argsCopy); - }); - readConcernArgs = repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); - shardRegistry->reload(opCtx); + shardRegistry->clearEntries(); } } } diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 65ba8fff86b..e95fcaf4044 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -1467,16 +1467,11 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, validator->resetKeyManagerCache(); } - // The code below will force the config server to update its shard registry. - // Otherwise it may have the stale data that has been just rolled back. + // Force the config server to update its shard registry on next access. Otherwise it may have + // the stale data that has been just rolled back. if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { if (auto shardRegistry = Grid::get(opCtx)->shardRegistry()) { - auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx); - ON_BLOCK_EXIT([ argsCopy = readConcernArgs, &readConcernArgs ] { - readConcernArgs = std::move(argsCopy); - }); - readConcernArgs = repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); - shardRegistry->reload(opCtx); + shardRegistry->clearEntries(); } } diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index e2c5ec5573f..265c8aed6c6 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -66,17 +66,17 @@ namespace mongo { -using std::shared_ptr; using std::set; +using std::shared_ptr; using std::string; using std::unique_ptr; using std::vector; using executor::NetworkInterface; using executor::NetworkInterfaceThreadPool; +using executor::TaskExecutor; using executor::TaskExecutorPool; using executor::ThreadPoolTaskExecutor; -using executor::TaskExecutor; using CallbackArgs = TaskExecutor::CallbackArgs; using CallbackHandle = TaskExecutor::CallbackHandle; @@ -350,6 +350,12 @@ void ShardRegistry::replicaSetChangeShardRegistryUpdateHook( Grid::get(getGlobalServiceContext())->shardRegistry()->updateReplSetHosts(connString); } +void ShardRegistry::clearEntries() { + ShardRegistryData empty; + empty.addConfigShard(_data.getConfigShard()); + _data.swap(empty); +} + void ShardRegistry::replicaSetChangeConfigServerUpdateHook(const std::string& setName, const std::string& newConnectionString) { // This is run in it's own thread. Exceptions escaping would result in a call to terminate. diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index 5004b271a90..8371b1aff8a 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -181,6 +181,12 @@ public: */ bool reload(OperationContext* opCtx); + /** + * Clears all entries from the shard registry entries, which will force the registry to do a + * reload on next access. + */ + void clearEntries(); + /** * Takes a connection string describing either a shard or config server replica set, looks * up the corresponding Shard object based on the replica set name, then updates the -- cgit v1.2.1