summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-08-21 10:06:34 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-08-21 12:10:38 -0400
commitf8cdaf32b6c44528123d8ffef7ea801a2f611745 (patch)
tree439a5b537649c5225b06b3d38b7859f2e386abc5 /src/mongo/s
parentf24e4ddcc542959a5bf3f8cbbcb08796c3f8856f (diff)
downloadmongo-f8cdaf32b6c44528123d8ffef7ea801a2f611745.tar.gz
SERVER-19855 Use ShardConnection for migrations and splits
This ensures that prior to sending the operation on the wire, the host will be primed to know that it is part of a sharded cluster.
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/chunk.cpp15
-rw-r--r--src/mongo/s/chunk.h2
-rw-r--r--src/mongo/s/commands/cluster_merge_chunks_cmd.cpp4
-rw-r--r--src/mongo/s/d_migrate.cpp5
4 files changed, 12 insertions, 14 deletions
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index da6cbc196df..23cbf463778 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -435,8 +435,6 @@ Status Chunk::multiSplit(OperationContext* txn, const vector<BSONObj>& m, BSONOb
uassert(13333, "can't split a chunk in that many parts", m.size() < maxSplitPoints);
uassert(13003, "can't split a chunk with only one distinct value", _min.woCompare(_max));
- ScopedDbConnection conn(_getShardConnectionString());
-
BSONObjBuilder cmd;
cmd.append("splitChunk", _manager->getns());
cmd.append("keyPattern", _manager->getShardKeyPattern().toBSON());
@@ -453,6 +451,7 @@ Status Chunk::multiSplit(OperationContext* txn, const vector<BSONObj>& m, BSONOb
res = &dummy;
}
+ ShardConnection conn(_getShardConnectionString(), "");
if (!conn->runCommand("admin", cmdObj, *res)) {
string msg(str::stream() << "splitChunk failed - cmd: " << cmdObj << " result: " << *res);
warning() << msg;
@@ -481,17 +480,15 @@ bool Chunk::moveAndCommit(OperationContext* txn,
log() << "moving chunk ns: " << _manager->getns() << " moving ( " << toString() << ") "
<< getShardId() << " -> " << toShardId;
- const auto from = grid.shardRegistry()->getShard(getShardId());
-
BSONObjBuilder builder;
builder.append("moveChunk", _manager->getns());
- builder.append("from", from->getConnString().toString());
+ builder.append("from", _getShardConnectionString().toString());
{
const auto toShard = grid.shardRegistry()->getShard(toShardId);
builder.append("to", toShard->getConnString().toString());
}
// NEEDED FOR 2.0 COMPATIBILITY
- builder.append("fromShard", from->getId());
+ builder.append("fromShard", getShardId());
builder.append("toShard", toShardId);
///////////////////////////////
builder.append("min", _min);
@@ -515,7 +512,7 @@ bool Chunk::moveAndCommit(OperationContext* txn,
builder.append(LiteParsedQuery::cmdOptionMaxTimeMS, maxTimeMS);
builder.append("epoch", _manager->getVersion().epoch());
- ScopedDbConnection fromconn(from->getConnString());
+ ShardConnection fromconn(_getShardConnectionString(), "");
bool worked = fromconn->runCommand("admin", builder.done(), res);
fromconn.done();
@@ -626,9 +623,9 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) const {
}
}
-std::string Chunk::_getShardConnectionString() const {
+ConnectionString Chunk::_getShardConnectionString() const {
const auto shard = grid.shardRegistry()->getShard(getShardId());
- return shard->getConnString().toString();
+ return shard->getConnString();
}
long Chunk::getPhysicalSize() const {
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index 1ec9a9447cb..822ac534380 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -261,7 +261,7 @@ private:
/**
* Returns the connection string for the shard on which this chunk resides.
*/
- std::string _getShardConnectionString() const;
+ ConnectionString _getShardConnectionString() const;
// if min/max key is pos/neg infinity
bool _minIsInf() const;
diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
index 2c3802a8f3b..084b63661f3 100644
--- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
+++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
@@ -38,6 +38,7 @@
#include "mongo/s/catalog/catalog_cache.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/chunk_manager.h"
+#include "mongo/s/client/shard_connection.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
@@ -179,6 +180,7 @@ public:
grid.shardRegistry()->getConfigServerConnectionString().toString());
remoteCmdObjB.append(ClusterMergeChunksCommand::shardNameField(), firstChunk->getShardId());
+
BSONObj remoteResult;
// Throws, but handled at level above. Don't want to rewrap to preserve exception
@@ -191,7 +193,7 @@ public:
str::stream() << "Can't find shard for chunk: " << firstChunk->toString()));
}
- ScopedDbConnection conn(shard->getConnString());
+ ShardConnection conn(shard->getConnString(), "");
bool ok = conn->runCommand("admin", remoteCmdObjB.obj(), remoteResult);
conn.done();
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index 269a6d5a5e7..4138c2242a9 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -573,7 +573,6 @@ public:
return false;
}
- ScopedDbConnection connTo(toShardCS);
BSONObj res;
bool ok;
@@ -596,7 +595,9 @@ public:
}
try {
+ ScopedDbConnection connTo(toShardCS);
ok = connTo->runCommand("admin", recvChunkStartBuilder.done(), res);
+ connTo.done();
} catch (DBException& e) {
errmsg = str::stream() << "moveChunk could not contact to: shard " << toShardName
<< " to start transfer" << causedBy(e);
@@ -604,8 +605,6 @@ public:
return false;
}
- connTo.done();
-
if (!ok) {
errmsg = "moveChunk failed to engage TO-shard in the data transfer: ";
verify(res["errmsg"].type());