summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-02-24 11:54:52 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-02-24 16:04:57 -0500
commit5c182c1d5e8a141e6dcd156173f802f4e44b3610 (patch)
tree3958015cc3a77c08693c5e054a2638e811dac866 /src/mongo
parent794d99c43b312f11500f6bc5dc81a2afad7685ef (diff)
downloadmongo-5c182c1d5e8a141e6dcd156173f802f4e44b3610.tar.gz
SERVER-28098 Get rid of DBConfig::getAllShardIds
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp29
-rw-r--r--src/mongo/s/config.cpp10
-rw-r--r--src/mongo/s/config.h3
3 files changed, 20 insertions, 22 deletions
diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
index 33a45eb1b92..5ba01d49f4f 100644
--- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
@@ -119,7 +119,6 @@ BSONObj fixForShards(const BSONObj& orig,
return b.obj();
}
-
/**
* Outline for sharded map reduce for sharded output, $out replace:
*
@@ -282,6 +281,8 @@ public:
invariant(maxChunkSizeBytes < std::numeric_limits<int>::max());
}
+ const auto shardRegistry = Grid::get(txn)->shardRegistry();
+
// modify command to run on shards with output to tmp collection
string badShardedField;
BSONObj shardedCommand =
@@ -290,8 +291,8 @@ public:
if (!shardedInput && !shardedOutput && !customOutDB) {
LOG(1) << "simple MR, just passthrough";
- const auto shard = uassertStatusOK(
- Grid::get(txn)->shardRegistry()->getShard(txn, confIn->getPrimaryId()));
+ const auto shard =
+ uassertStatusOK(shardRegistry->getShard(txn, confIn->getPrimaryId()));
ShardConnection conn(shard->getConnString(), "");
@@ -350,8 +351,8 @@ public:
// Need to gather list of all servers even if an error happened
string server;
{
- const auto shard = uassertStatusOK(
- Grid::get(txn)->shardRegistry()->getShard(txn, mrResult.shardTargetId));
+ const auto shard =
+ uassertStatusOK(shardRegistry->getShard(txn, mrResult.shardTargetId));
server = shard->getConnString().toString();
}
servers.insert(server);
@@ -444,8 +445,8 @@ public:
bool hasWCError = false;
if (!shardedOutput) {
- const auto shard = uassertStatusOK(
- Grid::get(txn)->shardRegistry()->getShard(txn, confOut->getPrimaryId()));
+ const auto shard =
+ uassertStatusOK(shardRegistry->getShard(txn, confOut->getPrimaryId()));
LOG(1) << "MR with single shard output, NS=" << outputCollNss.ns()
<< " primary=" << shard->toString();
@@ -501,8 +502,18 @@ public:
//
// TODO: pre-split mapReduce output in a safer way.
- set<ShardId> outShardIds;
- confOut->getAllShardIds(&outShardIds);
+ const std::set<ShardId> outShardIds = [&]() {
+ std::vector<ShardId> shardIds;
+ shardRegistry->getAllShardIds(&shardIds);
+ uassert(ErrorCodes::ShardNotFound,
+ str::stream()
+ << "Unable to find shards on which to place output collection "
+ << outputCollNss.ns(),
+ !shardIds.empty());
+
+ return std::set<ShardId>(shardIds.begin(), shardIds.end());
+ }();
+
BSONObj sortKey = BSON("_id" << 1);
ShardKeyPattern sortKeyPattern(sortKey);
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index 1f6323a891d..153ddf71152 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -359,16 +359,6 @@ bool DBConfig::_loadIfNeeded(OperationContext* txn, Counter reloadIteration) {
return true;
}
-void DBConfig::getAllShardIds(std::set<ShardId>* shardIds) {
- stdx::lock_guard<stdx::mutex> lk(_lock);
- shardIds->insert(_primaryId);
-
- for (const auto& ciEntry : _collections) {
- const auto& ci = ciEntry.second;
- ci.cm->getAllShardIds(shardIds);
- }
-}
-
ShardId DBConfig::getPrimaryId() {
stdx::lock_guard<stdx::mutex> lk(_lock);
return _primaryId;
diff --git a/src/mongo/s/config.h b/src/mongo/s/config.h
index 73694eb37e2..2b0ecbb7d07 100644
--- a/src/mongo/s/config.h
+++ b/src/mongo/s/config.h
@@ -28,7 +28,6 @@
#pragma once
-#include <set>
#include <string>
#include "mongo/db/repl/optime.h"
@@ -96,8 +95,6 @@ public:
*/
bool load(OperationContext* txn);
- void getAllShardIds(std::set<ShardId>* shardIds);
-
protected:
typedef std::map<std::string, CollectionInfo> CollectionInfoMap;
typedef AtomicUInt64::WordType Counter;