summaryrefslogtreecommitdiff
path: root/s/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 's/client.cpp')
-rw-r--r--s/client.cpp56
1 files changed, 30 insertions, 26 deletions
diff --git a/s/client.cpp b/s/client.cpp
index 9058b31..493a8fb 100644
--- a/s/client.cpp
+++ b/s/client.cpp
@@ -18,7 +18,7 @@
#include "pch.h"
#include "server.h"
-
+#include "../util/scopeguard.h"
#include "../db/commands.h"
#include "../db/dbmessage.h"
#include "../db/stats/counters.h"
@@ -140,28 +140,31 @@ namespace mongo {
// handle single server
if ( shards->size() == 1 ) {
string theShard = *(shards->begin() );
-
- ShardConnection conn( theShard , "" );
+
+
BSONObj res;
bool ok = false;
- try{
- ok = conn->runCommand( "admin" , options , res );
- }
- catch( std::exception &e ){
-
- warning() << "could not get last error from shard " << theShard << causedBy( e ) << endl;
-
- // Catch everything that happens here, since we need to ensure we return our connection when we're
- // finished.
- conn.done();
+ {
+ ShardConnection conn( theShard , "" );
+ try {
+ ok = conn->runCommand( "admin" , options , res );
+ }
+ catch( std::exception &e ) {
- return false;
- }
+ warning() << "could not get last error from shard " << theShard << causedBy( e ) << endl;
+
+ // Catch everything that happens here, since we need to ensure we return our connection when we're
+ // finished.
+ conn.done();
+
+ return false;
+ }
- res = res.getOwned();
- conn.done();
+ res = res.getOwned();
+ conn.done();
+ }
_addWriteBack( writebacks , res );
@@ -171,16 +174,16 @@ namespace mongo {
if ( temp == theShard )
continue;
- ShardConnection conn( temp , "" );
-
try {
+ ShardConnection conn( temp , "" );
+ ON_BLOCK_EXIT_OBJ( conn, &ShardConnection::done );
_addWriteBack( writebacks , conn->getLastErrorDetailed() );
+
}
catch( std::exception &e ){
warning() << "could not clear last error from shard " << temp << causedBy( e ) << endl;
}
-
- conn.done();
+
}
clearSinceLastGetError();
@@ -224,11 +227,12 @@ namespace mongo {
for ( set<string>::iterator i = shards->begin(); i != shards->end(); i++ ) {
string theShard = *i;
bbb.append( theShard );
- ShardConnection conn( theShard , "" );
+ boost::scoped_ptr<ShardConnection> conn;
BSONObj res;
bool ok = false;
try {
- ok = conn->runCommand( "admin" , options , res );
+ conn.reset( new ShardConnection( theShard , "" ) ); // constructor can throw if shard is down
+ ok = (*conn)->runCommand( "admin" , options , res );
shardRawGLE.append( theShard , res );
}
catch( std::exception &e ){
@@ -237,7 +241,7 @@ namespace mongo {
// responses.
warning() << "could not get last error from a shard " << theShard << causedBy( e ) << endl;
- conn.done();
+ conn->done();
return false;
}
@@ -245,7 +249,7 @@ namespace mongo {
_addWriteBack( writebacks, res );
string temp = DBClientWithCommands::getLastErrorString( res );
- if ( conn->type() != ConnectionString::SYNC && ( ok == false || temp.size() ) ) {
+ if ( (*conn)->type() != ConnectionString::SYNC && ( ok == false || temp.size() ) ) {
errors.push_back( temp );
errorObjects.push_back( res );
}
@@ -258,7 +262,7 @@ namespace mongo {
updatedExistingStat = -1;
}
- conn.done();
+ conn->done();
}
bbb.done();