summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2013-06-13 13:39:25 -0400
committerGreg Studer <greg@10gen.com>2013-08-02 11:07:32 -0400
commit80f1630fc9a1603de5835690e49ac5fa0f4509e4 (patch)
tree16e16328560a3af4b7162a2dac71b3550f8ca03e
parentbae49ad621c67176cc329faba96f246597af98ea (diff)
downloadmongo-80f1630fc9a1603de5835690e49ac5fa0f4509e4.tar.gz
SERVER-9913 protect ScopedDbConn constructor in migrate critical section
-rw-r--r--src/mongo/s/d_migrate.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index 139a640f5ce..69390e331b8 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -1252,49 +1252,48 @@ namespace mongo {
// 5.b
// we're under the collection lock here, too, so we can undo the chunk donation because no other state change
// could be ongoing
- {
- BSONObj res;
+
+ BSONObj res;
+ bool ok;
+
+ try {
scoped_ptr<ScopedDbConnection> connTo(
ScopedDbConnection::getScopedDbConnection( toShard.getConnString(),
35.0 ) );
-
- bool ok;
-
- try{
- ok = connTo->get()->runCommand( "admin" ,
- BSON( "_recvChunkCommit" << 1 ) ,
- res );
- }
- catch( DBException& e ){
- errmsg = str::stream() << "moveChunk could not contact to: shard " << toShard.getConnString() << " to commit transfer" << causedBy( e );
- warning() << errmsg << endl;
- ok = false;
- }
-
+ ok = connTo->get()->runCommand( "admin", BSON( "_recvChunkCommit" << 1 ), res );
connTo->done();
+ }
+ catch ( DBException& e ) {
+ errmsg = str::stream() << "moveChunk could not contact to: shard "
+ << toShard.getConnString() << " to commit transfer"
+ << causedBy( e );
+ warning() << errmsg << endl;
+ ok = false;
+ }
- if ( ! ok ) {
- log() << "moveChunk migrate commit not accepted by TO-shard: " << res
- << " resetting shard version to: " << startingVersion << migrateLog;
- {
- Lock::GlobalWrite lk;
- log() << "moveChunk global lock acquired to reset shard version from "
- "failed migration" << endl;
-
- // revert the chunk manager back to the state before "forgetting" about the chunk
- shardingState.undoDonateChunk( ns , min , max , startingVersion );
- }
- log() << "Shard version successfully reset to clean up failed migration"
- << endl;
+ if ( !ok ) {
+ log() << "moveChunk migrate commit not accepted by TO-shard: " << res
+ << " resetting shard version to: " << startingVersion << migrateLog;
+ {
+ Lock::GlobalWrite lk;
+ log() << "moveChunk global lock acquired to reset shard version from "
+ "failed migration"
+ << endl;
- errmsg = "_recvChunkCommit failed!";
- result.append( "cause" , res );
- return false;
+ // revert the chunk manager back to the state before "forgetting" about the
+ // chunk
+ shardingState.undoDonateChunk( ns, min, max, startingVersion );
}
+ log() << "Shard version successfully reset to clean up failed migration"
+ << endl;
- log() << "moveChunk migrate commit accepted by TO-shard: " << res << migrateLog;
+ errmsg = "_recvChunkCommit failed!";
+ result.append( "cause", res );
+ return false;
}
+ log() << "moveChunk migrate commit accepted by TO-shard: " << res << migrateLog;
+
// 5.c
// version at which the next highest lastmod will be set
@@ -1404,7 +1403,7 @@ namespace mongo {
LOG(7) << "moveChunk update: " << cmd << migrateLog;
int exceptionCode = OkCode;
- bool ok = false;
+ ok = false;
BSONObj cmdResult;
try {
scoped_ptr<ScopedDbConnection> conn(