summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2016-12-07 11:34:34 -0500
committerMisha Tyulenev <misha@mongodb.com>2016-12-07 17:03:17 -0500
commita2f78bd51b6390f8e0f151b7a92f7f34567018cb (patch)
tree624b7eeb4a46e485e71ac1d8203022d7a97ccf3f
parentdd8f6dbf3afc9356f964ac79d80e2215405402c2 (diff)
downloadmongo-a2f78bd51b6390f8e0f151b7a92f7f34567018cb.tar.gz
SERVER-27078 fix race in ShardRegistry initialization
(cherry picked from commit 77147629b714b1e062c1b406e0aef193cfca36a8)
-rw-r--r--src/mongo/s/client/shard_registry.cpp15
-rw-r--r--src/mongo/s/client/shard_registry.h14
2 files changed, 2 insertions, 27 deletions
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 1931d48ad6e..9de3457f77a 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -101,11 +101,6 @@ ConnectionString ShardRegistry::getConfigServerConnectionString() const {
return getConfigShard()->getConnString();
}
-void ShardRegistry::rebuildConfigShard() {
- _data.rebuildConfigShard(_shardFactory.get());
- invariant(_data.getConfigShard());
-}
-
StatusWith<shared_ptr<Shard>> ShardRegistry::getShard(OperationContext* txn,
const ShardId& shardId) {
// If we know about the shard, return it.
@@ -177,6 +172,8 @@ void ShardRegistry::updateReplSetHosts(const ConnectionString& newConnString) {
invariant(newConnString.type() == ConnectionString::SET ||
newConnString.type() == ConnectionString::CUSTOM); // For dbtests
+ // to prevent update config shard connection string during init
+ stdx::unique_lock<stdx::mutex> lock(_reloadMutex);
_data.rebuildShardIfExists(newConnString, _shardFactory.get());
}
@@ -443,14 +440,6 @@ void ShardRegistryData::shardIdSetDifference(std::set<ShardId>& diff) const {
}
}
-void ShardRegistryData::rebuildConfigShard(ShardFactory* factory) {
- stdx::unique_lock<stdx::mutex> rebuildConfigShardLock(_mutex);
-
- ConnectionString configConnString = _configShard->originalConnString();
-
- _rebuildShard_inlock(configConnString, factory);
-}
-
void ShardRegistryData::rebuildShardIfExists(const ConnectionString& newConnString,
ShardFactory* factory) {
stdx::unique_lock<stdx::mutex> updateConnStringLock(_mutex);
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index e134cc2e2db..94962ec66f6 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -97,12 +97,6 @@ public:
*/
void rebuildShardIfExists(const ConnectionString& newConnString, ShardFactory* factory);
- /**
- * Rebuilds config shard. The result is to recreate a ReplicaSetMonitor in the case it does
- * not exist.
- */
- void rebuildConfigShard(ShardFactory* factory);
-
private:
/**
* Reads shards docs from the catalog client and fills in maps.
@@ -173,14 +167,6 @@ public:
bool reload(OperationContext* txn);
/**
- * Throws out and reconstructs the config shard. This has the effect that if replica set
- * monitoring of the config server replica set has stopped (because the set was down for too
- * long), this will cause the ReplicaSetMonitor to be rebuilt, which will re-trigger monitoring
- * of the config replica set to resume.
- */
- void rebuildConfigShard();
-
- /**
* 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.