From 3703a282eca7e79e91f4bd651b1b861b76dc6c68 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Tue, 5 Jun 2012 19:50:34 +0200 Subject: Imported Upstream version 2.0.6 --- client/dbclient_rs.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'client/dbclient_rs.cpp') diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp index 4a8112b..c792656 100644 --- a/client/dbclient_rs.cpp +++ b/client/dbclient_rs.cpp @@ -303,12 +303,29 @@ namespace mongo { } } - void ReplicaSetMonitor::_checkStatus(DBClientConnection *conn) { + void ReplicaSetMonitor::_checkStatus( const string& hostAddr ) { BSONObj status; - if (!conn->runCommand("admin", BSON("replSetGetStatus" << 1), status) || - !status.hasField("members") || - status["members"].type() != Array) { + /* replSetGetStatus requires admin auth so use a connection from the pool, + * which are authenticated with the keyFile credentials. + */ + ScopedDbConnection authenticatedConn( hostAddr ); + + if ( !authenticatedConn->runCommand( "admin", BSON( "replSetGetStatus" << 1 ), status )) { + LOG(1) << "dbclient_rs replSetGetStatus failed" << endl; + authenticatedConn.done(); // connection worked properly, but we got an error from server + return; + } + + // Make sure we return when finished + authenticatedConn.done(); + + if( !status.hasField("members") ) { + log() << "dbclient_rs error expected members field in replSetGetStatus result" << endl; + return; + } + if( status["members"].type() != Array) { + log() << "dbclient_rs error expected members field in replSetGetStatus result to be an array" << endl; return; } @@ -523,7 +540,7 @@ namespace mongo { } _checkHosts( b.arr(), changed); - _checkStatus( conn ); + _checkStatus( conn->getServerAddress() ); } catch ( std::exception& e ) { -- cgit v1.2.3