summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/op_observer_impl.cpp11
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp11
-rw-r--r--src/mongo/s/client/shard_registry.cpp10
-rw-r--r--src/mongo/s/client/shard_registry.h6
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
@@ -182,6 +182,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
* ShardRegistry's notion of what hosts make up that shard.