diff options
author | Mathias Stearn <mathias@10gen.com> | 2010-11-24 14:27:36 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2010-11-29 14:47:44 -0500 |
commit | c83071685f298074c6e18d11803bf6aa3dcc286b (patch) | |
tree | 5b8d29576bb78133a52123cd84ab9d46d9b18d97 /tools | |
parent | 5eb70c007216908dbc72298916e26565e20a7ab9 (diff) | |
download | mongo-c83071685f298074c6e18d11803bf6aa3dcc286b.tar.gz |
make sure tools always use the same slave connection
This is needed for SERVER-2025 to be implemented safely
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tool.cpp | 9 | ||||
-rw-r--r-- | tools/tool.h | 1 |
2 files changed, 7 insertions, 3 deletions
diff --git a/tools/tool.cpp b/tools/tool.cpp index f2c74a8ee85..1845a727e70 100644 --- a/tools/tool.cpp +++ b/tools/tool.cpp @@ -38,7 +38,7 @@ namespace mongo { Tool::Tool( string name , DBAccess access , string defaultDB , string defaultCollection , bool usesstdout ) : _name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , - _usesstdout(usesstdout), _noconnection(false), _autoreconnect(false), _conn(0), _paired(false) { + _usesstdout(usesstdout), _noconnection(false), _autoreconnect(false), _conn(0), _slaveConn(0), _paired(false) { _options = new po::options_description( "options" ); _options->add_options() @@ -240,8 +240,11 @@ namespace mongo { } DBClientBase& Tool::conn( bool slaveIfPaired ){ - if ( slaveIfPaired && _conn->type() == ConnectionString::SET ) - return ((DBClientReplicaSet*)_conn)->slaveConn(); + if ( slaveIfPaired && _conn->type() == ConnectionString::SET ){ + if (!_slaveConn) + _slaveConn = &((DBClientReplicaSet*)_conn)->slaveConn(); + return *_slaveConn; + } return *_conn; } diff --git a/tools/tool.h b/tools/tool.h index 5771d1cce4c..d703c6b0fcb 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -121,6 +121,7 @@ namespace mongo { protected: mongo::DBClientBase * _conn; + mongo::DBClientBase * _slaveConn; bool _paired; boost::program_options::options_description * _options; |