summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-08-12 16:55:18 -0400
committerEliot Horowitz <eliot@10gen.com>2009-08-12 16:55:18 -0400
commit38bb9b15c223e1abfe001b984ecc772064f76278 (patch)
tree6c428cdb8ffda9019a265e00bf9a3769696bb885
parent0cfa107650fdc0f57b0823feb04ea7e1d705e102 (diff)
downloadmongo-38bb9b15c223e1abfe001b984ecc772064f76278.tar.gz
when doing a dump from a replica pair, do it from the slave SERVER-169
-rw-r--r--tools/Tool.cpp9
-rw-r--r--tools/Tool.h5
-rw-r--r--tools/dump.cpp6
3 files changed, 14 insertions, 6 deletions
diff --git a/tools/Tool.cpp b/tools/Tool.cpp
index 50198ba2eda..6526ebaadbf 100644
--- a/tools/Tool.cpp
+++ b/tools/Tool.cpp
@@ -14,7 +14,7 @@ using namespace mongo;
namespace po = boost::program_options;
mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
- _name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , _conn(0) {
+ _name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , _conn(0), _paired(false) {
_options = new po::options_description( name + " options" );
_options->add_options()
@@ -78,6 +78,7 @@ int mongo::Tool::main( int argc , char ** argv ){
}
else {
DBClientPaired * c = new DBClientPaired();
+ _paired = true;
_conn = c;
if ( ! c->connect( _host ) ){
@@ -118,6 +119,12 @@ int mongo::Tool::main( int argc , char ** argv ){
}
}
+mongo::DBClientBase& mongo::Tool::conn( bool slaveIfPaired ){
+ if ( _paired && slaveIfPaired )
+ return ((DBClientPaired*)_conn)->slaveConn();
+ return *_conn;
+}
+
void mongo::Tool::auth( string dbname ){
if ( ! dbname.size() )
dbname = _db;
diff --git a/tools/Tool.h b/tools/Tool.h
index 080a167b3c0..4082a593f1e 100644
--- a/tools/Tool.h
+++ b/tools/Tool.h
@@ -56,7 +56,7 @@ namespace mongo {
protected:
- mongo::DBClientBase &conn() { return *_conn; }
+ mongo::DBClientBase &conn( bool slaveIfPaired = false );
void auth( string db = "" );
string _name;
@@ -71,7 +71,8 @@ namespace mongo {
private:
string _host;
mongo::DBClientBase * _conn;
-
+ bool _paired;
+
boost::program_options::options_description * _options;
boost::program_options::positional_options_description _positonalOptions;
diff --git a/tools/dump.cpp b/tools/dump.cpp
index 3c64659e306..27e19938173 100644
--- a/tools/dump.cpp
+++ b/tools/dump.cpp
@@ -40,7 +40,7 @@ public:
int out = open( outputFile.string().c_str() , O_WRONLY | O_CREAT | O_TRUNC , 0666 );
assert( out );
- auto_ptr<DBClientCursor> cursor = conn().query( coll.c_str() , Query().snapshot() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
+ auto_ptr<DBClientCursor> cursor = conn( true ).query( coll.c_str() , Query().snapshot() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
int num = 0;
while ( cursor->more() ) {
@@ -61,7 +61,7 @@ public:
string sns = db + ".system.namespaces";
- auto_ptr<DBClientCursor> cursor = conn().query( sns.c_str() , Query() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
+ auto_ptr<DBClientCursor> cursor = conn( true ).query( sns.c_str() , Query() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
while ( cursor->more() ) {
BSONObj obj = cursor->next();
if ( obj.toString().find( ".$" ) != string::npos )
@@ -88,7 +88,7 @@ public:
cout << "all dbs" << endl;
auth( "admin" );
- BSONObj res = conn().findOne( "admin.$cmd" , BSON( "listDatabases" << 1 ) );
+ BSONObj res = conn( true ).findOne( "admin.$cmd" , BSON( "listDatabases" << 1 ) );
BSONObj dbs = res.getField( "databases" ).embeddedObjectUserCheck();
set<string> keys;
dbs.getFieldNames( keys );