summaryrefslogtreecommitdiff
path: root/src/mongo/s/client
diff options
context:
space:
mode:
authorMatthew Saltz <matthew.saltz@mongodb.com>2018-03-23 15:05:15 -0400
committerMatthew Saltz <matthew.saltz@mongodb.com>2018-03-29 13:28:11 -0400
commit6306b96749d4a547a1fa023eb1a0085b37e75c07 (patch)
treedc1319cd6b4782d70b9d084a524ada7b31998a96 /src/mongo/s/client
parent50e1e0be8d2eeccf866a3b249f63bdfdf91e3698 (diff)
downloadmongo-6306b96749d4a547a1fa023eb1a0085b37e75c07.tar.gz
SERVER-33797: Reload ShardRegistry on shard collection command
Diffstat (limited to 'src/mongo/s/client')
-rw-r--r--src/mongo/s/client/shard_connection.cpp2
-rw-r--r--src/mongo/s/client/shard_registry.cpp16
-rw-r--r--src/mongo/s/client/shard_registry.h9
3 files changed, 24 insertions, 3 deletions
diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp
index 2aa50893ecf..9d117a706af 100644
--- a/src/mongo/s/client/shard_connection.cpp
+++ b/src/mongo/s/client/shard_connection.cpp
@@ -217,7 +217,7 @@ public:
auto const shardRegistry = Grid::get(opCtx)->shardRegistry();
std::vector<ShardId> all;
- shardRegistry->getAllShardIds(&all);
+ shardRegistry->getAllShardIdsNoReload(&all);
// Don't report exceptions here as errors in GetLastError
LastError::Disabled ignoreForGLE(&LastError::get(cc()));
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index c97279a8403..ff43db37b72 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -163,12 +163,26 @@ shared_ptr<Shard> ShardRegistry::lookupRSName(const string& name) const {
return _data.findByRSName(name);
}
-void ShardRegistry::getAllShardIds(vector<ShardId>* all) const {
+void ShardRegistry::getAllShardIdsNoReload(vector<ShardId>* all) const {
std::set<ShardId> seen;
_data.getAllShardIds(seen);
all->assign(seen.begin(), seen.end());
}
+void ShardRegistry::getAllShardIds(OperationContext* opCtx, vector<ShardId>* all) {
+ getAllShardIdsNoReload(all);
+ if (all->empty()) {
+ bool didReload = reload(opCtx);
+ getAllShardIdsNoReload(all);
+ // If we didn't do the reload ourselves, we should retry to ensure
+ // that the reload is actually initiated while we're executing this
+ if (!didReload && all->empty()) {
+ reload(opCtx);
+ getAllShardIdsNoReload(all);
+ }
+ }
+}
+
int ShardRegistry::getNumShards() const {
std::set<ShardId> seen;
_data.getAllShardIds(seen);
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index af1f11e8f06..ab27d97ac3c 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -232,7 +232,14 @@ public:
*/
std::shared_ptr<Shard> lookupRSName(const std::string& name) const;
- void getAllShardIds(std::vector<ShardId>* all) const;
+ void getAllShardIdsNoReload(std::vector<ShardId>* all) const;
+
+ /**
+ * Like getAllShardIdsNoReload(), but does a reload internally in the case that
+ * getAllShardIdsNoReload() comes back empty
+ */
+ void getAllShardIds(OperationContext* opCtx, std::vector<ShardId>* all);
+
int getNumShards() const;
void toBSON(BSONObjBuilder* result) const;