summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2016-01-06 10:17:01 -0500
committerMisha Tyulenev <misha@mongodb.com>2016-01-19 15:47:34 -0500
commitf777c19331257bc9c6547f62996850ae65f22b03 (patch)
tree83522ec25b505a6ea377090ecd0ffe7dd3d7d607 /src
parent556d071e9a917784cc03185472c632deee09c48f (diff)
downloadmongo-f777c19331257bc9c6547f62996850ae65f22b03.tar.gz
SERVER-21906 always use ReplicaSetMonitor when updating ShardRegistry lookup maps
(cherry picked from commit a05ba516fb340bd7a22480303c8d647b6d6c9874)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/s/client/shard_registry.cpp35
-rw-r--r--src/mongo/s/client/shard_registry.h9
2 files changed, 28 insertions, 16 deletions
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 55aa86def05..9b6814901b1 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -206,7 +206,7 @@ void ShardRegistry::reload(OperationContext* txn) {
continue;
}
- _addShard_inlock(shardType);
+ _addShard_inlock(shardType, false);
}
}
@@ -326,10 +326,10 @@ void ShardRegistry::_addConfigShard_inlock() {
ShardType configServerShard;
configServerShard.setName("config");
configServerShard.setHost(_configServerCS.toString());
- _addShard_inlock(configServerShard);
+ _addShard_inlock(configServerShard, true);
}
-void ShardRegistry::_addShard_inlock(const ShardType& shardType) {
+void ShardRegistry::_addShard_inlock(const ShardType& shardType, bool passHostName) {
// This validation should ideally go inside the ShardType::validate call. However, doing
// it there would prevent us from loading previously faulty shard hosts, which might have
// been stored (i.e., the entire getAllShards call would fail).
@@ -347,27 +347,38 @@ void ShardRegistry::_addShard_inlock(const ShardType& shardType) {
// mechanism and must only be reachable through CatalogManagerLegacy or legacy-style queries
// and inserts. Do not create targeter for these connections. This code should go away after
// 3.2 is released.
+ // Config server updates must pass the host name to avoid deadlock
shard = std::make_shared<Shard>(shardType.getName(), shardHost, nullptr);
+ _updateLookupMapsForShard_inlock(std::move(shard), shardHost);
} else {
// Non-SYNC shards use targeter factory.
shard = std::make_shared<Shard>(
shardType.getName(), shardHost, _targeterFactory->create(shardHost));
+ if (passHostName) {
+ _updateLookupMapsForShard_inlock(std::move(shard), shardHost);
+ } else {
+ _updateLookupMapsForShard_inlock(std::move(shard),
+ boost::optional<const ConnectionString&>(boost::none));
+ }
}
-
- _updateLookupMapsForShard_inlock(std::move(shard), shardHost);
}
-void ShardRegistry::updateLookupMapsForShard(shared_ptr<Shard> shard,
- const ConnectionString& newConnString) {
- log() << "Updating ShardRegistry connection string for shard " << shard->getId()
- << " from: " << shard->getConnString().toString() << " to: " << newConnString.toString();
+void ShardRegistry::updateLookupMapsForShard(
+ shared_ptr<Shard> shard, boost::optional<const ConnectionString&> optConnString) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
- _updateLookupMapsForShard_inlock(std::move(shard), newConnString);
+ _updateLookupMapsForShard_inlock(std::move(shard), optConnString);
}
-void ShardRegistry::_updateLookupMapsForShard_inlock(shared_ptr<Shard> shard,
- const ConnectionString& newConnString) {
+void ShardRegistry::_updateLookupMapsForShard_inlock(
+ shared_ptr<Shard> shard, boost::optional<const ConnectionString&> optConnString) {
auto oldConnString = shard->getConnString();
+ auto newConnString = optConnString ? *optConnString : shard->getTargeter()->connectionString();
+
+ if (oldConnString.toString() != newConnString.toString()) {
+ log() << "Updating ShardRegistry connection string for shard " << shard->getId()
+ << " from: " << oldConnString.toString() << " to: " << newConnString.toString();
+ }
+
for (const auto& host : oldConnString.getServers()) {
_lookup.erase(host.toString());
_hostLookup.erase(host);
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index e219cd26c7b..897b05809ec 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -149,12 +149,13 @@ public:
/**
* Updates _lookup and _rsLookup based on the given new version of the given Shard's
- * ConnectionString.
+ * ConnectionString. If ConnectionString is not specified the maps are updated with hosts
+ * from the ReplicaSetMonitor.
* Used to update the ShardRegistry when a change in replica set membership is detected by the
* ReplicaSetMonitor.
*/
void updateLookupMapsForShard(std::shared_ptr<Shard> shard,
- const ConnectionString& newConnString);
+ boost::optional<const ConnectionString&> newConnString);
/**
* Returns a shared pointer to the shard object with the given shard id.
@@ -342,7 +343,7 @@ private:
/**
* Creates a shard based on the specified information and puts it into the lookup maps.
*/
- void _addShard_inlock(const ShardType& shardType);
+ void _addShard_inlock(const ShardType& shardType, bool passHostName);
/**
* Adds the "config" shard (representing the config server) to the shard registry.
@@ -350,7 +351,7 @@ private:
void _addConfigShard_inlock();
void _updateLookupMapsForShard_inlock(std::shared_ptr<Shard> shard,
- const ConnectionString& newConnString);
+ boost::optional<const ConnectionString&> newConnString);
std::shared_ptr<Shard> _findUsingLookUp(const ShardId& shardId);